Thread: [javascriptlint-commit] SF.net SVN: javascriptlint:[204] trunk/pyjsl/lint.py
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2008-08-15 15:11:13
|
Revision: 204 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=204&view=rev Author: matthiasmiller Date: 2008-08-15 15:11:11 +0000 (Fri, 15 Aug 2008) Log Message: ----------- fix bug in variable declarations getting added to the wrong scope Modified Paths: -------------- trunk/pyjsl/lint.py Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2008-08-15 14:55:20 UTC (rev 203) +++ trunk/pyjsl/lint.py 2008-08-15 15:11:11 UTC (rev 204) @@ -310,7 +310,7 @@ @visitation.visit('push', tok.VAR) def _push_var(self, node): for kid in node.kids: - _warn_or_declare(scope, kid.atom, node, report) + _warn_or_declare(scopes[-1], kid.atom, node, report) return scope_checks This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2008-08-28 00:18:46
|
Revision: 229 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=229&view=rev Author: matthiasmiller Date: 2008-08-28 00:18:44 +0000 (Thu, 28 Aug 2008) Log Message: ----------- pyjsl.lint.Scope's contract indicates that "node" may be None Modified Paths: -------------- trunk/pyjsl/lint.py Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2008-08-28 00:14:15 UTC (rev 228) +++ trunk/pyjsl/lint.py 2008-08-28 00:18:44 UTC (rev 229) @@ -128,7 +128,8 @@ (scope, name, node) ] """ - is_in_with_scope = is_in_with_scope or self._node.kind == tok.WITH + if self._node and self._node.kind == tok.WITH: + is_in_with_scope = True # Add all identifiers as unreferenced. Children scopes will remove # them if they are referenced. Variables need to be keyed by name This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2008-08-28 00:25:44
|
Revision: 230 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=230&view=rev Author: matthiasmiller Date: 2008-08-28 00:25:42 +0000 (Thu, 28 Aug 2008) Log Message: ----------- improve pyjsl.lint.Scope's contract: * Outer-level scopes will never be associated with a node. * All inner-level scopes will always be associated with a node. Modified Paths: -------------- trunk/pyjsl/lint.py Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2008-08-28 00:18:44 UTC (rev 229) +++ trunk/pyjsl/lint.py 2008-08-28 00:25:42 UTC (rev 230) @@ -72,16 +72,20 @@ return (comment, keyword, parms) class Scope: - def __init__(self, node): - """ node may be None """ + """ Outer-level scopes will never be associated with a node. + Inner-level scopes will always be associated with a node. + """ + def __init__(self): self._parent = None self._kids = [] self._identifiers = {} self._references = [] - self._node = node + self._node = None def add_scope(self, node): - self._kids.append(Scope(node)) + assert not node is None + self._kids.append(Scope()) self._kids[-1]._parent = self + self._kids[-1]._node = node return self._kids[-1] def add_declaration(self, name, node): self._identifiers[name] = node @@ -157,22 +161,22 @@ child._find_unreferenced_and_undeclared(unreferenced, undeclared, is_in_with_scope) def find_scope(self, node): - if not self._node: - return None - for kid in self._kids: scope = kid.find_scope(node) if scope: return scope # Always add it to the outer scope. - if not self._parent or \ - (node.start_pos() >= self._node.start_pos() and \ + if not self._parent: + assert not self._node + return self + + # Conditionally add it to an inner scope. + assert self._node + if (node.start_pos() >= self._node.start_pos() and \ node.end_pos() <= self._node.end_pos()): return self - return None - def lint_files(paths, lint_error, conf=conf.Conf()): def lint_file(path): def import_script(import_path): @@ -258,7 +262,7 @@ # Cache empty results for this script. assert not script_cache script_cache['imports'] = set() - script_cache['scope'] = Scope(None) + script_cache['scope'] = Scope() # Report errors and quit. for pos, msg in parse_errors: @@ -321,7 +325,7 @@ assert not script_cache imports = script_cache['imports'] = set() - scope = script_cache['scope'] = Scope(root) + scope = script_cache['scope'] = Scope() # Push the scope/variable checks. visitation.make_visitors(visitors, [_get_scope_checks(scope, report)]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-05-26 02:26:27
|
Revision: 244 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=244&view=rev Author: matthiasmiller Date: 2009-05-26 02:26:18 +0000 (Tue, 26 May 2009) Log Message: ----------- var_hides_arg should also check parent scopes Modified Paths: -------------- trunk/pyjsl/lint.py Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2009-05-20 07:37:57 UTC (rev 243) +++ trunk/pyjsl/lint.py 2009-05-26 02:26:18 UTC (rev 244) @@ -435,12 +435,13 @@ return onpush def _warn_or_declare(scope, name, node, report): - other = scope.get_identifier(name) + parent_scope, other = scope.resolve_identifier(name) or (None, None) if other and other.kind == tok.FUNCTION and name in other.fn_args: report(node, 'var_hides_arg', name=name) - elif other: + elif other and parent_scope == scope: report(node, 'redeclared_var', name=name) else: + # TODO: Warn when hiding a variable in a parent scope. scope.add_declaration(name, node) def _get_scope_checks(scope, report): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mat...@us...> - 2009-08-27 16:53:01
|
Revision: 246 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=246&view=rev Author: matthiasmiller Date: 2009-08-27 16:52:43 +0000 (Thu, 27 Aug 2009) Log Message: ----------- fix error position for nested comments Modified Paths: -------------- trunk/pyjsl/lint.py Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2009-08-27 16:45:33 UTC (rev 245) +++ trunk/pyjsl/lint.py 2009-08-27 16:52:43 UTC (rev 246) @@ -252,7 +252,7 @@ 'redeclared_var', 'var_hides_arg'): parse_errors.append((jsparse.NodePos(row, col), msg)) - def report(node, errname, **errargs): + def report(node, errname, pos=None, **errargs): if errname == 'empty_statement' and node.kind == tok.LC: for pass_ in passes: if pass_.start_pos() > node.start_pos() and \ @@ -283,7 +283,7 @@ fallthrus.remove(fallthru) return - report_lint(node, errname, **errargs) + report_lint(node, errname, pos, **errargs) parse_errors = [] declares = [] @@ -334,8 +334,15 @@ passes.append(node) else: if comment.opcode == 'c_comment': - if '/*' in comment.atom or comment.atom.endswith('/'): - report(comment, 'nested_comment') + # Look for nested C-style comments. + nested_comment = comment.atom.find('/*') + if nested_comment < 0 and comment.atom.endswith('/'): + nested_comment = len(comment.atom) - 1 + # Report at the actual error of the location. Add two + # characters for the opening two characters. + if nested_comment >= 0: + pos = node_positions.from_offset(node_positions.to_offset(comment.start_pos()) + 2 + nested_comment) + report(comment, 'nested_comment', pos=pos) if comment.atom.lower().startswith('jsl:'): report(comment, 'jsl_cc_not_understood') elif comment.atom.startswith('@'): @@ -378,15 +385,9 @@ declare_scope.add_declaration(name, node) def _lint_script_parts(script_parts, script_cache, lint_error, conf, import_callback): - def report_lint(node, errname, **errargs): - # TODO: This is ugly hardcoding to improve the error positioning of - # "missing_semicolon" errors. - if errname == 'missing_semicolon' or errname == 'missing_semicolon_for_lambda': - pos = node.end_pos() - else: - pos = node.start_pos() + def report_lint(node, errname, pos=None, **errargs): errdesc = warnings.format_error(errname, **errargs) - _report(pos, errname, errdesc, True) + _report(pos or node.start_pos(), errname, errdesc, True) def report_native(pos, errname): # TODO: Format the error. @@ -431,7 +432,13 @@ ret = visitor(node) assert ret is None, 'visitor should raise an exception, not return a value' except warnings.LintWarning, warning: - report(warning.node, visitor.warning, **warning.errargs) + # TODO: This is ugly hardcoding to improve the error positioning of + # "missing_semicolon" errors. + if visitor.warning in ('missing_semicolon', 'missing_semicolon_for_lambda'): + pos = warning.node.end_pos() + else: + pos = None + report(warning.node, visitor.warning, pos=pos, **warning.errargs) return onpush def _warn_or_declare(scope, name, node, report): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |