[javascriptlint-commit] SF.net SVN: javascriptlint:[359] trunk/javascriptlint
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2016-12-23 22:27:22
|
Revision: 359
http://sourceforge.net/p/javascriptlint/code/359
Author: matthiasmiller
Date: 2016-12-23 22:27:20 +0000 (Fri, 23 Dec 2016)
Log Message:
-----------
Remove more unused code.
Modified Paths:
--------------
trunk/javascriptlint/lint.py
trunk/javascriptlint/lintwarnings.py
Removed Paths:
-------------
trunk/javascriptlint/visitation.py
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2016-12-23 21:56:37 UTC (rev 358)
+++ trunk/javascriptlint/lint.py 2016-12-23 22:27:20 UTC (rev 359)
@@ -8,7 +8,6 @@
import htmlparse
import jsparse
import lintwarnings
-import visitation
import unittest
import util
@@ -478,7 +477,7 @@
visitors[event][kind] = [_getreporter(callback, report) for callback in callbacks]
# Push the scope/variable checks.
- visitation.make_visitors(visitors, [_get_scope_checks(script_cache.scope, report)])
+ _get_scope_checks(visitors, script_cache.scope, report)
# kickoff!
_lint_node(root, visitors)
@@ -582,43 +581,44 @@
else:
scope.add_declaration(name, node, type_)
-def _get_scope_checks(scope, report):
+def _get_scope_checks(visitors, scope, report):
scopes = [scope]
- class scope_checks:
- """ This is a non-standard visitation class to track scopes. The
- docstring is unused since this class never throws lint errors.
- """
- @visitation.visit('push', tok.NAME)
- def _name(self, node):
- if node.node_index == 0 and node.parent.kind == tok.COLON and node.parent.parent.kind == tok.RC:
- return # left side of object literal
- if node.parent.kind == tok.VAR:
- _warn_or_declare(scopes[-1], node.atom, 'var', node, report)
- return
- if node.parent.kind == tok.CATCH:
- scopes[-1].add_declaration(node.atom, node, 'var')
- scopes[-1].add_reference(node.atom, node)
+ def _visit(event, *args):
+ def _decorate(fn):
+ for arg in args:
+ visitors.setdefault(event, {}).setdefault(arg, []).append(fn)
+ return fn
+ return _decorate
- @visitation.visit('push', tok.FUNCTION)
- def _push_func(self, node):
- if node.opcode in (None, op.CLOSURE) and node.fn_name:
- _warn_or_declare(scopes[-1], node.fn_name, 'function', node, report)
- self._push_scope(node)
- for var_name in node.fn_args:
- if scopes[-1].has_property(var_name.atom):
- report(var_name, 'duplicate_formal', name=var_name.atom)
- scopes[-1].add_declaration(var_name.atom, var_name, 'arg')
+ @_visit('push', tok.NAME)
+ def _push_name(node):
+ if node.node_index == 0 and node.parent.kind == tok.COLON and node.parent.parent.kind == tok.RC:
+ return # left side of object literal
+ if node.parent.kind == tok.VAR:
+ _warn_or_declare(scopes[-1], node.atom, 'var', node, report)
+ return
+ if node.parent.kind == tok.CATCH:
+ scopes[-1].add_declaration(node.atom, node, 'var')
+ scopes[-1].add_reference(node.atom, node)
- @visitation.visit('push', tok.LEXICALSCOPE, tok.WITH)
- def _push_scope(self, node):
- scopes.append(scopes[-1].add_scope(node))
+ @_visit('push', tok.FUNCTION)
+ def _push_func(node):
+ if node.opcode in (None, op.CLOSURE) and node.fn_name:
+ _warn_or_declare(scopes[-1], node.fn_name, 'function', node, report)
+ _push_scope(node)
+ for var_name in node.fn_args:
+ if scopes[-1].has_property(var_name.atom):
+ report(var_name, 'duplicate_formal', name=var_name.atom)
+ scopes[-1].add_declaration(var_name.atom, var_name, 'arg')
- @visitation.visit('pop', tok.FUNCTION, tok.LEXICALSCOPE, tok.WITH)
- def _pop_scope(self, node):
- scopes.pop()
+ @_visit('push', tok.LEXICALSCOPE, tok.WITH)
+ def _push_scope(node):
+ scopes.append(scopes[-1].add_scope(node))
- return scope_checks
+ @_visit('pop', tok.FUNCTION, tok.LEXICALSCOPE, tok.WITH)
+ def _pop_scope(node):
+ scopes.pop()
def _lint_node(node, visitors):
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-23 21:56:37 UTC (rev 358)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-23 22:27:20 UTC (rev 359)
@@ -20,7 +20,6 @@
import types
import util
-import visitation
from jsengine.parser import kind as tok
from jsengine.parser import op
Deleted: trunk/javascriptlint/visitation.py
===================================================================
--- trunk/javascriptlint/visitation.py 2016-12-23 21:56:37 UTC (rev 358)
+++ trunk/javascriptlint/visitation.py 2016-12-23 22:27:20 UTC (rev 359)
@@ -1,52 +0,0 @@
-# vim: ts=4 sw=4 expandtab
-""" This is an abstract module for visiting specific nodes. This is useed to
-traverse the tree to generate warnings.
-"""
-
-def visit(event, *args):
- """ This decorator is used to indicate which nodes the function should
- examine. The function should accept (self, node) and return the relevant
- node or None. """
- def _decorate(fn):
- fn._visit_event = event
- fn._visit_nodes = args
- return fn
- return _decorate
-
-def make_visitors(visitors, klasses):
- """ Searches klasses for all member functions decorated with @visit and
- fills a dictionary that looks like:
- visitors = {
- 'event_name': {
- 'node_type' : [func1, func2]
- }
- }
- """
- assert isinstance(visitors, dict)
-
- # Intantiate an instance of each class
- for klass in klasses:
- if klass.__name__.lower() != klass.__name__:
- raise ValueError('class names must be lowercase')
- if not klass.__doc__:
- raise ValueError('missing docstring on class %s' % klass.__name__)
-
- # Look for functions with the "_visit_nodes" property.
- visitor = klass()
- for func in [getattr(visitor, name) for name in dir(visitor)]:
- event_visitors = None
- for node_kind in getattr(func, '_visit_nodes', ()):
- # Group visitors by event (e.g. push vs pop)
- if not event_visitors:
- try:
- event_visitors = visitors[func._visit_event]
- except KeyError:
- event_visitors = visitors[func._visit_event] = {}
-
- # Map from node_kind to the function
- try:
- event_visitors[node_kind].append(func)
- except KeyError:
- event_visitors[node_kind] = [func]
- return visitors
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|