yannickcr/eslint-plugin-react

View on GitHub
lib/rules/hook-use-state.js

Summary

Maintainability
D
2 days
Test Coverage

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

  create: Components.detect((context, components, util) => {
    const configuration = context.options[0] || {};
    const allowDestructuredState = configuration.allowDestructuredState || false;

    return {
Severity: Minor
Found in lib/rules/hook-use-state.js - About 7 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 create has 128 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  create: Components.detect((context, components, util) => {
    const configuration = context.options[0] || {};
    const allowDestructuredState = configuration.allowDestructuredState || false;

    return {
Severity: Major
Found in lib/rules/hook-use-state.js - About 5 hrs to fix

    Function CallExpression has 122 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          CallExpression(node) {
            const isImmediateReturn = node.parent
              && node.parent.type === 'ReturnStatement';
    
            if (isImmediateReturn || !util.isReactHookCall(node, ['useState'])) {
    Severity: Major
    Found in lib/rules/hook-use-state.js - About 4 hrs to fix

      Consider simplifying this complex logical expression.
      Open

                if (isSingleGetter && isUseStateCalledWithSingleArgument) {
                  const useMemoReactImportSpecifier = namedReactImports
                    && namedReactImports.find((specifier) => specifier.imported.name === 'useMemo');
      
                  let useMemoCode;
      Severity: Major
      Found in lib/rules/hook-use-state.js - About 40 mins to fix

        There are no issues that match your filters.

        Category
        Status