tools/closure_linter/closure_linter/ecmalintrules.py

Summary

Maintainability
F
1 wk
Test Coverage

Function CheckToken has a Cognitive Complexity of 291 (exceeds 5 allowed). Consider refactoring.
Open

  def CheckToken(self, token, state):
    """Checks a token, given the current parser_state, for warnings and errors.

    Args:
      token: The current token under consideration
Severity: Minor
Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 5 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

File ecmalintrules.py has 518 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
#
# Copyright 2008 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/ecmalintrules.py - About 1 day to fix

    Function _CheckLineLength has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

      def _CheckLineLength(self, last_token, state):
        """Checks whether the line is too long.
    
        Args:
          last_token: The last token in the line.
    Severity: Minor
    Found in tools/closure_linter/closure_linter/ecmalintrules.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 _CheckJsDocType has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def _CheckJsDocType(self, token):
        """Checks the given type for style errors.
    
        Args:
          token: The DOC_FLAG token for the flag whose type to check.
    Severity: Minor
    Found in tools/closure_linter/closure_linter/ecmalintrules.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

    Avoid deeply nested control flow statements.
    Open

                if not is_immediately_called and (last_in_line or
                    not token.next.type == Type.SEMICOLON):
                  self._HandleError(errors.MISSING_SEMICOLON_AFTER_FUNCTION,
                      'Missing semicolon after function assigned to a variable',
                      token, Position.AtEnd(token.string))
    Severity: Major
    Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if not last_in_line and token.next.type == Type.SEMICOLON:
                    self._HandleError(errors.ILLEGAL_SEMICOLON_AFTER_FUNCTION,
                        'Illegal semicolon after function declaration',
                        token.next, Position.All(token.next.string))
      
      
      Severity: Major
      Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if end_token.type in Type.FLAG_DESCRIPTION_TYPES:
                      end_string = htmlutil.StripTags(end_token.string).rstrip()
        
        
        Severity: Major
        Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if jsdoc.HasFlag('override'):
                        self._HandleError(errors.INVALID_OVERRIDE_PRIVATE,
                            '%s should not override a private member.' % identifier,
                            jsdoc.GetFlag('override').flag_token)
                      # Can have a private class which inherits documentation from a
          Severity: Major
          Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if jsdoc.HasFlag('private') and 'underscore' in jsdoc.suppressions:
                          self._HandleError(errors.UNNECESSARY_SUPPRESS,
                              '@suppress {underscore} is not necessary with @private',
                              jsdoc.suppressions['underscore'])
                      elif jsdoc.HasFlag('private'):
            Severity: Major
            Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          if op == 'I':
                            # Insertion.
                            # Parsing doc comments is the same for all languages
                            # but some languages care about parameters that don't have
                            # doc comments and some languages don't care.
              Severity: Major
              Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if jsdoc.HasFlag('inheritDoc') and not jsdoc.HasFlag('constructor'):
                              self._HandleError(errors.INVALID_INHERIT_DOC_PRIVATE,
                                  '%s should not inherit from a private member.' % identifier,
                                  jsdoc.GetFlag('inheritDoc').flag_token)
                            if (not jsdoc.HasFlag('private') and
                Severity: Major
                Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if not (comment and comment.lower().count('jsdoc inherited')):
                                self._HandleError(errors.MISSING_MEMBER_DOCUMENTATION,
                                    "No docs found for member '%s'" % identifier,
                                    token);
                          elif jsdoc and (not state.InConstructor() or
                  Severity: Major
                  Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                while desc_str.endswith('>'):
                                  start_tag_index = desc_str.rfind('<')
                                  if start_tag_index < 0:
                                    break              
                                  desc_str = desc_str[:start_tag_index].rstrip()
                    Severity: Major
                    Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  if (not jsdoc.HasFlag('private') and
                                      not ('underscore' in jsdoc.suppressions)):
                                    self._HandleError(errors.MISSING_PRIVATE,
                                        'Member "%s" must have @private JsDoc.' %
                                        identifier, token)
                      Severity: Major
                      Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 45 mins to fix

                        Consider simplifying this complex logical expression.
                        Open

                              if state.GetFunction().is_interface:
                                if token.previous and token.previous.type == Type.PARAMETERS:
                                  self._HandleError(errors.INTERFACE_CONSTRUCTOR_CANNOT_HAVE_PARAMS,
                                      'Interface constructor cannot have parameters',
                                      token.previous)
                        Severity: Major
                        Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 40 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                if (not first_in_line and token.previous.type == Type.WHITESPACE and
                                    last_non_space_token and
                                    last_non_space_token.type in Type.EXPRESSION_ENDER_TYPES):
                                  self._HandleError(errors.EXTRA_SPACE, 'Extra space before "["',
                                      token.previous, Position.All(token.previous.string))
                          Severity: Major
                          Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 40 mins to fix

                            Consider simplifying this complex logical expression.
                            Open

                                  if (token.previous and token.previous.type == Type.WHITESPACE and
                                      not token.previous.IsFirstInLine() and
                                      not (last_non_space_token and last_non_space_token.line_number ==
                                               token.line_number and
                                           last_non_space_token.type == Type.SEMICOLON)):
                            Severity: Major
                            Found in tools/closure_linter/closure_linter/ecmalintrules.py - About 40 mins to fix

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

                                    if (token.previous and token.previous.type == Type.WHITESPACE and
                                        not token.previous.IsFirstInLine() and
                                        not (last_non_space_token and last_non_space_token.line_number ==
                                                 token.line_number and
                                             last_non_space_token.type == Type.SEMICOLON)):
                              Severity: Minor
                              Found in tools/closure_linter/closure_linter/ecmalintrules.py and 1 other location - About 40 mins to fix
                              tools/closure_linter/closure_linter/ecmalintrules.py on lines 435..439

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

                              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 (token.previous and token.previous.type == Type.WHITESPACE and
                                          last_code and last_code.type in (Type.NORMAL, Type.IDENTIFIER)):
                                        self._HandleError(errors.EXTRA_SPACE,
                                            'Extra space before "%s"' % token.string, token.previous,
                                            Position.All(token.previous.string))
                              Severity: Minor
                              Found in tools/closure_linter/closure_linter/ecmalintrules.py and 1 other location - About 40 mins to fix
                              tools/closure_linter/closure_linter/ecmalintrules.py on lines 393..399

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

                              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 last_code.IsOperator(','):
                                      self._HandleError(errors.COMMA_AT_END_OF_LITERAL,
                                          'Illegal comma at end of object literal', last_code,
                                          Position.All(last_code.string))
                              Severity: Minor
                              Found in tools/closure_linter/closure_linter/ecmalintrules.py and 1 other location - About 30 mins to fix
                              tools/closure_linter/closure_linter/ecmalintrules.py on lines 403..406

                              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

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

                                      if last_code.IsOperator(','):
                                        self._HandleError(errors.COMMA_AT_END_OF_LITERAL,
                                            'Illegal comma at end of array literal', last_code,
                                            Position.All(last_code.string))
                              Severity: Minor
                              Found in tools/closure_linter/closure_linter/ecmalintrules.py and 1 other location - About 30 mins to fix
                              tools/closure_linter/closure_linter/ecmalintrules.py on lines 284..287

                              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

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

                                      if token.IsFirstInLine():
                                        self._HandleError(errors.ILLEGAL_TAB,
                                            'Illegal tab in whitespace before "%s"' % token.next.string,
                                            token, Position.All(token.string))
                              Severity: Minor
                              Found in tools/closure_linter/closure_linter/ecmalintrules.py and 2 other locations - About 30 mins to fix
                              tools/closure_linter/closure_linter/ecmalintrules.py on lines 410..417
                              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 278..285

                              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