django/django

View on GitHub

File qunit.js has 3181 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * QUnit 2.0.1
 * https://qunitjs.com/
 *
 * Copyright jQuery Foundation and other contributors
Severity: Major
Found in js_tests/qunit/qunit.js - About 1 wk to fix

    Function templatize has a Cognitive Complexity of 204 (exceeds 5 allowed). Consider refactoring.
    Open

    def templatize(src, origin=None):
        """
        Turn a Django template into something that is understood by xgettext. It
        does so by translating the Django translation tags into standard gettext
        function invocations.
    Severity: Minor
    Found in django/utils/translation/template.py - About 4 days 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 diff has 732 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    QUnit.diff = ( function() {
        function DiffMatchPatch() {
        }
    
        //  DIFF FUNCTIONS
    Severity: Major
    Found in js_tests/qunit/qunit.js - About 3 days to fix

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

      class AlterUniqueTogether(FieldRelatedOptionOperation):
          """
          Change the value of unique_together to the target one.
          Input value of unique_together must be a set of tuples.
          """
      Severity: Major
      Found in django/db/migrations/operations/models.py and 1 other location - About 3 days to fix
      django/db/migrations/operations/models.py on lines 544..595

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

      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

      class AlterIndexTogether(FieldRelatedOptionOperation):
          """
          Change the value of index_together to the target one.
          Input value of index_together must be a set of tuples.
          """
      Severity: Major
      Found in django/db/migrations/operations/models.py and 1 other location - About 3 days to fix
      django/db/migrations/operations/models.py on lines 490..541

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

      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

      File compiler.py has 1168 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import collections
      import functools
      import re
      import warnings
      from itertools import chain
      Severity: Major
      Found in django/db/models/sql/compiler.py - About 3 days to fix

        File autodetector.py has 1055 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import functools
        import re
        from itertools import chain
        
        from django.conf import settings
        Severity: Major
        Found in django/db/migrations/autodetector.py - About 2 days to fix

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

          class TemplateTagIndexView(BaseAdminDocsView):
              template_name = 'admin_doc/template_tag_index.html'
          
              def get_context_data(self, **kwargs):
                  tags = []
          Severity: Major
          Found in django/contrib/admindocs/views.py and 1 other location - About 2 days to fix
          django/contrib/admindocs/views.py on lines 94..125

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

          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

          class TemplateFilterIndexView(BaseAdminDocsView):
              template_name = 'admin_doc/template_filter_index.html'
          
              def get_context_data(self, **kwargs):
                  filters = []
          Severity: Major
          Found in django/contrib/admindocs/views.py and 1 other location - About 2 days to fix
          django/contrib/admindocs/views.py on lines 60..91

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

          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

          File checks.py has 859 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          from itertools import chain
          
          from django.apps import apps
          from django.conf import settings
          from django.contrib.admin.utils import (
          Severity: Major
          Found in django/contrib/admin/checks.py - About 2 days to fix

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

            class SHA1PasswordHasher(BasePasswordHasher):
                """
                The SHA1 password hashing algorithm (not recommended)
                """
                algorithm = "sha1"
            Severity: Major
            Found in django/contrib/auth/hashers.py and 1 other location - About 2 days to fix
            django/contrib/auth/hashers.py on lines 505..532

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

            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

            class MD5PasswordHasher(BasePasswordHasher):
                """
                The Salted MD5 password hashing algorithm (not recommended)
                """
                algorithm = "md5"
            Severity: Major
            Found in django/contrib/auth/hashers.py and 1 other location - About 2 days to fix
            django/contrib/auth/hashers.py on lines 474..501

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

            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 delta.days != 0:
                        return pgettext(
                            'naturaltime', '%(delta)s ago'
                        ) % {'delta': defaultfilters.timesince(value, now)}
                    elif delta.seconds == 0:
            Severity: Major
            Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
            django/contrib/humanize/templatetags/humanize.py on lines 249..274

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

            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 delta.days != 0:
                        return pgettext(
                            'naturaltime', '%(delta)s from now'
                        ) % {'delta': defaultfilters.timeuntil(value, now)}
                    elif delta.seconds == 0:
            Severity: Major
            Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
            django/contrib/humanize/templatetags/humanize.py on lines 221..246

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

            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

            Function _build_migration_list has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring.
            Open

                def _build_migration_list(self, graph=None):
                    """
                    Chop the lists of operations up into migrations with dependencies on
                    each other. Do this by going through an app's list of operations until
                    one is found that has an outgoing dependency that isn't in another
            Severity: Minor
            Found in django/db/migrations/autodetector.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

            File models.py has 690 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            from django.db import models
            from django.db.migrations.operations.base import Operation
            from django.db.migrations.state import ModelState
            from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
            from django.db.models.options import normalize_together
            Severity: Major
            Found in django/db/migrations/operations/models.py - About 1 day to fix

              File six.py has 662 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              """Utilities for writing code that runs on Python 2 and 3"""
              
              # Copyright (c) 2010-2015 Benjamin Peterson
              #
              # Permission is hereby granted, free of charge, to any person obtaining a copy
              Severity: Major
              Found in django/utils/six.py - About 1 day to fix

                Function handle_inspection has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
                Open

                    def handle_inspection(self, options):
                        connection = connections[options['database']]
                        # 'table_name_filter' is a stealth option
                        table_name_filter = options.get('table_name_filter')
                
                
                Severity: Minor
                Found in django/core/management/commands/inspectdb.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

                GEOSGeometryBase has 77 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class GEOSGeometryBase(GEOSBase):
                
                    _GEOS_CLASSES = None
                
                    ptr_type = GEOM_PTR
                Severity: Major
                Found in django/contrib/gis/geos/geometry.py - About 1 day to fix

                  Function handle has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def handle(self, *args, **options):
                          username = options[self.UserModel.USERNAME_FIELD]
                          database = options['database']
                  
                          # If not provided, create the user with an unusable password
                  Severity: Minor
                  Found in django/contrib/auth/management/commands/createsuperuser.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

                  Severity
                  Category
                  Status