Ejemplo n.º 1
0
    def unknown_globals(self, scope):
        # helper functions
        not_jsignored = inverse(gs.test_ident_is_jsignored)
        not_builtin = inverse(gs.test_ident_is_builtin())
        not_libsymbol = inverse(curry3(gs.test_for_libsymbol,
            self.opts.class_namespaces)(self.known_globals_bases))
        not_confsymbol = lambda node: globals_table[node] not in self.opts.allowed_globals
        def warn_appender(global_nodes):
            for node in global_nodes:
                issue = warn("Unknown global symbol used: '%s'" % globals_table[node], self.file_name, node)
                self.issues.append(issue)

        # ------------------------------
        # collect scope's global use locations
        globals_table = {} # {node: assembled}
        for id_, scopeVar in scope.globals().items():
            for head_node in scopeVar.uses:
                var_top = treeutil.findVarRoot(head_node)
                assembled = (treeutil.assembleVariable(var_top))[0]
                globals_table[head_node] = assembled

        # filter and add remains to warnings

        pipeline(
            globals_table.keys()
            , bind(filter, not_builtin)
            , bind(filter, not_jsignored)
            , bind(filter, not_libsymbol)
            , bind(filter, not_confsymbol)
            , warn_appender
        )
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 4
0
    def unknown_globals(self, scope):
        # helper functions
        not_jsignored = inverse(gs.test_ident_is_jsignored)
        not_builtin = inverse(gs.test_ident_is_builtin())
        not_libsymbol = inverse(curry3(gs.test_for_libsymbol, 
            self.opts.class_namespaces)(self.known_globals_bases))
        not_confsymbol = lambda node: globals_table[node] not in self.opts.allowed_globals
        def warn_appender(global_nodes):
            for node in global_nodes:
                issue = warn("Unknown global symbol used: '%s'" % globals_table[node], self.file_name, node)
                issue.name = globals_table[node] # @deprecated {3.0} to filter against #ignore later
                self.issues.append(issue)

        # ------------------------------
        # collect scope's global use locations
        globals_table = {} # {node: assembled}
        for id_, scopeVar in scope.globals().items():
            for head_node in scopeVar.uses:
                var_top = treeutil.findVarRoot(head_node)
                assembled = (treeutil.assembleVariable(var_top))[0]
                globals_table[head_node] = assembled

        # filter and add remains to warnings
        pipeline(
            globals_table.keys()
            , bind(filter, not_builtin)
            , bind(filter, not_jsignored)
            , bind(filter, not_libsymbol)
            , bind(filter, not_confsymbol)
            , warn_appender
            )