[javascriptlint-commit] SF.net SVN: javascriptlint:[371] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2016-12-30 22:48:35
|
Revision: 371 http://sourceforge.net/p/javascriptlint/code/371 Author: matthiasmiller Date: 2016-12-30 22:48:30 +0000 (Fri, 30 Dec 2016) Log Message: ----------- Properly distinguish between errors and warnings. Modified Paths: -------------- trunk/javascriptlint/jsl.py trunk/javascriptlint/lint.py trunk/test.py trunk/tests/conf/jscript_function_extensions-3.js trunk/tests/conf/jscript_function_extensions-4.js trunk/tests/control_comments/conf-version-2.js trunk/tests/control_comments/conf-version.js trunk/tests/errors/expected_tok.js trunk/tests/errors/syntax_error.js trunk/tests/html/e4x.html Modified: trunk/javascriptlint/jsl.py =================================================================== --- trunk/javascriptlint/jsl.py 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/javascriptlint/jsl.py 2016-12-30 22:48:30 UTC (rev 371) @@ -17,7 +17,7 @@ import version _lint_results = { - 'warnings': 0, + 'warning': 0, 'errors': 0 } @@ -26,8 +26,9 @@ script = fs.readfile(path, encoding) jsparse.dump_tree(script) -def _lint_warning(conf_, path, line, col, errname, errdesc): - _lint_results['warnings'] = _lint_results['warnings'] + 1 +def _lint_warning(conf_, path, line, col, msg_type, errname, errdesc): + assert msg_type in ('warning', 'error') + _lint_results[msg_type] += 1 print util.format_error(conf_['output-format'], path, line, col, errname, errdesc) @@ -120,7 +121,7 @@ try: conf_.loadfile(options.conf) except conf.ConfError, error: - _lint_warning(conf_, error.path, error.lineno, 0, 'conf_error', + _lint_warning(conf_, error.path, error.lineno, 0, 'error', 'conf_error', unicode(error)) profile_func = _profile_disabled @@ -151,12 +152,12 @@ profile_func(_lint, paths, conf_, options.printlisting, options.encoding) if options.printsummary: - print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'], - _lint_results['warnings']) + print '\n%i error(s), %i warnings(s)' % (_lint_results['error'], + _lint_results['warning']) - if _lint_results['errors']: + if _lint_results['error']: sys.exit(3) - if _lint_results['warnings']: + if _lint_results['warning']: sys.exit(1) sys.exit(0) Modified: trunk/javascriptlint/lint.py =================================================================== --- trunk/javascriptlint/lint.py 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/javascriptlint/lint.py 2016-12-30 22:48:30 UTC (rev 371) @@ -288,18 +288,18 @@ def report_lint(node, errname, offset=0, **errargs): assert errname in lintwarnings.warnings, errname if conf[errname]: - _report(offset or node.start_offset, errname, errargs) + _report(offset or node.start_offset, 'warning', errname, errargs) def report_parse_error(offset, errname, errargs): assert errname in lintwarnings.errors, errname - _report(offset, errname, errargs) + _report(offset, 'error', errname, errargs) - def _report(offset, errname, errargs): + def _report(offset, msg_type, errname, errargs): errdesc = lintwarnings.format_error(errname, **errargs) if lint_cache[normpath].should_ignore(offset): return pos = node_positions.from_offset(offset) - return lint_error(normpath, pos.line, pos.col, errname, errdesc) + return lint_error(normpath, pos.line, pos.col, msg_type, errname, errdesc) normpath = fs.normpath(path) if normpath in lint_cache: Modified: trunk/test.py =================================================================== --- trunk/test.py 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/test.py 2016-12-30 22:48:30 UTC (rev 371) @@ -33,15 +33,15 @@ "returns an array of tuples -- line, warning" warnings = [] - regexp = re.compile(r"/\*warning:([^*]*)\*/") + regexp = re.compile(r"/\*(error|warning):([^*]*)\*/") lines = script.splitlines() for i in range(0, len(lines)): - for warning in regexp.findall(lines[i]): + for msg_type, warning in regexp.findall(lines[i]): # TODO: implement these unimpl_warnings = ('dup_option_explicit',) if not warning in unimpl_warnings: - warnings.append((i, warning)) + warnings.append((i, msg_type, warning)) return warnings def _testfile(path): @@ -51,13 +51,13 @@ unexpected_warnings = [] conf = _get_conf(script) - def lint_error(path, line, col, errname, errdesc): - warning = (line, errname) + def lint_error(path, line, col, msg_type, errname, errdesc): + warning = (line, msg_type, errname) # Bad hack to fix line numbers on ambiguous else statements # TODO: Fix tests. if errname == 'ambiguous_else_stmt' and not warning in expected_warnings: - warning = (line-1, errname) + warning = (line-1, msg_type, errname) if warning in expected_warnings: expected_warnings.remove(warning) @@ -69,11 +69,11 @@ errors = [] if expected_warnings: errors.append('Expected warnings:') - for line, warning in expected_warnings: + for line, msg_type, warning in expected_warnings: errors.append('\tline %i: %s' % (line+1, warning)) if unexpected_warnings: errors.append('Unexpected warnings:') - for line, warning, errdesc in unexpected_warnings: + for line, msg_type, warning, errdesc in unexpected_warnings: errors.append('\tline %i: %s/%s' % (line+1, warning, errdesc)) if errors: raise TestError('\n'.join(errors)) Modified: trunk/tests/conf/jscript_function_extensions-3.js =================================================================== --- trunk/tests/conf/jscript_function_extensions-3.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/conf/jscript_function_extensions-3.js 2016-12-30 22:48:30 UTC (rev 371) @@ -23,5 +23,5 @@ this.val = null; } -function conf.jscript_function_extensions..ok(val) { /*warning:syntax_error*/ +function conf.jscript_function_extensions..ok(val) { /*error:syntax_error*/ } Modified: trunk/tests/conf/jscript_function_extensions-4.js =================================================================== --- trunk/tests/conf/jscript_function_extensions-4.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/conf/jscript_function_extensions-4.js 2016-12-30 22:48:30 UTC (rev 371) @@ -1,4 +1,4 @@ /*conf:+jscript_function_extensions*/ -function conf.jscript_function_extensions:onunload(val) { /*warning:syntax_error*/ +function conf.jscript_function_extensions:onunload(val) { /*error:syntax_error*/ } Modified: trunk/tests/control_comments/conf-version-2.js =================================================================== --- trunk/tests/control_comments/conf-version-2.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/control_comments/conf-version-2.js 2016-12-30 22:48:30 UTC (rev 371) @@ -3,5 +3,5 @@ /* Make sure that the control comment overrides the config file. */ function default_version() { - yield true; /*warning:semi_before_stmnt*/ + yield true; /*error:semi_before_stmnt*/ } Modified: trunk/tests/control_comments/conf-version.js =================================================================== --- trunk/tests/control_comments/conf-version.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/control_comments/conf-version.js 2016-12-30 22:48:30 UTC (rev 371) @@ -1,5 +1,5 @@ /*conf:+default-version text/javascript;version=1.7*/ function default_version() { // TODO: Support js1.7 - yield true; /*warning:semi_before_stmnt*/ + yield true; /*error:semi_before_stmnt*/ } Modified: trunk/tests/errors/expected_tok.js =================================================================== --- trunk/tests/errors/expected_tok.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/errors/expected_tok.js 2016-12-30 22:48:30 UTC (rev 371) @@ -1,4 +1,4 @@ function expected_tok() { - return { a, }; /*warning:expected_tok*/ + return { a, }; /*error:expected_tok*/ } Modified: trunk/tests/errors/syntax_error.js =================================================================== --- trunk/tests/errors/syntax_error.js 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/errors/syntax_error.js 2016-12-30 22:48:30 UTC (rev 371) @@ -1,4 +1,4 @@ function syntax_error() { - &; /*warning:syntax_error*/ + &; /*error:syntax_error*/ } Modified: trunk/tests/html/e4x.html =================================================================== --- trunk/tests/html/e4x.html 2016-12-29 22:10:19 UTC (rev 370) +++ trunk/tests/html/e4x.html 2016-12-30 22:48:30 UTC (rev 371) @@ -7,19 +7,19 @@ <script type="text/javascript"> // e4x is disabled by default, so HTML comments are single-line only. var comment_a = <!-- - ? /*warning:syntax_error*/ + ? /*error:syntax_error*/ -->; </script> <script type="text/javascript;e4x=1">/*warning:e4x_deprecated*/ // Explicitly enable e4x. var comment_c = <!-- - ? /*warning:syntax_error*/ + ? /*error:syntax_error*/ -->; </script> <script type="text/javascript;version=1.6;e4x=0"> // e4x is always enabled in 1.6+ var comment_b = <!-- - ? /*warning:syntax_error*/ + ? /*error:syntax_error*/ -->; </script> </head> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |