ruslansagitov/loud

View on GitHub
lib/a11y-node.js

Summary

Maintainability
F
5 days
Test Coverage
A
100%

File a11y-node.js has 822 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2024 Ruslan Sagitov
 *
Severity: Major
Found in lib/a11y-node.js - About 1 day to fix

    A11yNode has 37 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class A11yNode {
        constructor(node) {
            this.node = node;
    
            this.childs = [];
    Severity: Minor
    Found in lib/a11y-node.js - About 4 hrs to fix

      Function isDescendantsValid has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          isDescendantsValid(limits) {
              let node = this.firstChild,
                  nodeCount = 0,
                  role, lim;
              for (; node; node = node.nextSibling) {
      Severity: Minor
      Found in lib/a11y-node.js - About 4 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 ownedByValidRolesFor has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          ownedByValidRolesFor(role) {
              let context = ROLE_CONTEXT[role];
              if (!context) {
                  return true;
              }
      Severity: Minor
      Found in lib/a11y-node.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 isHidden has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          isHidden(inst) {
              let node = this.node;
      
              if (this.nodeType !== 1) {
                  return false;
      Severity: Minor
      Found in lib/a11y-node.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 isNodeNonEmpty has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          isNodeNonEmpty(node) {
              node = node.firstChild;
              for (; node; node = node.nextSibling) {
                  if (node.nodeType === 1) {
                      if (node.hidden) {
      Severity: Minor
      Found in lib/a11y-node.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 getTextContentFromDirectChild has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          getTextContentFromDirectChild(childName) {
              let node = this.firstChild,
                  iter;
              for (; node; node = node.nextSibling) {
                  if (node.nodeType !== 1) {
      Severity: Minor
      Found in lib/a11y-node.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 isHidden has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          isHidden(inst) {
              let node = this.node;
      
              if (this.nodeType !== 1) {
                  return false;
      Severity: Minor
      Found in lib/a11y-node.js - About 1 hr to fix

        Function isDescendantsValid has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            isDescendantsValid(limits) {
                let node = this.firstChild,
                    nodeCount = 0,
                    role, lim;
                for (; node; node = node.nextSibling) {
        Severity: Minor
        Found in lib/a11y-node.js - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                  if (!node.isDescendantsValid(lim)) {
                                      return false;
                                  }
          Severity: Major
          Found in lib/a11y-node.js - About 45 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    if (this.hasAttribute('hidden') ||
                        this.getAttribute('aria-hidden') === 'true' ||
                        this.tag === 'input' &&
                        this.getAttribute('type') === 'hidden' ||
                        node.style.visibility === 'hidden' ||
            Severity: Major
            Found in lib/a11y-node.js - About 40 mins to fix

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

                  isInputInsideLabel() {
                      let id = this.getAttribute('id');
                      if (id && this.tag === 'input') {
                          let node = this.parentNode;
                          for (; node; node = node.parentNode) {
              Severity: Minor
              Found in lib/a11y-node.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 true;
              Severity: Major
              Found in lib/a11y-node.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

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

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

                          if (this.tag === 'input') {
                              let type = this.getAttribute('type') || 'text';
                              type = type.toLowerCase();
                              return INPUT_TYPE_NO_ROLE.has(type);
                          }
                  Severity: Minor
                  Found in lib/a11y-node.js and 1 other location - About 35 mins to fix
                  lib/a11y-node.js on lines 561..565

                  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

                      /* istanbul ignore next: untestable */ isHyperlink() {
                          let rel = this.getAttribute('rel') || '';
                          rel = rel.toLowerCase();
                          return HYPERLINK_TYPES.has(rel);
                      }
                  Severity: Minor
                  Found in lib/a11y-node.js and 1 other location - About 35 mins to fix
                  lib/a11y-node.js on lines 615..619

                  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 3 locations. Consider refactoring.
                  Open

                      a: {
                          link: 1,
                          button: 1,
                          checkbox: 1,
                          menuitem: 1,
                  Severity: Minor
                  Found in lib/a11y-node.js and 2 other locations - About 35 mins to fix
                  lib/a11y-node.js on lines 179..188
                  lib/a11y-node.js on lines 194..203

                  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 3 locations. Consider refactoring.
                  Open

                      ol: {
                          directory: 1,
                          list: 1,
                          listbox: 1,
                          menu: 1,
                  Severity: Minor
                  Found in lib/a11y-node.js and 2 other locations - About 35 mins to fix
                  lib/a11y-node.js on lines 101..110
                  lib/a11y-node.js on lines 179..188

                  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 3 locations. Consider refactoring.
                  Open

                      menu: {
                          directory: 1,
                          list: 1,
                          listbox: 1,
                          menu: 1,
                  Severity: Minor
                  Found in lib/a11y-node.js and 2 other locations - About 35 mins to fix
                  lib/a11y-node.js on lines 101..110
                  lib/a11y-node.js on lines 194..203

                  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

                  There are no issues that match your filters.

                  Category
                  Status