BabylonJS/Spector.js

View on GitHub
src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts

Summary

Maintainability
F
4 days
Test Coverage

Function _adaptComments has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    private _adaptComments(str: string): string {
        let singleLineComment = false;
        let multiLineComment = false;

        for (let index = 0; index < str.length; index++) {
Severity: Minor
Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - 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

File sourceCodeComponent.ts has 289 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import preprocess from "@shaderfrog/glsl-parser/preprocessor"; // tslint:disable-line:no-submodule-imports
import { BaseComponent, IStateEvent } from "../../mvx/baseComponent";
import { ISourceCodeChangeEvent } from "../resultView";
import { Logger } from "../../../shared/utils/logger";

Severity: Minor
Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 2 hrs to fix

    Function render has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        public render(state: ISourceCodeState, stateId: number): Element {
            const source = state.fragment ? state.sourceFragment : state.sourceVertex;
            let originalShader: string;
            let preprocessed = state.preprocessed;
    
    
    Severity: Minor
    Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - 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 render has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public render(state: ISourceCodeState, stateId: number): Element {
            const source = state.fragment ? state.sourceFragment : state.sourceVertex;
            let originalShader: string;
            let preprocessed = state.preprocessed;
    
    
    Severity: Major
    Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 2 hrs to fix

      Function _beautify has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          private _beautify(glsl: string, level: number = 0): string {
              let spaces = "";
              for (let i = 0; i < level; i++) {
                  spaces += "    "; // 4 spaces
              }
      Severity: Minor
      Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - 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 _beautify has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private _beautify(glsl: string, level: number = 0): string {
              let spaces = "";
              for (let i = 0; i < level; i++) {
                  spaces += "    "; // 4 spaces
              }
      Severity: Minor
      Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 1 hr to fix

        Function _adaptComments has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private _adaptComments(str: string): string {
                let singleLineComment = false;
                let multiLineComment = false;
        
                for (let index = 0; index < str.length; index++) {
        Severity: Minor
        Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 1 hr to fix

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

              private _getBracket(str: string, searchFrom = -1): { firstIteration: number, lastIteration: number } {
                  const fb = str.indexOf("{", searchFrom);
                  const arr = str.substr(fb + 1).split("");
                  let counter = 1;
                  let currentPosInString = fb;
          Severity: Minor
          Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - 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 _indentIfdef has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              private _indentIfdef(str: string): string {
                  let level = 0;
          
                  const arr2 = str.split("\n");
          
          
          Severity: Minor
          Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - 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

          Avoid deeply nested control flow statements.
          Open

                      else if (char === "}") {
                          if (singleLineComment || multiLineComment) {
                              str = str.substr(0, index) + SourceCodeComponent.closeCurlyReplacementKey + str.substr(index + 1);
                          }
                      }
          Severity: Major
          Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (!multiLineComment) {
                                    singleLineComment = true;
                                    index++;
                                }
            Severity: Major
            Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              if (singleLineComment || multiLineComment) {
                                  str = str.substr(0, index) + SourceCodeComponent.openCurlyReplacementKey + str.substr(index + 1);
                              }
              Severity: Major
              Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 45 mins to fix

                Function showError has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public showError(errorMessage: string) {
                        if (!this.editor) {
                            return;
                        }
                
                
                Severity: Minor
                Found in src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts - About 25 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

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

                    constructor() {
                        super();
                        this.onTranslatedVertexSourceClicked = this.createEvent("onTranslatedVertexSourceClicked");
                        this.onTranslatedFragmentSourceClicked = this.createEvent("onTranslatedFragmentSourceClicked");
                        this.onVertexSourceClicked = this.createEvent("onVertexSourceClicked");
                src/embeddedFrontend/resultView/menu/resultViewMenuComponent.ts on lines 27..37

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

                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 (char === ";") {
                                if (singleLineComment || multiLineComment) {
                                    str = str.substr(0, index) + SourceCodeComponent.semicolonReplacementKey + str.substr(index + 1);
                                }
                            }
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 276..285
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 281..285

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

                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 (char === "}") {
                                if (singleLineComment || multiLineComment) {
                                    str = str.substr(0, index) + SourceCodeComponent.closeCurlyReplacementKey + str.substr(index + 1);
                                }
                            }
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 271..285
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 276..285

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

                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 (char === "{") {
                                if (singleLineComment || multiLineComment) {
                                    str = str.substr(0, index) + SourceCodeComponent.openCurlyReplacementKey + str.substr(index + 1);
                                }
                            }
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 271..285
                src/embeddedFrontend/resultView/sourceCode/sourceCodeComponent.ts on lines 281..285

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

                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