tools/closure_linter/closure_linter/javascriptlintrules.py

Summary

Maintainability
F
5 days
Test Coverage

Function CheckToken has a Cognitive Complexity of 106 (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/javascriptlintrules.py - About 2 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

Function Finalize has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

  def Finalize(self, state, tokenizer_mode):
    """Perform all checks that need to occur after all lines are processed."""
    # Call the base class's Finalize function.
    super(JavaScriptLintRules, self).Finalize(state, tokenizer_mode)

Severity: Minor
Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 4 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

File javascriptlintrules.py has 288 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: Minor
Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

              if (function.has_return and function.doc and
                  not is_immediately_called and
                  not function.doc.HasFlag('return') and
                  not function.doc.InheritsDocumentation() and
                  not function.doc.HasFlag('constructor')):
    Severity: Critical
    Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  if (return_flag.type is None or (
                      'undefined' not in return_flag.type and
                      'void' not in return_flag.type and
                      '*' not in return_flag.type)):
                    self._HandleError(
      Severity: Major
      Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 45 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if (function.has_this and function.doc and
                    not function.doc.HasFlag('this') and
                    not function.is_constructor and
                    not function.is_interface and
                    '.prototype.' not in function.name):
        Severity: Major
        Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                  if (flag.flag_type not in ('suppress', 'enum') and
                      (flag.type == None or flag.type == '' or flag.type.isspace())):
                    self._HandleError(errors.MISSING_JSDOC_TAG_TYPE,
                                      'Missing type in %s tag' % token.string, token)
          
          
          Severity: Major
          Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                  if (FLAGS.strict and not self._is_html and state.InTopLevel() and
                      not state.InBlock()):
            
                    # Check if we're in a fileoverview or constructor JsDoc.
                    doc_comment = state.GetDocComment()
            Severity: Major
            Found in tools/closure_linter/closure_linter/javascriptlintrules.py - About 40 mins to fix

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

                    if extra_requires:
                      self._HandleError(
                          errors.EXTRA_GOOG_REQUIRE,
                          'The following goog.require statements appear unnecessary:\n' +
                          '\n'.join(map(lambda x: 'goog.require(\'%s\');' % x,
              Severity: Major
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 2 other locations - About 3 hrs to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 340..346
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 363..369

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

              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 missing_requires:
                      self._HandleError(
                          errors.MISSING_GOOG_REQUIRE,
                          'Missing the following goog.require statements:\n' +
                          '\n'.join(map(lambda x: 'goog.require(\'%s\');' % x,
              Severity: Major
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 2 other locations - About 3 hrs to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 340..346
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 387..393

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

              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 missing_provides:
                      self._HandleError(
                          errors.MISSING_GOOG_PROVIDE,
                          'Missing the following goog.provide statements:\n' +
                          '\n'.join(map(lambda x: 'goog.provide(\'%s\');' % x,
              Severity: Major
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 2 other locations - About 3 hrs to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 363..369
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 387..393

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

              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 bad:
                    self._HandleError(
                        errors.GOOG_REQUIRES_NOT_ALPHABETIZED,
                        'goog.require classes must be alphabetized.  The correct code is:\n' +
                        '\n'.join(map(lambda x: 'goog.require(\'%s\');' % x,
              Severity: Major
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 1 other location - About 3 hrs to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 326..333

              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

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

                  if bad:
                    self._HandleError(
                        errors.GOOG_PROVIDES_NOT_ALPHABETIZED,
                        'goog.provide classes must be alphabetized.  The correct code is:\n' +
                        '\n'.join(map(lambda x: 'goog.provide(\'%s\');' % x,
              Severity: Major
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 1 other location - About 3 hrs to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 304..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 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

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

                  for item in provides:
                    if item != sorted_provides[index]:
                      bad = True
                      break
                    index += 1
              Severity: Minor
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 1 other location - About 45 mins to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 298..302

              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

                  for item in requires:
                    if item != sorted_requires[index]:
                      bad = True
                      break
                    index += 1
              Severity: Minor
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 1 other location - About 45 mins to fix
              tools/closure_linter/closure_linter/javascriptlintrules.py on lines 320..324

              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 3 locations. Consider refactoring.
              Open

                      if (token.previous.type in (Type.START_PAREN, Type.START_BRACKET,
                                                  Type.FUNCTION_NAME)
                          or token.next.type == Type.START_PARAMETERS):
                        self._HandleError(
                            errors.EXTRA_SPACE,
              Severity: Minor
              Found in tools/closure_linter/closure_linter/javascriptlintrules.py and 2 other locations - About 30 mins to fix
              tools/closure_linter/closure_linter/ecmalintrules.py on lines 410..413
              tools/closure_linter/closure_linter/ecmalintrules.py on lines 410..417

              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