Esempio n. 1
0
def lint_check(node, file_name, opts):
    node = scopes.create_scopes(node)  # update scopes
    if not hasattr(node, 'hint'):
        node = jshints.create_hints_tree(node)
    lint = LintChecker(node, file_name, opts)
    lint.visit(node)
    return lint.issues
Esempio n. 2
0
    def _analyzeClassDepsNode(self, node, depsList, inLoadContext, inDefer=False):
        # helper functions
        not_jsignored = inverse(gs.test_ident_is_jsignored)
        browser_sans_this = [x for x in lang.GLOBALS if x!='this']
        not_builtin = inverse(gs.test_ident_is_builtin(browser_sans_this))
        not_jsignore_envcall = inverse(lambda d: gs.name_is_jsignored(
            d.name+('.'+d.attribute if d.attribute else ''), d.node))
        # ensure a complete hint tree for ignore checking
        root_node = node.getRoot()
        if not hasattr(root_node, 'hint'):
            root_node = jshints.create_hints_tree(root_node)

        code_deps = pipeline(
            self.dependencies_from_ast(node)
            , bind(filter, not_jsignored)
            , bind(filter, not_builtin)
            , bind(map, self.depsItem_from_node)
        )
        envcall_deps = pipeline(
            self.dependencies_from_envcalls(node)
            , bind(filter, not_jsignore_envcall)
        )
        dependencies = code_deps + envcall_deps
        
        [setattr(x,'node',None) for x in dependencies]  # remove AST links (for easier caching)
        depsList.extend(dependencies)
Esempio n. 3
0
    def _analyzeClassDepsNode(self, node, depsList, inLoadContext, inDefer=False):
        # helper functions
        not_jsignored = inverse(gs.test_ident_is_jsignored)
        browser_sans_this = [x for x in lang.GLOBALS if x!='this']
        not_builtin = inverse(gs.test_ident_is_builtin(browser_sans_this))
        not_jsignore_envcall = inverse(lambda d: gs.name_is_jsignored(
            d.name+('.'+d.attribute if d.attribute else ''), d.node))
        # ensure a complete hint tree for ignore checking
        root_node = node.getRoot()
        if not hasattr(root_node, 'hint'):
            root_node = jshints.create_hints_tree(root_node)

        code_deps = pipeline(
            self.dependencies_from_ast(node)
            , bind(filter, not_jsignored)
            , bind(filter, not_builtin)
            , bind(map, self.depsItem_from_node)
        )
        envcall_deps = pipeline(
            self.dependencies_from_envcalls(node)
            , bind(filter, not_jsignore_envcall)
        )
        dependencies = code_deps + envcall_deps

        [setattr(x,'node',None) for x in dependencies]  # remove AST links (for easier caching)
        depsList.extend(dependencies)
Esempio n. 4
0
def lint_check(node, file_name, opts):
    node = scopes.create_scopes(node)  # update scopes
    if not hasattr(node, 'hint'):
        node = jshints.create_hints_tree(node)
    lint = LintChecker(node, file_name, opts)
    lint.visit(node)
    return lint.issues
Esempio n. 5
0
def globals_filter_by_hints(global_nodes, tree):
    result = []
    tree = jshints.create_hints_tree(tree)
    for node in global_nodes:
        if not ident_is_ignored(node):
            result.append(node)
    return result
Esempio n. 6
0
def globals_filter_by_hints(global_nodes, tree):
    result = []
    tree = jshints.create_hints_tree(tree)
    for node in global_nodes:
        if not ident_is_ignored(node):
            result.append(node)
    return result
Esempio n. 7
0
        def buildShallowDeps(tree=None):

            load, run   = [], []
            ignore = [DependencyItem(x, '', "|DefaultIgnoredNamesDynamic|") for x in self.defaultIgnoredNamesDynamic]

            console.debug("Getting shallow deps of: %s" % self.id)
            console.indent()

            # Read source tree data
            if not tree:
                if variantSet: # a filled variantSet map means that "variants" optimization is wanted
                    tree = self.optimize(None, ["variants"], variantSet)
                else:
                    tree = self.tree()

            # Get deps from compiler hints
            if not hasattr(tree, 'hint'):
                tree = jshints.create_hints_tree(tree) # this will be used by some of the subsequent method calls
            load_hints, run_hints, ignore_hints, all_feature_checks = self.dependencies_from_comphints(tree) # ignore_hints=[HintArgument]
            load.extend(load_hints)
            run.extend(run_hints)
            load_feature_checks = all_feature_checks[0]
            run_feature_checks = all_feature_checks[1]

            # Analyze tree
            treeDeps  = []  # will be filled by _analyzeClassDepsNode
            self._analyzeClassDepsNode(tree, treeDeps, inLoadContext=True)

            # Filter lexical deps through ignore_hints
            load1, run1, ignore1 = self.filter_symbols_by_comphints(treeDeps, ignore_hints)
                # load and run are being filtered, ignore contains the actually filtered depsItems

            # integrate into existing lists
            load_hint_names = [str(x) for x in load_hints]
            for dep in load1:
                if str(dep) in load_hint_names and not load_feature_checks:
                    console.warn("%s: @require(%s) is auto-detected" % (self.id, dep))
                load.append(dep)
            run_hint_names = [str(x) for x in run_hints]
            for dep in run1:
                if str(dep) in run_hint_names and not run_feature_checks:
                    console.warn("%s: @use(%s) is auto-detected" % (self.id, dep))
                run.append(dep)
            ignore.extend(ignore1)

            console.outdent()

            # Build data structure
            deps = {
                "load"   : load,
                "run"    : run,
                "ignore" : ignore,
            }

            return deps
Esempio n. 8
0
        def buildShallowDeps(tree=None):

            load, run   = [], []
            ignore = [DependencyItem(x, '', "|DefaultIgnoredNamesDynamic|") for x in self.defaultIgnoredNamesDynamic]

            console.debug("Getting shallow deps of: %s" % self.id)
            console.indent()

            # Read source tree data
            if not tree:
                if variantSet: # a filled variantSet map means that "variants" optimization is wanted
                    tree = self.optimize(None, ["variants"], variantSet)
                else:
                    tree = self.tree()

            # Get deps from compiler hints
            if not hasattr(tree, 'hint'):
                tree = jshints.create_hints_tree(tree) # this will be used by some of the subsequent method calls
            load_hints, run_hints, ignore_hints, all_feature_checks = self.dependencies_from_comphints(tree) # ignore_hints=[HintArgument]
            load.extend(load_hints)
            run.extend(run_hints)
            load_feature_checks = all_feature_checks[0]
            run_feature_checks = all_feature_checks[1]

            # Analyze tree
            treeDeps  = []  # will be filled by _analyzeClassDepsNode
            self._analyzeClassDepsNode(tree, treeDeps, inLoadContext=True)

            # Filter lexical deps through ignore_hints
            load1, run1, ignore1 = self.filter_symbols_by_comphints(treeDeps, ignore_hints)
                # load and run are being filtered, ignore contains the actually filtered depsItems

            # integrate into existing lists
            load_hint_names = [str(x) for x in load_hints]
            for dep in load1:
                if str(dep) in load_hint_names and not load_feature_checks:
                    console.warn("%s: @require(%s) is auto-detected" % (self.id, dep))
                load.append(dep)
            run_hint_names = [str(x) for x in run_hints]
            for dep in run1:
                if str(dep) in run_hint_names and not run_feature_checks:
                    console.warn("%s: @use(%s) is auto-detected" % (self.id, dep))
                run.append(dep)
            ignore.extend(ignore1)

            console.outdent()

            # Build data structure
            deps = {
                "load"   : load,
                "run"    : run,
                "ignore" : ignore,
            }

            return deps
 def _analyzeClassDepsNode(self, node, depsList, inLoadContext, inDefer=False):
     # ensure a complete hint tree for ignore checking
     root_node = node.getRoot()
     if not hasattr(root_node, 'hint'):
         root_node = jshints.create_hints_tree(root_node)
     lexical_globals  =  self.dependencies_from_ast(node)
     lexical_globals +=  self.dependencies_from_envcalls(node)
     lexical_globals  =  self.filter_symbols_by_jshints(node, lexical_globals)
     filtered_globals =  self.filter_symbols_by_builtins(lexical_globals)
     [setattr(x,'node',None) for x in filtered_globals]  # remove AST links (for easier caching)
     depsList.extend(filtered_globals)
     return
Esempio n. 10
0
 def get_hint_jsdocs(meta):
     tree = self.tree()
     if not hasattr(tree, 'hint'):
         tree = jshints.create_hints_tree(tree)
     for hint in tree.hint.iterator():
         for target,hintKey in (('assetDeps','asset'), ('cldr','cldr')):
             if hintKey in hint.hints:
                 #meta[target].extend(hint.hints[hintKey][None])
                 # for now only use HintArgument.source, to comply with old #asset hints
                 if hint.hints[hintKey][None]:
                     meta[target].extend([x.source for x in hint.hints[hintKey][None]])
     return meta
 def filter_symbols_by_jshints(self, tree, depsItems):
     result = []
     tree = jshints.create_hints_tree(tree)
     for depsItem in depsItems:
         #if self.id == 'qx.test.ui.decoration.MDoubleBorder' and depsItem.name=='TestDecorator':
         #    import pydb; pydb.debugger()
         deps_repr = depsItem.name
         if depsItem.attribute:
             deps_repr += '.' + depsItem.attribute
         if not global_symbols.ident_is_ignored(deps_repr, depsItem.node):
             result.append(depsItem)
     return result
Esempio n. 12
0
 def get_hint_jsdocs(meta):
     tree = self.tree()
     if not hasattr(tree, 'hint'):
         tree = jshints.create_hints_tree(tree)
     for hint in tree.hint.iterator():
         for target, hintKey in (('assetDeps', 'asset'), ('cldr',
                                                          'cldr')):
             if hintKey in hint.hints:
                 #meta[target].extend(hint.hints[hintKey][None])
                 # for now only use HintArgument.source, to comply with old #asset hints
                 if hint.hints[hintKey][None]:
                     meta[target].extend(
                         [x.source for x in hint.hints[hintKey][None]])
     return meta
Esempio n. 13
0
 def _analyzeClassDepsNode(self,
                           node,
                           depsList,
                           inLoadContext,
                           inDefer=False):
     # ensure a complete hint tree for ignore checking
     root_node = node.getRoot()
     if not hasattr(root_node, 'hint'):
         root_node = jshints.create_hints_tree(root_node)
     lexical_globals = self.dependencies_from_ast(node)
     lexical_globals += self.dependencies_from_envcalls(node)
     lexical_globals = self.filter_symbols_by_jshints(node, lexical_globals)
     filtered_globals = self.filter_symbols_by_builtins(lexical_globals)
     [setattr(x, 'node', None)
      for x in filtered_globals]  # remove AST links (for easier caching)
     depsList.extend(filtered_globals)
     return
Esempio n. 14
0
                raise

            # Annotate with scopes
            if True:
                tree = scopes.create_scopes(tree)  # checks for suitable treegenerator_tag
                #tree.scope.prrnt()
                #print self.id, " (globals):", [c for s in tree.scope.scope_iterator() for c in s.globals()]

            # Annotate scopes with load time information
            if True:
                if hasattr(tree,'scope') and tree.scope:
                    load_time.load_time_check(tree.scope)

            # Annotate with jsdoc hints
            if True:
                tree = jshints.create_hints_tree(tree)

            # Store unoptimized tree
            cache.write(cacheId, tree, memory=tradeSpaceForSpeed)

            console.outdent()

        return tree


    ##
    # Raises in case of inconsistencies, otherwise returns None
    #
    def checkClassId(self, tree):
        className = None  # not-found return value
        filePathId = self.id