kachkaev/humane-math

View on GitHub
src/core/analysis/3-semantic/validator.js

Summary

Maintainability
F
1 wk
Test Coverage

Function validateNode has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
Open

  validateNode(treeNode, symbols, rules) {
    var symbolId;
    var possibleMessageParams;

    switch (treeNode.type) {
Severity: Minor
Found in src/core/analysis/3-semantic/validator.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 validateNode has 202 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  validateNode(treeNode, symbols, rules) {
    var symbolId;
    var possibleMessageParams;

    switch (treeNode.type) {
Severity: Major
Found in src/core/analysis/3-semantic/validator.js - About 1 day to fix

    File validator.js has 283 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import _ from 'underscore';
    import {Message}      from '../message';
    import {MessageList}  from '../message-list';
    import {Pos}          from '../pos';
    import {TokenType}    from '../1-lexical/token-type';
    Severity: Minor
    Found in src/core/analysis/3-semantic/validator.js - About 2 hrs to fix

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

        validate(tree, symbols, rules, calculator) {
      
          this.errors.clear();
      
          // Check for emptiness
      Severity: Major
      Found in src/core/analysis/3-semantic/validator.js - About 2 hrs to fix

        Function validate has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          validate(tree, symbols, rules, calculator) {
        
            this.errors.clear();
        
            // Check for emptiness
        Severity: Minor
        Found in src/core/analysis/3-semantic/validator.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

        Avoid deeply nested control flow statements.
        Open

                    if (treeNode.subNodes[argumentCount - 1]) {
                      errorPos = Pos.unite(
                          Pos.ending(treeNode.subNodes[argumentCount - 1].pos),
                          Pos.ending(treeNode.argumentPos)
                      );
        Severity: Major
        Found in src/core/analysis/3-semantic/validator.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      } if (realArgumentCount > argumentCount.max) {
                        errorPos = Pos.unite(
                            Pos.ending(treeNode.subNodes[argumentCount.max - 1].pos),
                            Pos.ending(treeNode.argumentPos)
                          );
          Severity: Major
          Found in src/core/analysis/3-semantic/validator.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (realArgumentCount < argumentCount.min) {
                          errorPos = realArgumentCount
                              ? Pos.unite(
                                  Pos.ending(treeNode.subNodes[realArgumentCount - 1].pos),
                                  Pos.ending(treeNode.argumentPos)
            Severity: Major
            Found in src/core/analysis/3-semantic/validator.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        } else if (realArgumentCount < argumentCount) {
                          errorPos = realArgumentCount
                                ? Pos.unite(Pos.ending(
                                    treeNode.subNodes[realArgumentCount - 1].pos),
                                    Pos.ending(treeNode.argumentPos)
              Severity: Major
              Found in src/core/analysis/3-semantic/validator.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if (realArgumentCount < argumentCount.min) {
                              errorPos = realArgumentCount
                                  ? Pos.unite(
                                      Pos.ending(treeNode.subNodes[realArgumentCount - 1].pos),
                                      Pos.ending(treeNode.argumentPos)
                Severity: Major
                Found in src/core/analysis/3-semantic/validator.js - About 45 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return;
                  Severity: Major
                  Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return;
                    Severity: Major
                    Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return;
                      Severity: Major
                      Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return;
                        Severity: Major
                        Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                return;
                          Severity: Major
                          Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return;
                            Severity: Major
                            Found in src/core/analysis/3-semantic/validator.js - About 30 mins to fix

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

                                    if (symbolId) {
                              
                                      // Keep node sub-type and the id of the variable in the node.
                                      treeNode.id = symbolId;
                                      treeNode.subType = TreeNodeType.STANDARD_VARIABLE;
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 1 day to fix
                              src/core/analysis/3-semantic/validator.js on lines 143..160

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

                              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 (symbolId) {
                              
                                      // Keep node sub-type and the id of the constant in the node.
                                      treeNode.id = symbolId;
                                      treeNode.subType = TreeNodeType.STANDARD_CONSTANT;
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 1 day to fix
                              src/core/analysis/3-semantic/validator.js on lines 172..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 202.

                              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

                                          if (realArgumentCount < argumentCount.min) {
                                            errorPos = realArgumentCount
                                                ? Pos.unite(
                                                    Pos.ending(treeNode.subNodes[realArgumentCount - 1].pos),
                                                    Pos.ending(treeNode.argumentPos)
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 2 other locations - About 2 hrs to fix
                              src/core/analysis/3-semantic/validator.js on lines 275..287
                              src/core/analysis/3-semantic/validator.js on lines 294..306

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

                              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

                                        } else if (realArgumentCount < argumentCount) {
                                          errorPos = realArgumentCount
                                                ? Pos.unite(Pos.ending(
                                                    treeNode.subNodes[realArgumentCount - 1].pos),
                                                    Pos.ending(treeNode.argumentPos)
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 2 other locations - About 2 hrs to fix
                              src/core/analysis/3-semantic/validator.js on lines 294..306
                              src/core/analysis/3-semantic/validator.js on lines 310..322

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

                              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

                                          if (realArgumentCount < argumentCount.min) {
                                            errorPos = realArgumentCount
                                                ? Pos.unite(
                                                    Pos.ending(treeNode.subNodes[realArgumentCount - 1].pos),
                                                    Pos.ending(treeNode.argumentPos)
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 2 other locations - About 2 hrs to fix
                              src/core/analysis/3-semantic/validator.js on lines 275..287
                              src/core/analysis/3-semantic/validator.js on lines 310..322

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

                              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 (rules.valueOnlyGreaterThan.isYes()
                                        && isFinite(tree.root.value)
                                        && isFinite(rules.valueOnlyGreaterThan.bound)
                                        && tree.root.value <= rules.valueOnlyGreaterThan.bound) {
                                      this.errors.add(new Message(
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 1 hr to fix
                              src/core/analysis/3-semantic/validator.js on lines 99..107

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

                              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 (rules.valueOnlyLessThan.isYes()
                                        && isFinite(tree.root.value)
                                        && tree.root.value >= rules.valueOnlyLessThan.bound) {
                                      this.errors.add(new Message(
                                          'e_sem_expected_lt',
                              Severity: Major
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 1 hr to fix
                              src/core/analysis/3-semantic/validator.js on lines 87..96

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

                              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 (symbolId) {
                                      this.errors.add(new Message(
                                          'e_sem_variable_as_function',
                                          treeNode.namePos,
                                          {name: treeNode.nameRaw, id: symbolId}
                              Severity: Minor
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 50 mins to fix
                              src/core/analysis/3-semantic/validator.js on lines 194..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 51.

                              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 (symbolId) {
                                      this.errors.add(new Message('e_sem_function_as_symbol', treeNode.pos,{name: treeNode.nameRaw, id: symbolId}));
                                      return;
                                    }
                              Severity: Minor
                              Found in src/core/analysis/3-semantic/validator.js and 1 other location - About 50 mins to fix
                              src/core/analysis/3-semantic/validator.js on lines 354..361

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

                              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