tools/closure_linter/closure_linter/ecmametadatapass.py

Summary

Maintainability
D
2 days
Test Coverage

Function _ProcessContext has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
Open

  def _ProcessContext(self):
    """Process the context at the current token.

    Returns:
      The context that should be assigned to the current token, or None if
Severity: Minor
Found in tools/closure_linter/closure_linter/ecmametadatapass.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 ecmametadatapass.py has 341 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
#
# Copyright 2010 The Closure Linter Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Severity: Minor
Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 4 hrs to fix

    Consider simplifying this complex logical expression.
    Open

          if (is_last_code_in_line and
              self._StatementCouldEndInContext() and
              not is_multiline_string and
              not is_end_of_block and
              not is_continued_identifier and
    Severity: Critical
    Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

          if token.type != TokenType.SEMICOLON:
            next_code = tokenutil.SearchExcept(token, TokenType.NON_CODE_TYPES)
            # A statement like if (x) does not need a semicolon after it
            is_implied_block = self._context == EcmaContext.IMPLIED_BLOCK
            is_last_code_in_line = token.IsCode() and (
      Severity: Critical
      Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 1 hr to fix

        Function _ProcessToken has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def _ProcessToken(self):
            """Process the given token."""
            token = self._token
            token.metadata = self._CreateMetaData()
            context = (self._ProcessContext() or self._context)
        Severity: Minor
        Found in tools/closure_linter/closure_linter/ecmametadatapass.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

        Consider simplifying this complex logical expression.
        Open

              if (self._last_code.type in (TokenType.END_PAREN,
                                           TokenType.END_PARAMETERS) or
                  self._last_code.IsKeyword('else') or
                  self._last_code.IsKeyword('do') or
                  self._last_code.IsKeyword('try') or
        Severity: Major
        Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 1 hr to fix

          Function _GetOperatorType has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def _GetOperatorType(self, token):
              """Returns the operator type of the given operator token.
          
              Args:
                token: The token to get arity for.
          Severity: Minor
          Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 45 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 too many return statements within this function.
          Open

              return EcmaMetaData.BINARY_OPERATOR
          Severity: Major
          Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return EcmaMetaData.UNARY_OPERATOR
            Severity: Major
            Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return context
              Severity: Major
              Found in tools/closure_linter/closure_linter/ecmametadatapass.py - About 30 mins to fix

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

                  def __init__(self, type, start_token, parent):
                    """Initializes the context object.
                
                    Args:
                      type: The context type.
                Severity: Minor
                Found in tools/closure_linter/closure_linter/ecmametadatapass.py and 1 other location - About 30 mins to fix
                tools/closure_linter/closure_linter/common/matcher.py on lines 46..60

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

                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