edgewall/trac

View on GitHub
contrib/jinjachecker.py

Summary

Maintainability
F
5 days
Test Coverage

Function check_jinja has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

def check_jinja(filename, line_statements, quiet):
    """Verifies proper nesting of Jinja2 control structures.
    """
    print("\n# -- Jinja2 check for '%s'" % filename)
    kw_stack = []
Severity: Minor
Found in contrib/jinjachecker.py - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function check_html has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
Open

def check_html(filename, html_lines, html_hints, quiet, show_ignored):
    """Validates the given HTML (as XHTML actually)
    """
    global etree
    print("\n# -- HTML check for '%s'" % filename)
Severity: Minor
Found in contrib/jinjachecker.py - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function scan has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

def scan(lines):
    """Scans template lines and separates Jinja2 structure from HTML structure.
    """

    def count_parens(line):
Severity: Minor
Found in contrib/jinjachecker.py - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File jinjachecker.py has 366 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016-2023 Edgewall Software
# All rights reserved.
Severity: Minor
Found in contrib/jinjachecker.py - About 4 hrs to fix

    Function remove_jinja_exprs has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_jinja_exprs(linenum, line, opened_braces):
        """This probably could be a one-liner... ;-)
        """
        idx = 0
        line = line.replace('$', '')
    Severity: Minor
    Found in contrib/jinjachecker.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function main has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        parser = argparse.ArgumentParser(description="""\
            If no flags are given, both jinja and html checks will be performed.
    
            An alternative usage is to run the tool via make, i.e. `make jinja`,
    Severity: Minor
    Found in contrib/jinjachecker.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

                            if line.strip().startswith(LINE_COMMENT_PREFIX):
                                check_for_hint(linenum, line)
                            else:
                                # check for a line statement
                                m = LINE_STATEMENT_RE.match(line)
    Severity: Major
    Found in contrib/jinjachecker.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if top and top.expr != s.expr:
                              warn.append(("'endblock %s' misplaced or misspelled,"
                                           " current block is '%s %s'") %
                                          (s.expr, top.kw, top.expr))
                      else:
      Severity: Major
      Found in contrib/jinjachecker.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if s.kw == top.kw:
                                kw_stack.pop()
                            else:
                                warn.append(("'end%s' misplaced, current block is"
                                             " '%s' (at line %d)") %
        Severity: Major
        Found in contrib/jinjachecker.py - About 45 mins to fix

          Function check_html has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def check_html(filename, html_lines, html_hints, quiet, show_ignored):
          Severity: Minor
          Found in contrib/jinjachecker.py - About 35 mins to fix

            Function print_statement has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def print_statement(filename, s, warn=None, quiet=False):
                if not quiet:
                    print('%5d %s %s%s%s%s' % (s.linenum,
                                               ' ' * s.indent,
                                               '}' if s.end else
            Severity: Minor
            Found in contrib/jinjachecker.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if not has_html_elt:
                        normalized_lines[0] = '<html>' + normalized_lines[0]
                        normalized_lines[-1] = normalized_lines[-1] + '</html>'
            Severity: Major
            Found in contrib/jinjachecker.py and 1 other location - About 2 hrs to fix
            contrib/jinjachecker.py on lines 359..361

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 54.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if not has_body_elt:
                        normalized_lines[0] = '<body>' + normalized_lines[0]
                        normalized_lines[-1] = normalized_lines[-1] + '</body>'
            Severity: Major
            Found in contrib/jinjachecker.py and 1 other location - About 2 hrs to fix
            contrib/jinjachecker.py on lines 364..366

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 54.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status