Example #1
0
    def run(path, code=None, params=None, ignore=None, select=None, **meta):
        """Check code with Radon.

        :return list: List of errors.
        """
        complexity = params.get('complexity', 10)
        no_assert = params.get('no_assert', False)
        show_closures = params.get('show_closures', False)

        visitor = ComplexityVisitor.from_code(code, no_assert=no_assert)
        blocks = visitor.blocks
        if show_closures:
            blocks = add_inner_blocks(blocks)

        return [{
            'lnum':
            block.lineno,
            'col':
            block.col_offset,
            'type':
            'R',
            'number':
            'R709',
            'text':
            'R701: %s is too complex %d' % (block.name, block.complexity)
        } for block in visitor.blocks if block.complexity > complexity]
Example #2
0
    def run(path, code=None, params=None, ignore=None, select=None, **meta):
        """Check code with Radon.

        :return list: List of errors.
        """
        complexity = params.get("complexity", 10)
        no_assert = params.get("no_assert", False)
        show_closures = params.get("show_closures", False)

        visitor = ComplexityVisitor.from_code(code, no_assert=no_assert)
        blocks = visitor.blocks
        if show_closures:
            blocks = add_inner_blocks(blocks)

        return [
            {
                "lnum": block.lineno,
                "col": block.col_offset,
                "type": "R",
                "number": "R709",
                "text": "R701: %s is too complex %d" % (block.name, block.complexity),
            }
            for block in visitor.blocks
            if block.complexity > complexity
        ]
Example #3
0
    def run_check(self, ctx: RunContext):  # noqa  # noqa
        """Check code with Radon."""
        params = ctx.get_params("radon")
        options = ctx.options
        if options:
            params.setdefault("complexity", options.max_complexity)
            params.setdefault("no_assert", options.radon_no_assert)
            params.setdefault("show_closures", options.radon_show_closures)

        complexity = params.get("complexity", 10)
        no_assert = params.get("no_assert", False)
        show_closures = params.get("show_closures", False)
        visitor = ComplexityVisitor.from_code(ctx.source, no_assert=no_assert)
        blocks = visitor.blocks
        if show_closures:
            blocks = add_inner_blocks(blocks)
        for block in visitor.blocks:
            if block.complexity > complexity:
                ctx.push(
                    lnum=block.lineno,
                    col=block.col_offset + 1,
                    source="radon",
                    type="R",
                    number="R901",
                    text=f"{block.name} is too complex {block.complexity}",
                )
Example #4
0
    def run(self):
        '''Run the ComplexityVisitor over the AST tree.'''
        if self.max_cc < 0:
            if not self.no_assert:
                return
            self.max_cc = 10
        visitor = ComplexityVisitor.from_ast(self.tree,
                                             no_assert=self.no_assert)

        blocks = visitor.blocks
        if self.show_closures:
            blocks = add_inner_blocks(blocks)

        for block in blocks:
            if block.complexity > self.max_cc:
                text = self._error_tmpl % (block.name, block.complexity)
                yield block.lineno, block.col_offset, text, type(self)
Example #5
0
 def gobble(self, fobj):
     '''Analyze the content of the file object.'''
     r = cc_visit(fobj.read(), no_assert=self.config.no_assert)
     if self.config.show_closures:
         r = add_inner_blocks(r)
     return sorted_results(r, order=self.config.order)
Example #6
0
 def gobble(self, fobj):
     '''Analyze the content of the file object.'''
     r = cc_visit(fobj.read(), no_assert=self.config.no_assert)
     if self.config.show_closures:
         r = add_inner_blocks(r)
     return sorted_results(r, order=self.config.order)