yannickcr/eslint-plugin-react

View on GitHub
lib/util/propTypes.js

Summary

Maintainability
F
2 wks
Test Coverage

Function propTypesInstructions has a Cognitive Complexity of 304 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function propTypesInstructions(context, components, utils) {
  // Used to track the type annotations in scope.
  // Necessary because babel's scopes do not track type annotations.
  let stack = null;

Severity: Minor
Found in lib/util/propTypes.js - About 6 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 propTypesInstructions has 866 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function propTypesInstructions(context, components, utils) {
  // Used to track the type annotations in scope.
  // Necessary because babel's scopes do not track type annotations.
  let stack = null;

Severity: Major
Found in lib/util/propTypes.js - About 4 days to fix

    File propTypes.js has 921 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * @fileoverview Common propTypes detection functionality.
     */
    
    'use strict';
    Severity: Major
    Found in lib/util/propTypes.js - About 2 days to fix

      Function markPropTypesAsDeclared has 130 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function markPropTypesAsDeclared(node, propTypes) {
          let componentNode = node;
          while (componentNode && !components.get(componentNode)) {
            componentNode = componentNode.parent;
          }
      Severity: Major
      Found in lib/util/propTypes.js - About 5 hrs to fix

        Function buildReactDeclarationTypes has 95 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function buildReactDeclarationTypes(value, parentName) {
            if (
              value
              && value.callee
              && value.callee.object
        Severity: Major
        Found in lib/util/propTypes.js - About 3 hrs to fix

          Function convertReturnTypeToPropTypes has 77 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              convertReturnTypeToPropTypes(node) {
                // ReturnType<T> should always have one parameter
                const nodeTypeParams = node.typeParameters;
                if (nodeTypeParams) {
                  if (nodeTypeParams.params.length === 1) {
          Severity: Major
          Found in lib/util/propTypes.js - About 3 hrs to fix

            Function markAnnotatedFunctionArgumentsAsDeclared has 63 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              function markAnnotatedFunctionArgumentsAsDeclared(node) {
                if (!node.params || !node.params.length) {
                  return;
                }
            
            
            Severity: Major
            Found in lib/util/propTypes.js - About 2 hrs to fix

              Function searchDeclarationByName has 53 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  searchDeclarationByName(node) {
                    let typeName;
                    if (astUtil.isTSTypeReference(node)) {
                      typeName = node.typeName.name;
                      const leftMostName = getLeftMostTypeName(node.typeName);
              Severity: Major
              Found in lib/util/propTypes.js - About 2 hrs to fix

                Consider simplifying this complex logical expression.
                Open

                    if (
                      node.parent
                      && node.parent.callee
                      && node.parent.typeParameters
                      && node.parent.typeParameters.params
                Severity: Critical
                Found in lib/util/propTypes.js - About 1 hr to fix

                  Function ObjectTypeAnnotation has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      ObjectTypeAnnotation(annotation, parentName, seen) {
                        let containsUnresolvedObjectTypeSpread = false;
                        let containsSpread = false;
                        const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);
                        const shapeTypeDefinition = {
                  Severity: Minor
                  Found in lib/util/propTypes.js - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                        if (
                          value
                          && value.type === 'CallExpression'
                          && value.callee
                          && value.callee.property
                    Severity: Major
                    Found in lib/util/propTypes.js - About 1 hr to fix

                      Avoid deeply nested control flow statements.
                      Open

                                    if (returnTypeFunction.length === 0) {
                                      // Cannot find identifier in current scope. It might be an exported type.
                                      this.shouldIgnorePropTypes = true;
                                      return;
                                    }
                      Severity: Major
                      Found in lib/util/propTypes.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                        if (isFunctionType(func)) {
                                          let res = func.body;
                                          if (res.type === 'BlockStatement') {
                                            res = astUtil.findReturnStatement(func);
                                            if (res) {
                        Severity: Major
                        Found in lib/util/propTypes.js - About 45 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                      if (((n.type === 'AssignmentExpression') && propsUtil.isPropTypesDeclaration(n.left))
                                        || ((n.type === 'ClassProperty' || n.type === 'PropertyDefinition' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n))) {
                                        // Found a propType used inside of another propType. This is not considered usage, we'll still validate
                                        // this component.
                                        isUsedInPropTypes = true;
                          Severity: Major
                          Found in lib/util/propTypes.js - About 40 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return {};
                            Severity: Major
                            Found in lib/util/propTypes.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

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

                                Avoid too many return statements within this function.
                                Open

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

                                  Avoid too many return statements within this function.
                                  Open

                                        if (!isValidReactGenericTypeAnnotation(annotation)) return;
                                  Severity: Major
                                  Found in lib/util/propTypes.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

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

                                      Avoid too many return statements within this function.
                                      Open

                                              return declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
                                      Severity: Major
                                      Found in lib/util/propTypes.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              return declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
                                        Severity: Major
                                        Found in lib/util/propTypes.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                              return {};
                                          Severity: Major
                                          Found in lib/util/propTypes.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                        return {};
                                            Severity: Major
                                            Found in lib/util/propTypes.js - About 30 mins to fix

                                              Function isSuperTypeParameterPropsDeclaration has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function isSuperTypeParameterPropsDeclaration(node) {
                                                if (node && (node.type === 'ClassDeclaration' || node.type === 'ClassExpression')) {
                                                  if (node.superTypeParameters && node.superTypeParameters.params.length > 0) {
                                                    return true;
                                                  }
                                              Severity: Minor
                                              Found in lib/util/propTypes.js - About 25 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

                                              Function iterateProperties has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function iterateProperties(context, properties, fn, handleSpreadFn) {
                                                if (properties && properties.length && typeof fn === 'function') {
                                                  for (let i = 0, j = properties.length; i < j; i++) {
                                                    const node = properties[i];
                                                    const key = astUtil.getKeyValue(context, node);
                                              Severity: Minor
                                              Found in lib/util/propTypes.js - About 25 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

                                              There are no issues that match your filters.

                                              Category
                                              Status