django/django

View on GitHub
django/utils/translation/template.py

Summary

Maintainability
F
5 days
Test Coverage

Function templatize has a Cognitive Complexity of 194 (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 3 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

Avoid deeply nested control flow statements.
Open

                    if translators_comment_start is not None and lineno >= translators_comment_start:
                        out.write(' # %s' % line)
                    else:
                        out.write(' #\n')
                incomment = False
Severity: Major
Found in django/utils/translation/template.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        for fmatch in constant_re.findall(t.contents):
                            out.write(' _(%s) ' % fmatch)
                        if bmatch.group(1):
    Severity: Major
    Found in django/utils/translation/template.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if imatch.group(2):
                              # A context is provided
                              context_match = context_re.match(imatch.group(2))
                              message_context = context_match.group(1)
                              if message_context[0] == '"':
      Severity: Major
      Found in django/utils/translation/template.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            for cmatch in cmatches:
                                out.write(' _(%s) ' % cmatch)
                        elif t.contents == 'comment':
        Severity: Major
        Found in django/utils/translation/template.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if p.find(':_(') >= 0:
                                  out.write(' %s ' % p.split(':', 1)[1])
                              else:
                                  out.write(blankout(p, 'F'))
                      elif t.token_type == TokenType.COMMENT:
          Severity: Major
          Found in django/utils/translation/template.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if line.lstrip().startswith(TRANSLATOR_COMMENT_MARK):
                                    translators_comment_start = lineno
                            for lineno, line in enumerate(content.splitlines(True)):
            Severity: Major
            Found in django/utils/translation/template.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if g[0] == '"':
                                      g = g.strip('"')
                                  elif g[0] == "'":
                                      g = g.strip("'")
                                  g = g.replace('%', '%%')
              Severity: Major
              Found in django/utils/translation/template.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if inplural:
                                        if message_context:
                                            out.write(' npgettext({p}{!r}, {p}{!r}, {p}{!r},count) '.format(
                                                message_context,
                                                join_tokens(singular, trimmed),
                Severity: Major
                Found in django/utils/translation/template.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if bmatch.group(1):
                                          # A context is provided
                                          context_match = context_re.match(bmatch.group(1))
                                          message_context = context_match.group(1)
                                          if message_context[0] == '"':
                  Severity: Major
                  Found in django/utils/translation/template.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if origin:
                                            filemsg = 'file %s, ' % origin
                                        raise SyntaxError(
                    Severity: Major
                    Found in django/utils/translation/template.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if t.token_type != TokenType.COMMENT:
                                              for c in lineno_comment_map[comment_lineno_cache]:
                                                  filemsg = ''
                                                  if origin:
                                                      filemsg = 'file %s, ' % origin
                      Severity: Major
                      Found in django/utils/translation/template.py - About 45 mins to fix

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

                                                if message_context[0] == '"':
                                                    message_context = message_context.strip('"')
                                                elif message_context[0] == "'":
                                                    message_context = message_context.strip("'")
                        Severity: Major
                        Found in django/utils/translation/template.py and 2 other locations - About 2 hrs to fix
                        django/utils/translation/template.py on lines 169..172
                        django/utils/translation/template.py on lines 178..181

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

                        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

                                                if message_context[0] == '"':
                                                    message_context = message_context.strip('"')
                                                elif message_context[0] == "'":
                                                    message_context = message_context.strip("'")
                        Severity: Major
                        Found in django/utils/translation/template.py and 2 other locations - About 2 hrs to fix
                        django/utils/translation/template.py on lines 169..172
                        django/utils/translation/template.py on lines 195..198

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

                        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

                                            if g[0] == '"':
                                                g = g.strip('"')
                                            elif g[0] == "'":
                                                g = g.strip("'")
                        Severity: Major
                        Found in django/utils/translation/template.py and 2 other locations - About 2 hrs to fix
                        django/utils/translation/template.py on lines 178..181
                        django/utils/translation/template.py on lines 195..198

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

                        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