tools/closure_linter/closure_linter/statetracker.py

Summary

Maintainability
F
4 days
Test Coverage

File statetracker.py has 709 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
#
# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Severity: Major
Found in tools/closure_linter/closure_linter/statetracker.py - About 1 day to fix

    Function HandleToken has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
    Open

      def HandleToken(self, token, last_non_space_token):
        """Handles the given token and updates state.
    
        Args:
          token: The token to handle.
    Severity: Minor
    Found in tools/closure_linter/closure_linter/statetracker.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

    StateTracker has 31 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class StateTracker(object):
      """EcmaScript state tracker.
    
      Tracks block depth, function names, etc. within an EcmaScript token stream.
      """
    Severity: Minor
    Found in tools/closure_linter/closure_linter/statetracker.py - About 3 hrs to fix

      Function __init__ has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def __init__(self, flag_token):
          """Creates the DocFlag object and attaches it to the given start token.
      
          Args:
            flag_token: The starting token of the flag.
      Severity: Minor
      Found in tools/closure_linter/closure_linter/statetracker.py - About 3 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 CompareParameters has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def CompareParameters(self, params):
          """Computes the edit distance and list from the function params to the docs.
      
          Uses the Levenshtein edit distance algorithm, with code modified from
          http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance#Python
      Severity: Minor
      Found in tools/closure_linter/closure_linter/statetracker.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 InInterfaceMethod has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def InInterfaceMethod(self):
          """Returns true if the current token is within an interface method.
      
          Returns:
            True if the current token is within an interface method.
      Severity: Minor
      Found in tools/closure_linter/closure_linter/statetracker.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 _GetEndTokenAndContents has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def _GetEndTokenAndContents(start_token):
        """Returns last content token and all contents before FLAG_ENDING_TYPE token.
      
        Comment prefixes are split into DOC_PREFIX tokens and stripped from the
        returned contents.
      Severity: Minor
      Found in tools/closure_linter/closure_linter/statetracker.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 type == Type.START_BLOCK:
            self._block_depth += 1
      
            # Subclasses need to handle block start very differently because
            # whether a block is a CODE or OBJECT_LITERAL block varies significantly
      Severity: Major
      Found in tools/closure_linter/closure_linter/statetracker.py - About 1 hr to fix

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

        def _GetMatchingEndBraceAndContents(start_brace):
          """Returns the matching end brace and contents between the two braces.
        
          If any FLAG_ENDING_TYPE token is encountered before a matching end brace, then
          that token is used as the matching ending token. Contents will have all
        Severity: Minor
        Found in tools/closure_linter/closure_linter/statetracker.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 deeply nested control flow statements.
        Open

                    if not identifier or not identifier.type in Type.NON_CODE_TYPES:
                      break
        
        
        Severity: Major
        Found in tools/closure_linter/closure_linter/statetracker.py - About 45 mins to fix

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

            def HandleAfterToken(self, token):
              """Handle updating state after a token has been checked.
          
              This function should be used for destructive state changes such as
              deleting a tracked object.
          Severity: Minor
          Found in tools/closure_linter/closure_linter/statetracker.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

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

              if token.type == Type.DOC_START_BRACE:
                open_count += 1
              elif token.type == Type.DOC_END_BRACE:
                close_count += 1
          Severity: Major
          Found in tools/closure_linter/closure_linter/statetracker.py and 1 other location - About 1 hr to fix
          deps/v8/tools/ll_prof.py on lines 966..971

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

          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