yannickcr/eslint-plugin-react

View on GitHub
lib/util/Components.js

Summary

Maintainability
F
1 wk
Test Coverage

Function componentRule has a Cognitive Complexity of 221 (exceeds 5 allowed). Consider refactoring.
Open

function componentRule(rule, context) {
  const pragma = pragmaUtil.getFromContext(context);
  const sourceCode = context.getSourceCode();
  const components = new Components();
  const wrapperFunctions = getWrapperFunctions(context, pragma);
Severity: Minor
Found in lib/util/Components.js - About 4 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 componentRule has 494 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function componentRule(rule, context) {
  const pragma = pragmaUtil.getFromContext(context);
  const sourceCode = context.getSourceCode();
  const components = new Components();
  const wrapperFunctions = getWrapperFunctions(context, pragma);
Severity: Major
Found in lib/util/Components.js - About 2 days to fix

    File Components.js has 680 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * @fileoverview Utility class and functions for React components detection
     * @author Yannick Croissant
     */
    
    
    Severity: Major
    Found in lib/util/Components.js - About 1 day to fix

      Function getStatelessComponent has 111 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getStatelessComponent(node) {
            const parent = node.parent;
            if (
              node.type === 'FunctionDeclaration'
              && (!node.id || isFirstLetterCapitalized(node.id.name))
      Severity: Major
      Found in lib/util/Components.js - About 4 hrs to fix

        Function getRelatedComponent has 81 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            getRelatedComponent(node) {
              let i;
              let j;
              let k;
              let l;
        Severity: Major
        Found in lib/util/Components.js - About 3 hrs to fix

          Function isReactHookCall has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              isReactHookCall(node, expectedHookNames) {
                if (node.type !== 'CallExpression') {
                  return false;
                }
          
          
          Severity: Major
          Found in lib/util/Components.js - About 2 hrs to fix

            Function list has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              list() {
                const thisList = Lists.get(this);
                const list = {};
                const usedPropTypes = {};
            
            
            Severity: Minor
            Found in lib/util/Components.js - About 1 hr to fix

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

              function usedPropTypesAreEquivalent(propA, propB) {
                if (propA.name === propB.name) {
                  if (!propA.allNames && !propB.allNames) {
                    return true;
                  }
              Severity: Minor
              Found in lib/util/Components.js - 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

              Avoid too many return statements within this function.
              Open

                    return null;
              Severity: Major
              Found in lib/util/Components.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                          return undefined;
                Severity: Major
                Found in lib/util/Components.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return node;
                  Severity: Major
                  Found in lib/util/Components.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return node;
                    Severity: Major
                    Found in lib/util/Components.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return undefined;
                      Severity: Major
                      Found in lib/util/Components.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return node;
                        Severity: Major
                        Found in lib/util/Components.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return null;
                          Severity: Major
                          Found in lib/util/Components.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return undefined;
                            Severity: Major
                            Found in lib/util/Components.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return node;
                              Severity: Major
                              Found in lib/util/Components.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return node;
                                Severity: Major
                                Found in lib/util/Components.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                            return undefined;
                                  Severity: Major
                                  Found in lib/util/Components.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                              return undefined;
                                    Severity: Major
                                    Found in lib/util/Components.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                return pragmaComponentWrapper;
                                      Severity: Major
                                      Found in lib/util/Components.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                  return undefined;
                                        Severity: Major
                                        Found in lib/util/Components.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                    return undefined;
                                          Severity: Major
                                          Found in lib/util/Components.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                      return undefined;
                                            Severity: Major
                                            Found in lib/util/Components.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                        return undefined;
                                              Severity: Major
                                              Found in lib/util/Components.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                              return node;
                                                Severity: Major
                                                Found in lib/util/Components.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                        return undefined;
                                                  Severity: Major
                                                  Found in lib/util/Components.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                              return undefined;
                                                    Severity: Major
                                                    Found in lib/util/Components.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                return undefined;
                                                      Severity: Major
                                                      Found in lib/util/Components.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                  return isFirstLetterCapitalized(node.id.name) ? node : undefined;
                                                        Severity: Major
                                                        Found in lib/util/Components.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                      return undefined;
                                                          Severity: Major
                                                          Found in lib/util/Components.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                          return node;
                                                            Severity: Major
                                                            Found in lib/util/Components.js - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                        return undefined;
                                                              Severity: Major
                                                              Found in lib/util/Components.js - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                        return node;
                                                                Severity: Major
                                                                Found in lib/util/Components.js - About 30 mins to fix

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                        return components.add(componentNode, 1);
                                                                  Severity: Major
                                                                  Found in lib/util/Components.js - About 30 mins to fix

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

                                                                            if (node.parent.type === 'ArrowFunctionExpression' && node.parent.parent.type === 'Property' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
                                                                              if (isFirstLetterCapitalized(node.parent.parent.key.name)) {
                                                                                return node;
                                                                              }
                                                                              return undefined;
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 2 hrs to fix
                                                                    lib/util/Components.js on lines 519..524

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

                                                                    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 (node.parent.type === 'ArrowFunctionExpression' && node.parent.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
                                                                              if (isFirstLetterCapitalized(node.parent.parent.left.name)) {
                                                                                return node;
                                                                              }
                                                                              return undefined;
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 2 hrs to fix
                                                                    lib/util/Components.js on lines 527..532

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

                                                                    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 (functionExpr.parent.type === 'Property' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
                                                                                if (isFirstLetterCapitalized(functionExpr.parent.key.name)) {
                                                                                  return node;
                                                                                }
                                                                                return undefined;
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 1 hr to fix
                                                                    lib/util/Components.js on lines 540..545

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

                                                                    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 (functionExpr.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
                                                                                if (isFirstLetterCapitalized(functionExpr.parent.left.name)) {
                                                                                  return node;
                                                                                }
                                                                                return undefined;
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 1 hr to fix
                                                                    lib/util/Components.js on lines 551..556

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

                                                                    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

                                                                      addDefaultReactImport(specifier) {
                                                                        const info = ReactImports.get(this);
                                                                        ReactImports.set(this, Object.assign({}, info, {
                                                                          defaultReactImports: (info.defaultReactImports || []).concat(specifier),
                                                                        }));
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 1 hr to fix
                                                                    lib/util/Components.js on lines 228..233

                                                                    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

                                                                      addNamedReactImport(specifier) {
                                                                        const info = ReactImports.get(this);
                                                                        ReactImports.set(this, Object.assign({}, info, {
                                                                          namedReactImports: (info.namedReactImports || []).concat(specifier),
                                                                        }));
                                                                    Severity: Major
                                                                    Found in lib/util/Components.js and 1 other location - About 1 hr to fix
                                                                    lib/util/Components.js on lines 215..220

                                                                    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

                                                                            } else if (
                                                                              refId.parent
                                                                              && refId.parent.type === 'VariableDeclarator'
                                                                              && refId.parent.init
                                                                              && refId.parent.init.type !== 'Identifier'
                                                                    Severity: Minor
                                                                    Found in lib/util/Components.js and 1 other location - About 55 mins to fix
                                                                    lib/util/isCreateContext.js on lines 9..16

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

                                                                    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 (node.property && node.property.type === 'Identifier') {
                                                                              componentPath.push(node.property.name);
                                                                            }
                                                                    Severity: Minor
                                                                    Found in lib/util/Components.js and 1 other location - About 35 mins to fix
                                                                    lib/util/Components.js on lines 648..650

                                                                    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 (node.object && node.object.type === 'Identifier') {
                                                                              componentPath.push(node.object.name);
                                                                            }
                                                                    Severity: Minor
                                                                    Found in lib/util/Components.js and 1 other location - About 35 mins to fix
                                                                    lib/util/Components.js on lines 645..647

                                                                    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

                                                                              val.node.type === 'ArrowFunctionExpression'
                                                                              && val.node.parent
                                                                              && val.node.parent.type === 'VariableDeclarator'
                                                                    Severity: Minor
                                                                    Found in lib/util/Components.js and 1 other location - About 30 mins to fix
                                                                    lib/util/defaultProps.js on lines 145..146

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

                                                                    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