django/django

View on GitHub
django/template/defaultfilters.py

Summary

Maintainability
F
3 days
Test Coverage

File defaultfilters.py has 765 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Default variable filters."""

import random as random_module
import re
import types
Severity: Major
Found in django/template/defaultfilters.py - About 1 day to fix

    Function unordered_list has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def unordered_list(value, autoescape=True):
        """
        Recursively take a self-nested list and return an HTML unordered list --
        WITHOUT opening and closing <ul> tags.
    
    
    Severity: Minor
    Found in django/template/defaultfilters.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 floatformat has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def floatformat(text, arg=-1):
        """
        Display a float to a specified number of decimal places.
    
        If called without an argument, display the floating point number with one
    Severity: Minor
    Found in django/template/defaultfilters.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 _property_resolver has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _property_resolver(arg):
        """
        When arg is convertible to float, behave like operator.itemgetter(arg)
        Otherwise, chain __getitem__() and getattr().
    
    
    Severity: Minor
    Found in django/template/defaultfilters.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 filesizeformat has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def filesizeformat(bytes_):
        """
        Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
        102 bytes, etc.).
        """
    Severity: Minor
    Found in django/template/defaultfilters.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 pluralize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def pluralize(value, arg="s"):
        """
        Return a plural suffix if the value is not 1, '1', or an object of
        length 1. By default, use 's' as the suffix:
    
    
    Severity: Minor
    Found in django/template/defaultfilters.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 linenumbers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def linenumbers(value, autoescape=True):
        """Display text with line numbers."""
        lines = value.split("\n")
        # Find the maximum width of the line count, for use with zero padding
        # string format command
    Severity: Minor
    Found in django/template/defaultfilters.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

    Avoid too many return statements within this function.
    Open

        return mark_safe(
    Severity: Major
    Found in django/template/defaultfilters.py - About 30 mins to fix

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

      @register.filter(is_safe=False)
      def first(value):
          """Return the first item in a list."""
          try:
              return value[0]
      Severity: Major
      Found in django/template/defaultfilters.py and 1 other location - About 1 hr to fix
      django/template/defaultfilters.py on lines 606..612

      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 38.

      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

      @register.filter(is_safe=True)
      def last(value):
          """Return the last item in a list."""
          try:
              return value[-1]
      Severity: Major
      Found in django/template/defaultfilters.py and 1 other location - About 1 hr to fix
      django/template/defaultfilters.py on lines 584..590

      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 38.

      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 3 locations. Consider refactoring.
      Open

      @register.filter(is_safe=True)
      @stringfilter
      def rjust(value, arg):
          """Right-align the value in a field of a given width."""
          return value.rjust(int(arg))
      Severity: Major
      Found in django/template/defaultfilters.py and 2 other locations - About 40 mins to fix
      django/template/defaultfilters.py on lines 402..406
      django/template/defaultfilters.py on lines 416..420

      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 34.

      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

      @register.filter(is_safe=True)
      def safeseq(value):
          """
          A "safe" filter for sequences. Mark each element in the sequence,
          individually, as safe, after converting them to strings. Return a list
      Severity: Minor
      Found in django/template/defaultfilters.py and 1 other location - About 40 mins to fix
      django/template/defaultfilters.py on lines 446..453

      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 34.

      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 3 locations. Consider refactoring.
      Open

      @register.filter(is_safe=True)
      @stringfilter
      def ljust(value, arg):
          """Left-align the value in a field of a given width."""
          return value.ljust(int(arg))
      Severity: Major
      Found in django/template/defaultfilters.py and 2 other locations - About 40 mins to fix
      django/template/defaultfilters.py on lines 409..413
      django/template/defaultfilters.py on lines 416..420

      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 34.

      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

      @register.filter(is_safe=True)
      def escapeseq(value):
          """
          An "escape" filter for sequences. Mark each element in the sequence,
          individually, as a string that should be auto-escaped. Return a list with
      Severity: Minor
      Found in django/template/defaultfilters.py and 1 other location - About 40 mins to fix
      django/template/defaultfilters.py on lines 500..507

      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 34.

      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 3 locations. Consider refactoring.
      Open

      @register.filter(is_safe=True)
      @stringfilter
      def center(value, arg):
          """Center the value in a field of a given width."""
          return value.center(int(arg))
      Severity: Major
      Found in django/template/defaultfilters.py and 2 other locations - About 40 mins to fix
      django/template/defaultfilters.py on lines 402..406
      django/template/defaultfilters.py on lines 409..413

      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 34.

      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