django/django

View on GitHub
django/template/defaulttags.py

Summary

Maintainability
F
4 days
Test Coverage

File defaulttags.py has 1115 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Default tags used by the template system, available to all templates."""
import re
import sys
import warnings
from collections import namedtuple
Severity: Major
Found in django/template/defaulttags.py - About 2 days to fix

    Function render has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def render(self, context):
            if 'forloop' in context:
                parentloop = context['forloop']
            else:
                parentloop = {}
    Severity: Minor
    Found in django/template/defaulttags.py - About 2 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 cycle has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def cycle(parser, token):
        """
        Cycle among the given strings each time this tag is encountered.
    
        Within a loop, cycles among the given strings each time through
    Severity: Minor
    Found in django/template/defaulttags.py - About 2 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 render has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def render(self, context):
            from django.urls import reverse, NoReverseMatch
            args = [arg.resolve(context) for arg in self.args]
            kwargs = {k: v.resolve(context) for k, v in self.kwargs.items()}
            view_name = self.view_name.resolve(context)
    Severity: Minor
    Found in django/template/defaulttags.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

    Function render has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def render(self, context):
            for condition, nodelist in self.conditions_nodelists:
    
                if condition is not None:           # if / elif clause
                    try:
    Severity: Minor
    Found in django/template/defaulttags.py - About 55 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

    Function do_for has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def do_for(parser, token):
        """
        Loop over each item in an array.
    
        For example, to display a list of athletes given ``athlete_list``::
    Severity: Minor
    Found in django/template/defaulttags.py - About 55 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

    Function url has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def url(parser, token):
        r"""
        Return an absolute URL matching the given view with its parameters.
    
        This is a way to define links that aren't tied to a particular URL
    Severity: Minor
    Found in django/template/defaulttags.py - About 45 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

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

        def __init__(self, loopvars, sequence, is_reversed, nodelist_loop, nodelist_empty=None):
    Severity: Minor
    Found in django/template/defaulttags.py - About 35 mins to fix

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

          def __init__(self, var1, var2, nodelist_true, nodelist_false, negate):
      Severity: Minor
      Found in django/template/defaulttags.py - About 35 mins to fix

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

            def render(self, context):
                csrf_token = context.get('csrf_token')
                if csrf_token:
                    if csrf_token == 'NOTPROVIDED':
                        return format_html("")
        Severity: Minor
        Found in django/template/defaulttags.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

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

        def load_from_library(library, label, names):
            """
            Return a subset of tags and filters from a library.
            """
            subset = Library()
        Severity: Minor
        Found in django/template/defaulttags.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

        Function lorem has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def lorem(parser, token):
            """
            Create random Latin text useful for providing test data in templates.
        
            Usage format::
        Severity: Minor
        Found in django/template/defaulttags.py - About 25 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

        Function render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def render(self, context):
                try:
                    value = self.val_expr.resolve(context)
                    max_value = self.max_expr.resolve(context)
                    max_width = int(self.max_width.resolve(context))
        Severity: Minor
        Found in django/template/defaulttags.py - About 25 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

        There are no issues that match your filters.

        Category
        Status