yannickcr/eslint-plugin-react

View on GitHub
lib/rules/jsx-no-target-blank.js

Summary

Maintainability
F
5 days
Test Coverage

Function create has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
Open

  create(context) {
    const configuration = Object.assign(
      {
        allowReferrer: false,
        warnOnSpreadAttributes: false,
Severity: Minor
Found in lib/rules/jsx-no-target-blank.js - About 1 day 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 create has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  create(context) {
    const configuration = Object.assign(
      {
        allowReferrer: false,
        warnOnSpreadAttributes: false,
Severity: Major
Found in lib/rules/jsx-no-target-blank.js - About 3 hrs to fix

    Function JSXOpeningElement has 78 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          JSXOpeningElement(node) {
            const targetIndex = findLastIndex(node.attributes, (attr) => attr.name && attr.name.name === 'target');
            const spreadAttributeIndex = findLastIndex(node.attributes, (attr) => (attr.type === 'JSXSpreadAttribute'));
    
            if (linkComponents.has(node.name.name)) {
    Severity: Major
    Found in lib/rules/jsx-no-target-blank.js - About 3 hrs to fix

      Function getStringFromValue has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

      function getStringFromValue(value, targetValue) {
        if (value) {
          if (value.type === 'Literal') {
            return value.value;
          }
      Severity: Minor
      Found in lib/rules/jsx-no-target-blank.js - About 2 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Function attributeValuePossiblyBlank has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      function attributeValuePossiblyBlank(attribute) {
        if (!attribute || !attribute.value) {
          return false;
        }
        const value = attribute.value;
      Severity: Minor
      Found in lib/rules/jsx-no-target-blank.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 fix has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                    fix(fixer) {
                      // eslint 5 uses `node.attributes`; eslint 6+ uses `node.parent.attributes`
                      const nodeWithAttrs = node.parent.attributes ? node.parent : node;
                      // eslint 5 does not provide a `name` property on JSXSpreadElements
                      const relAttribute = nodeWithAttrs.attributes.find((attr) => attr.name && attr.name.name === 'rel');
      Severity: Minor
      Found in lib/rules/jsx-no-target-blank.js - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                            if (typeof relAttribute.value.expression.value === 'string') {
                              const parts = relAttribute.value.expression.value
                                .split('noreferrer')
                                .filter(Boolean);
                              return fixer.replaceText(relAttribute.value.expression, `"${parts.concat('noreferrer').join(' ')}"`);
        Severity: Major
        Found in lib/rules/jsx-no-target-blank.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (targetTestCond === relTestCond) {
                      const targetBlankIndex = [targetValue.expression.consequent.value, targetValue.expression.alternate.value].indexOf('_blank');
                      return relValues[targetBlankIndex];
                    }
          Severity: Major
          Found in lib/rules/jsx-no-target-blank.js - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

              return null;
            Severity: Major
            Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return expr.value;
              Severity: Major
              Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  return false;
                Severity: Major
                Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return null;
                  Severity: Major
                  Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                        return fixer.replaceText(relAttribute.value, '"noreferrer"');
                    Severity: Major
                    Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                            return fixer.replaceText(relAttribute.value.expression, `"${parts.concat('noreferrer').join(' ')}"`);
                      Severity: Major
                      Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return true;
                        Severity: Major
                        Found in lib/rules/jsx-no-target-blank.js - About 30 mins to fix

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

                                    if (!attributeValuePossiblyBlank(node.attributes[targetIndex])) {
                                      const hasSpread = spreadAttributeIndex >= 0;
                          
                                      if (warnOnSpreadAttributes && hasSpread) {
                                        // continue to check below
                          Severity: Major
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 1 hr to fix
                          lib/rules/jsx-no-target-blank.js on lines 252..264

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

                          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 (!attributeValuePossiblyBlank(node.attributes[targetIndex])) {
                                      const hasSpread = spreadAttributeIndex >= 0;
                          
                                      if (warnOnSpreadAttributes && hasSpread) {
                                        // continue to check below
                          Severity: Major
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 1 hr to fix
                          lib/rules/jsx-no-target-blank.js on lines 189..197

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

                          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 (expr.alternate.type === 'Literal' && expr.alternate.value && expr.alternate.value.toLowerCase() === '_blank') {
                                  return true;
                                }
                          Severity: Major
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 1 hr to fix
                          lib/rules/jsx-no-target-blank.js on lines 44..46

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

                          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 (expr.consequent.type === 'Literal' && expr.consequent.value && expr.consequent.value.toLowerCase() === '_blank') {
                                  return true;
                                }
                          Severity: Major
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 1 hr to fix
                          lib/rules/jsx-no-target-blank.js on lines 41..43

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

                          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 (value.type === 'Literal') {
                              return typeof value.value === 'string' && value.value.toLowerCase() === '_blank';
                            }
                          Severity: Minor
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 35 mins to fix
                          lib/rules/jsx-no-target-blank.js on lines 37..39

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

                          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 (expr.type === 'Literal') {
                                return typeof expr.value === 'string' && expr.value.toLowerCase() === '_blank';
                              }
                          Severity: Minor
                          Found in lib/rules/jsx-no-target-blank.js and 1 other location - About 35 mins to fix
                          lib/rules/jsx-no-target-blank.js on lines 32..34

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

                          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