django/django

View on GitHub
django/contrib/staticfiles/storage.py

Summary

Maintainability
D
2 days
Test Coverage

Function _post_process has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    def _post_process(self, paths, adjustable_paths, hashed_files):
        # Sort the files by directory level
        def path_level(name):
            return len(name.split(os.sep))

Severity: Minor
Found in django/contrib/staticfiles/storage.py - About 6 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 storage.py has 327 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import hashlib
import json
import os
import posixpath
import re
Severity: Minor
Found in django/contrib/staticfiles/storage.py - About 3 hrs to fix

    Function url_converter has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def url_converter(self, name, hashed_files, template=None):
            """
            Return the custom URL converter for the given file name.
            """
            if template is None:
    Severity: Minor
    Found in django/contrib/staticfiles/storage.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 _url has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def _url(self, hashed_name_func, name, force=False, hashed_files=None):
            """
            Return the non-hashed URL in DEBUG mode.
            """
            if settings.DEBUG and not force:
    Severity: Minor
    Found in django/contrib/staticfiles/storage.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 hashed_name has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def hashed_name(self, name, content=None, filename=None):
            # `filename` is the name of file to hash if `content` isn't given.
            # `name` is the base name to construct the new hashed filename from.
            parsed_name = urlsplit(unquote(name))
            clean_name = parsed_name.path.strip()
    Severity: Minor
    Found in django/contrib/staticfiles/storage.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 post_process has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def post_process(self, paths, dry_run=False, **options):
            """
            Post process the given dictionary of files (called from collectstatic).
    
            Processing is actually two separate operations:
    Severity: Minor
    Found in django/contrib/staticfiles/storage.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

    Avoid deeply nested control flow statements.
    Open

                            if matches_patterns(path, (extension,)):
                                for pattern, template in patterns:
                                    converter = self.url_converter(name, hashed_files, template)
                                    try:
                                        content = pattern.sub(converter, content)
    Severity: Major
    Found in django/contrib/staticfiles/storage.py - About 45 mins to fix

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

          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              self._patterns = {}
              self.hashed_files = {}
              for extension, patterns in self.patterns:
      Severity: Minor
      Found in django/contrib/staticfiles/storage.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

      There are no issues that match your filters.

      Category
      Status