edgewall/trac

View on GitHub
trac/web/chrome.py

Summary

Maintainability
F
1 wk
Test Coverage

File chrome.py has 1249 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2023 Edgewall Software
# Copyright (C) 2005-2006 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
Severity: Major
Found in trac/web/chrome.py - About 3 days to fix

    Function get_navigation_items has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_navigation_items(self, req, handler):
    
            def get_item_attributes(category, name, text):
                section = self.config[category]
                href = section.get(name + '.href')
    Severity: Minor
    Found in trac/web/chrome.py - About 7 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 populate_data has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def populate_data(self, req=None, data=None, d=None):
            """Fills a dictionary with the standard set of fields expected
            by templates.
    
            :param req: a `Request` object; if `None`, no request related fields
    Severity: Minor
    Found in trac/web/chrome.py - About 5 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

    Chrome has 39 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Chrome(Component):
        """Web site chrome assembly manager.
    
        Chrome is everything that is not actual page content.
        """
    Severity: Minor
    Found in trac/web/chrome.py - About 5 hrs to fix

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

          def render_template(self, req, filename, data, metadata):
              """Renders the ``filename`` template using ``data`` for the context.
      
              It attempts to load a Jinja2 template, augments the provided
              *data* with standard data, and renders it according to the
      Severity: Minor
      Found in trac/web/chrome.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 generate_template_stream has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def generate_template_stream(self, template, data, text=False,
                                       iterable=None):
              """Returns the rendered template in a form that can be "sent".
      
              This will be either a single UTF-8 encoded `btyes` object, or an
      Severity: Minor
      Found in trac/web/chrome.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 get_logo_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_logo_data(self, href, abs_href=None):
              # TODO: Possibly, links to 'common/' could use chrome.htdocs_location
              logo = {}
              logo_src = self.logo_src
              if logo_src:
      Severity: Minor
      Found in trac/web/chrome.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 format_author has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def format_author(self, req, author, resource=None, show_email=None):
              """Format a username in plain text.
      
              If `[trac]` `show_email_addresses` is `False`, email addresses
              will be obfuscated when the user doesn't have `EMAIL_VIEW`
      Severity: Minor
      Found in trac/web/chrome.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 iterable_content has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def iterable_content(self, stream, text=False, **kwargs):
              """Generate an iterable object which iterates `btyes` instances
              from the given stream instance.
      
              :param text: in text mode (``True``) XML/HTML auto-escape of
      Severity: Minor
      Found in trac/web/chrome.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 process_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_request(self, req):
              prefix = req.args['prefix']
              filename = req.args['filename']
      
              dirs = []
      Severity: Minor
      Found in trac/web/chrome.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 prevnext_nav has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def prevnext_nav(req, prev_label, next_label, up_label=None):
          """Add Previous/Up/Next navigation links.
      
             :param        req: a `Request` object
             :param prev_label: the label to use for left (previous) link
      Severity: Minor
      Found in trac/web/chrome.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 add_link has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def add_link(req, rel, href, title=None, mimetype=None, classname=None,
      Severity: Major
      Found in trac/web/chrome.py - About 50 mins to fix

        Function add_meta has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def add_meta(req, content, http_equiv=None, name=None, scheme=None, lang=None):
        Severity: Minor
        Found in trac/web/chrome.py - About 45 mins to fix

          Function web_context has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def web_context(req, resource=None, id=False, version=False, parent=False,
          Severity: Minor
          Found in trac/web/chrome.py - About 45 mins to fix

            Function prepare_template has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def prepare_template(self, req, filename, data, text=False, domain=None):
            Severity: Minor
            Found in trac/web/chrome.py - About 35 mins to fix

              Function generate_fragment has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def generate_fragment(self, req, filename, data, text=False, domain=None):
              Severity: Minor
              Found in trac/web/chrome.py - About 35 mins to fix

                Function render_fragment has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def render_fragment(self, req, filename, data, text=False, domain=None):
                Severity: Minor
                Found in trac/web/chrome.py - About 35 mins to fix

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

                      def get_icon_data(self, req):
                          icon = {}
                          icon_src = icon_abs_src = self.env.project_icon
                          if icon_src:
                              if not icon_src.startswith('/') and icon_src.find('://') == -1:
                  Severity: Minor
                  Found in trac/web/chrome.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 chrome_resource_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def chrome_resource_path(req, filename):
                      """Get the path for a chrome resource given its `filename`.
                  
                      If `filename` is a network-path reference (i.e. starts with a protocol
                      or `//`), the return value will not be modified. If `filename` is absolute
                  Severity: Minor
                  Found in trac/web/chrome.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

                  Function get_email_map has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_email_map(self):
                          """Get the email addresses of all known users."""
                          email_map = {}
                          if self.show_email_addresses:
                              for username, name, email in self.env.get_known_users():
                  Severity: Minor
                  Found in trac/web/chrome.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 dateonly:
                                      label = absolute
                                  elif req.lc_time == 'iso8601':
                                      label = _("at %(iso8601)s", iso8601=absolute)
                                  elif format == 'date':
                  Severity: Major
                  Found in trac/web/chrome.py and 1 other location - About 5 hrs to fix
                  trac/timeline/web_ui.py on lines 302..311

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

                  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 'prev' in links:
                          prev = links['prev'][0]
                          prev_link = tag.a(prev_label, href=prev['href'], title=prev['title'],
                  Severity: Major
                  Found in trac/web/chrome.py and 1 other location - About 2 hrs to fix
                  trac/web/chrome.py on lines 266..268

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

                  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 'next' in links:
                          next_ = links['next'][0]
                          next_link = tag.a(next_label, href=next_['href'], title=next_['title'],
                  Severity: Major
                  Found in trac/web/chrome.py and 1 other location - About 2 hrs to fix
                  trac/web/chrome.py on lines 254..256

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

                  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

                      def render_fragment(self, req, filename, data, text=False, domain=None):
                          """Produces a string from given template *filename* and input *data*,
                          with minimal overhead.
                  
                          It calls `prepare_template` to augment the *data* with the
                  Severity: Major
                  Found in trac/web/chrome.py and 1 other location - About 1 hr to fix
                  trac/web/chrome.py on lines 1420..1440

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

                  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

                      def generate_fragment(self, req, filename, data, text=False, domain=None):
                          """Produces content ready to be sent from the given template
                          *filename* and input *data*, with minimal overhead.
                  
                          It calls `prepare_template` to augment the *data* with the
                  Severity: Major
                  Found in trac/web/chrome.py and 1 other location - About 1 hr to fix
                  trac/web/chrome.py on lines 1442..1463

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

                  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 msg not in req.chrome[name]:
                          req.chrome[name].append(msg)
                  Severity: Minor
                  Found in trac/web/chrome.py and 1 other location - About 45 mins to fix
                  trac/web/chrome.py on lines 1373..1374

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

                  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 message not in req.chrome[type_]:
                                              req.chrome[type_].append(message)
                  Severity: Minor
                  Found in trac/web/chrome.py and 1 other location - About 45 mins to fix
                  trac/web/chrome.py on lines 227..228

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

                  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 format == 'date':
                                  absolute = user_time(req, format_date, date)
                              else:
                                  absolute = user_time(req, format_datetime, date)
                  Severity: Minor
                  Found in trac/web/chrome.py and 1 other location - About 35 mins to fix
                  trac/timeline/web_ui.py on lines 279..282

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

                  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