[javascriptlint-commit] SF.net SVN: javascriptlint:[374] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2018-01-02 21:20:18
|
Revision: 374 http://sourceforge.net/p/javascriptlint/code/374 Author: matthiasmiller Date: 2018-01-02 21:20:15 +0000 (Tue, 02 Jan 2018) Log Message: ----------- Improve error messages with invalid imports. Modified Paths: -------------- trunk/javascriptlint/lint.py Added Paths: ----------- trunk/tests/path_resolution/missing_import.html trunk/tests/path_resolution/missing_import.js Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2018-01-02 20:28:00 UTC (rev 373) +++ trunk/javascriptlint/lint.py 2018-01-02 21:20:15 UTC (rev 374) @@ -251,6 +251,7 @@ yield { 'type': 'external', 'jsversion': jsversion, + 'offset': tag['offset'], 'src': src, } elif tag['type'] == 'end': @@ -278,13 +279,19 @@ def lint_files(paths, lint_error, encoding, conf=conf.Conf(), printpaths=True): def lint_file(path, kind, jsversion, encoding): - def import_script(import_path, jsversion): + def import_script(offset, import_path, jsversion): # The user can specify paths using backslashes (such as when # linting Windows scripts on a posix environment. import_path = import_path.replace('\\', os.sep) import_path = os.path.join(os.path.dirname(path), import_path) - return lint_file(import_path, 'js', jsversion, encoding) + if os.path.isfile(import_path): + return lint_file(import_path, 'js', jsversion, encoding) + _report(offset, 'error', 'io_error', { + 'error': 'The file could not be found: %s' % import_path + }) + return _Script() + def report_lint(node, errname, offset=0, **errargs): assert errname in lintwarnings.warnings, errname if conf[errname]: @@ -326,7 +333,7 @@ continue if script['type'] == 'external': - other = import_script(script['src'], script['jsversion']) + other = import_script(script['offset'], script['src'], script['jsversion']) lint_cache[normpath].importscript(other) elif script['type'] == 'inline': script_parts.append((script['offset'], script['jsversion'], @@ -460,7 +467,7 @@ if not parms: report(node, 'jsl_cc_not_understood') else: - import_paths.append(parms) + import_paths.append((node.start_offset, parms)) elif keyword == 'fallthru': fallthrus.append(node) elif keyword == 'pass': @@ -503,8 +510,8 @@ report(fallthru, 'invalid_pass') # Process imports by copying global declarations into the universal scope. - for path in import_paths: - script_cache.importscript(import_callback(path, jsversion)) + for offset, path in import_paths: + script_cache.importscript(import_callback(offset, path, jsversion)) for name, node in declares: declare_scope = script_cache.scope.find_scope(node) Added: trunk/tests/path_resolution/missing_import.html =================================================================== --- trunk/tests/path_resolution/missing_import.html (rev 0) +++ trunk/tests/path_resolution/missing_import.html 2018-01-02 21:20:15 UTC (rev 374) @@ -0,0 +1,10 @@ +<html> +<head> + <script src="file_does_not_exist.js"></script> <!--/*error:io_error*/--> +</head> +<body> + <script> + /*jsl:import file_does_not_exist.js*/ /*error:io_error*/ + </script> +</body> +</html> Added: trunk/tests/path_resolution/missing_import.js =================================================================== --- trunk/tests/path_resolution/missing_import.js (rev 0) +++ trunk/tests/path_resolution/missing_import.js 2018-01-02 21:20:15 UTC (rev 374) @@ -0,0 +1 @@ +/*jsl:import file_does_not_exist.js*/ /*error:io_error*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |