edgewall/trac

View on GitHub
trac/dist.py

Summary

Maintainability
F
5 days
Test Coverage

Function extract_python has a Cognitive Complexity of 93 (exceeds 5 allowed). Consider refactoring.
Open

    def extract_python(fileobj, keywords, comment_tags, options):
        """Extract messages from Python source code, This is patched
        extract_python from Babel to support keyword argument mapping.

        `kwargs_maps` option: names of keyword arguments will be mapping to
Severity: Minor
Found in trac/dist.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 dist.py has 516 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2011-2023 Edgewall Software
# All rights reserved.
#
Severity: Major
Found in trac/dist.py - About 1 day to fix

    Function write_js has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def write_js(fileobj, catalog, domain, locale):
            from trac.util.presentation import to_json
            data = {'domain': domain, 'locale': locale}
    
            messages = {}
    Severity: Minor
    Found in trac/dist.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

    Consider simplifying this complex logical expression.
    Open

                if call_stack == -1 and tok == NAME and value in ('def', 'class'):
                    in_def = True
                elif tok == OP and value == '(':
                    if in_def:
                        # Avoid false positives for declarations such as:
    Severity: Critical
    Found in trac/dist.py - About 2 hrs to fix

      Function check_markup has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def check_markup(catalog, message):
              """Verify markups in the translation."""
              def to_array(value):
                  if not isinstance(value, (list, tuple)):
                      value = (value,)
      Severity: Minor
      Found in trac/dist.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 run has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

              def run(self):
                  mo_files = []
                  js_files = []
      
                  def js_path(dir, locale):
      Severity: Minor
      Found in trac/dist.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 extract_html has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def extract_html(fileobj, keywords, comment_tags, options):
              """Extracts translatable texts from templates.
      
              We simplify white-space found in translatable texts collected
              via the ``gettext`` function (which is what the ``trans``
      Severity: Minor
      Found in trac/dist.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 name not in func_kwargs_map:
                                  continue
                              index = func_kwargs_map[name]
      Severity: Major
      Found in trac/dist.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if kwarg_name in func_kwargs_map:
                                    messages_kwargs[kwarg_name] = message
                                else:
                                    messages.append(message)
                                del buf[:]
        Severity: Major
        Found in trac/dist.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  while index >= len(messages):
                                      messages.append(None)
                                  messages[index - 1] = message
          Severity: Major
          Found in trac/dist.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if kwarg_name in func_kwargs_map:
                                        messages_kwargs[kwarg_name] = message
                                    else:
                                        messages.append(message)
                                    del buf[:]
            Severity: Major
            Found in trac/dist.py - About 45 mins to fix

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

                  def _check_markup_0(msgid, msgid_name, msgstr, msgstr_name):
                      from xml.etree import ElementTree
              
                      def count_tags(text):
                          buf = io.StringIO()
              Severity: Minor
              Found in trac/dist.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 run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                      def run(self):
                          for filename in self._get_po_files():
                              distlog.info('checking catalog %s', filename)
                              with open(filename, 'rb') as f:
                                  catalog = read_po(f, domain=self.domain)
              Severity: Minor
              Found in trac/dist.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

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

                                  if buf:
                                      message = ''.join(buf)
                                      if kwarg_name in func_kwargs_map:
                                          messages_kwargs[kwarg_name] = message
                                      else:
              Severity: Major
              Found in trac/dist.py and 1 other location - About 3 hrs to fix
              trac/dist.py on lines 191..199

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

              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

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

                                  if buf:
                                      message = ''.join(buf)
                                      if kwarg_name in func_kwargs_map:
                                          messages_kwargs[kwarg_name] = message
                                      else:
              Severity: Major
              Found in trac/dist.py and 1 other location - About 3 hrs to fix
              trac/dist.py on lines 244..252

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

              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