tomchentw/react-prop-types-element-of-type

View on GitHub

Showing 16 of 16 total issues

Function describePropTypesElementOfType has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

describe(`propTypesElementOfType`, function describePropTypesElementOfType() {
  let domEl;
  let ChildComponent;
  let WrapperComponent;
  let consoleErrorSpy;
Severity: Major
Found in src/__tests__/index.spec.js - About 2 hrs to fix

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

      it(`should not warn for valid element`, function it() {
        render(<WrapperComponent childElement={<ChildComponent />} />, domEl);
    
        expect(consoleErrorSpy.calls.length).toBe(0);
      });
    Severity: Major
    Found in src/__tests__/index.spec.js and 1 other location - About 1 hr to fix
    src/__tests__/index.spec.js on lines 62..66

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

    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

      it(`should warn for invalid element`, function it() {
        render(<WrapperComponent childElement={<div />} />, domEl);
    
        expect(consoleErrorSpy.calls.length).toBe(1);
      });
    Severity: Major
    Found in src/__tests__/index.spec.js and 1 other location - About 1 hr to fix
    src/__tests__/index.spec.js on lines 74..78

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

    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

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

    export default function createComponentTypeChecker(expectedComponent) {
      function validate(isRequired, props, propName, componentName, location, propFullName = propName) {
        const locationName = ReactPropTypeLocationNames[location];
        if (props[propName] === null || props[propName] === undefined) {
          if (isRequired) {
    Severity: Minor
    Found in src/index.js - About 1 hr to fix

      Function createComponentTypeChecker has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function createComponentTypeChecker(expectedComponent) {
        function validate(isRequired, props, propName, componentName, location, propFullName = propName) {
          const locationName = ReactPropTypeLocationNames[location];
          if (props[propName] === null || props[propName] === undefined) {
            if (isRequired) {
      Severity: Minor
      Found in src/index.js - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function validate has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        function validate(isRequired, props, propName, componentName, location, propFullName = propName) {
      Severity: Minor
      Found in src/index.js - About 45 mins to fix

        Use default import syntax to import 'React'.
        Open

          default as React,
        Severity: Minor
        Found in src/__tests__/index.spec.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Do not access Object.prototype method 'isPrototypeOf' from target object.
        Open

          if (expectedComponent.prototype.isPrototypeOf(actualComponent.prototype)) {
        Severity: Minor
        Found in src/index.js by eslint

        Disallow use of Object.prototypes builtins directly (no-prototype-builtins)

        In ECMAScript 5.1, Object.create was added, which enables the creation of objects with a specified [[Prototype]]. Object.create(null) is a common pattern used to create objects that will be used as a Map. This can lead to errors when it is assumed that objects will have properties from Object.prototype. This rule prevents calling Object.prototype methods directly from an object.

        Rule Details

        This rule disallows calling some Object.prototype methods directly on object instances.

        Examples of incorrect code for this rule:

        /*eslint no-prototype-builtins: "error"*/
        
        var hasBarProperty = foo.hasOwnProperty("bar");
        
        var isPrototypeOfBar = foo.isPrototypeOf(bar);
        
        var barIsEnumerable = foo.propertyIsEnumerable("bar");

        Examples of correct code for this rule:

        /*eslint no-prototype-builtins: "error"*/
        
        var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
        
        var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
        
        var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");

        When Not To Use It

        You may want to turn this rule off if you will never use an object that shadows an Object.prototype method or which does not inherit from Object.prototype. Source: http://eslint.org/docs/rules/

        Use default import syntax to import 'propTypesElementOfType'.
        Open

          default as propTypesElementOfType,
        Severity: Minor
        Found in src/__tests__/index.spec.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Use default import syntax to import 'ReactElement'.
        Open

          default as ReactElement,
        Severity: Minor
        Found in src/index.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Use default import syntax to import 'ReactPropTypeLocationNames'.
        Open

          default as ReactPropTypeLocationNames,
        Severity: Minor
        Found in src/index.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Use default import syntax to import 'ReactPropTypeLocations'.
        Open

          default as ReactPropTypeLocations,
        Severity: Minor
        Found in src/__tests__/index.spec.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Unexpected mix of '&&' and '||'.
        Open

          return componentClass && componentClass.name || ANONYMOUS;
        Severity: Minor
        Found in src/index.js by eslint

        Disallow mixes of different operators (no-mixed-operators)

        Enclosing complex expressions by parentheses clarifies the developer's intention, which makes the code more readable. This rule warns when different operators are used consecutively without parentheses in an expression.

        var foo = a && b || c || d;    /*BAD: Unexpected mix of '&&' and '||'.*/
        var foo = (a && b) || c || d;  /*GOOD*/
        var foo = a && (b || c || d);  /*GOOD*/

        Rule Details

        This rule checks BinaryExpression and LogicalExpression.

        This rule may conflict with [no-extra-parens](no-extra-parens.md) rule. If you use both this and [no-extra-parens](no-extra-parens.md) rule together, you need to use the nestedBinaryExpressions option of [no-extra-parens](no-extra-parens.md) rule.

        Examples of incorrect code for this rule:

        /*eslint no-mixed-operators: "error"*/
        
        var foo = a && b < 0 || c > 0 || d + 1 === 0;
        var foo = a + b * c;

        Examples of correct code for this rule:

        /*eslint no-mixed-operators: "error"*/
        
        var foo = a || b || c;
        var foo = a && b && c;
        var foo = (a && b < 0) || c > 0 || d + 1 === 0;
        var foo = a && (b < 0 || c > 0 || d + 1 === 0);
        var foo = a + (b * c);
        var foo = (a + b) * c;

        Options

        {
            "no-mixed-operators": [
                "error",
                {
                    "groups": [
                        ["+", "-", "*", "/", "%", "**"],
                        ["&", "|", "^", "~", "<>", ">>>"],
                        ["==", "!=", "===", "!==", ">", ">=", "

        This rule has 2 options.

        • groups (string[][]) - specifies groups to compare operators. When this rule compares two operators, if both operators are included in a same group, this rule checks it. Otherwise, this rule ignores it. This value is a list of groups. The group is a list of binary operators. Default is the groups for each kind of operators.
        • allowSamePrecedence (boolean) - specifies to allow mix of 2 operators if those have the same precedence. Default is true.

        groups

        The following operators can be used in groups option:

        • Arithmetic Operators: "+", "-", "*", "/", "%", "**"
        • Bitwise Operators: "&", "|", "^", "~", "<<", ">>", ">>>"
        • Comparison Operators: "==", "!=", "===", "!==", ">", ">=", "<", "<="
        • Logical Operators: "&&", "||"
        • Relational Operators: "in", "instanceof"

        Now, considers about {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} configure. This configure has 2 groups: bitwise operators and logical operators. This rule checks only if both operators are included in a same group. So, in this case, this rule comes to check between bitwise operators and between logical operators. This rule ignores other operators.

        Examples of incorrect code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

        /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<>", ">>>"], ["&&", "||"]]}]*/
        
        var foo = a && b < 0 || c > 0 || d + 1 === 0;
        var foo = a & b | c;

        Examples of correct code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

        /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<>", ">>>"], ["&&", "||"]]}]*/
        
        var foo = a || b > 0 || c + 1 === 0;
        var foo = a && b > 0 && c + 1 === 0;
        var foo = (a && b < 0) || c > 0 || d + 1 === 0;
        var foo = a && (b < 0 ||  c > 0 || d + 1 === 0);
        var foo = (a & b) | c;
        var foo = a & (b | c);
        var foo = a + b * c;
        var foo = a + (b * c);
        var foo = (a + b) * c;

        allowSamePrecedence

        Examples of correct code for this rule with {"allowSamePrecedence": true} option:

        /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": true}]*/
        
        // + and - have the same precedence.
        var foo = a + b - c;

        Examples of incorrect code for this rule with {"allowSamePrecedence": false} option:

        /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": false}]*/
        
        // + and - have the same precedence.
        var foo = a + b - c;

        When Not To Use It

        If you don't want to be notified about mixed operators, then it's safe to disable this rule.

        Related Rules

        Unexpected mix of '&&' and '||'.
        Open

          return componentClass && componentClass.name || ANONYMOUS;
        Severity: Minor
        Found in src/index.js by eslint

        Disallow mixes of different operators (no-mixed-operators)

        Enclosing complex expressions by parentheses clarifies the developer's intention, which makes the code more readable. This rule warns when different operators are used consecutively without parentheses in an expression.

        var foo = a && b || c || d;    /*BAD: Unexpected mix of '&&' and '||'.*/
        var foo = (a && b) || c || d;  /*GOOD*/
        var foo = a && (b || c || d);  /*GOOD*/

        Rule Details

        This rule checks BinaryExpression and LogicalExpression.

        This rule may conflict with [no-extra-parens](no-extra-parens.md) rule. If you use both this and [no-extra-parens](no-extra-parens.md) rule together, you need to use the nestedBinaryExpressions option of [no-extra-parens](no-extra-parens.md) rule.

        Examples of incorrect code for this rule:

        /*eslint no-mixed-operators: "error"*/
        
        var foo = a && b < 0 || c > 0 || d + 1 === 0;
        var foo = a + b * c;

        Examples of correct code for this rule:

        /*eslint no-mixed-operators: "error"*/
        
        var foo = a || b || c;
        var foo = a && b && c;
        var foo = (a && b < 0) || c > 0 || d + 1 === 0;
        var foo = a && (b < 0 || c > 0 || d + 1 === 0);
        var foo = a + (b * c);
        var foo = (a + b) * c;

        Options

        {
            "no-mixed-operators": [
                "error",
                {
                    "groups": [
                        ["+", "-", "*", "/", "%", "**"],
                        ["&", "|", "^", "~", "<>", ">>>"],
                        ["==", "!=", "===", "!==", ">", ">=", "

        This rule has 2 options.

        • groups (string[][]) - specifies groups to compare operators. When this rule compares two operators, if both operators are included in a same group, this rule checks it. Otherwise, this rule ignores it. This value is a list of groups. The group is a list of binary operators. Default is the groups for each kind of operators.
        • allowSamePrecedence (boolean) - specifies to allow mix of 2 operators if those have the same precedence. Default is true.

        groups

        The following operators can be used in groups option:

        • Arithmetic Operators: "+", "-", "*", "/", "%", "**"
        • Bitwise Operators: "&", "|", "^", "~", "<<", ">>", ">>>"
        • Comparison Operators: "==", "!=", "===", "!==", ">", ">=", "<", "<="
        • Logical Operators: "&&", "||"
        • Relational Operators: "in", "instanceof"

        Now, considers about {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} configure. This configure has 2 groups: bitwise operators and logical operators. This rule checks only if both operators are included in a same group. So, in this case, this rule comes to check between bitwise operators and between logical operators. This rule ignores other operators.

        Examples of incorrect code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

        /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<>", ">>>"], ["&&", "||"]]}]*/
        
        var foo = a && b < 0 || c > 0 || d + 1 === 0;
        var foo = a & b | c;

        Examples of correct code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

        /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<>", ">>>"], ["&&", "||"]]}]*/
        
        var foo = a || b > 0 || c + 1 === 0;
        var foo = a && b > 0 && c + 1 === 0;
        var foo = (a && b < 0) || c > 0 || d + 1 === 0;
        var foo = a && (b < 0 ||  c > 0 || d + 1 === 0);
        var foo = (a & b) | c;
        var foo = a & (b | c);
        var foo = a + b * c;
        var foo = a + (b * c);
        var foo = (a + b) * c;

        allowSamePrecedence

        Examples of correct code for this rule with {"allowSamePrecedence": true} option:

        /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": true}]*/
        
        // + and - have the same precedence.
        var foo = a + b - c;

        Examples of incorrect code for this rule with {"allowSamePrecedence": false} option:

        /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": false}]*/
        
        // + and - have the same precedence.
        var foo = a + b - c;

        When Not To Use It

        If you don't want to be notified about mixed operators, then it's safe to disable this rule.

        Related Rules

        Use default import syntax to import 'expect'.
        Open

          default as expect,
        Severity: Minor
        Found in src/__tests__/index.spec.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        JSX not allowed in files with extension '.js'
        Open

                return <div>Child</div>;
        Severity: Minor
        Found in src/__tests__/index.spec.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        Severity
        Category
        Status
        Source
        Language