Gapminder/vizabi

View on GitHub
src/base/component.js

Summary

Maintainability
D
3 days
Test Coverage

File component.js has 382 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as utils from "base/utils";
import Events from "base/events";
import Model from "base/model";
import globals from "base/globals";

Severity: Minor
Found in src/base/component.js - About 5 hrs to fix

    Component has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    const Component = Events.extend({
    
      /**
       * Initializes the component
       * @param {Object} config Initial config, with name and placeholder
    Severity: Minor
    Found in src/base/component.js - About 3 hrs to fix

      Function _modelMapping has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _modelMapping(model_config) {
          const _this = this;
          const values = {};
          //If model_config is an array, we map it
          if (utils.isArray(model_config) && utils.isArray(this.model_expects)) {
      Severity: Major
      Found in src/base/component.js - About 2 hrs to fix

        Function loadTemplate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          loadTemplate() {
            const tmpl = this.template;
            let data = this.template_data;
            const _this = this;
            let rendered = "";
        Severity: Minor
        Found in src/base/component.js - About 1 hr to fix

          Function renderError has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            renderError(error) {
              if (!error) return utils.warn("renderError() was called without any specific error. Not rendering anything then.");
              if (utils.hasClass(this.placeholder, class_error)) return utils.warn("The app is already showing error dialog. Not rendering again.");
          
              utils.removeClass(this.placeholder, class_loading_first);
          Severity: Minor
          Found in src/base/component.js - About 1 hr to fix

            Function renderError has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              renderError(error) {
                if (!error) return utils.warn("renderError() was called without any specific error. Not rendering anything then.");
                if (utils.hasClass(this.placeholder, class_error)) return utils.warn("The app is already showing error dialog. Not rendering again.");
            
                utils.removeClass(this.placeholder, class_loading_first);
            Severity: Minor
            Found in src/base/component.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 _modelMapping has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              _modelMapping(model_config) {
                const _this = this;
                const values = {};
                //If model_config is an array, we map it
                if (utils.isArray(model_config) && utils.isArray(this.model_expects)) {
            Severity: Minor
            Found in src/base/component.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 init has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              init(config, parent) {
                this._id = this._id || utils.uniqueId("c");
                this._ready = false;
                this._readyOnce = false;
                this.name = this.name || config.name || this._id;
            Severity: Minor
            Found in src/base/component.js - About 1 hr to fix

              Function init has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                init(config, parent) {
                  this._id = this._id || utils.uniqueId("c");
                  this._ready = false;
                  this._readyOnce = false;
                  this.name = this.name || config.name || this._id;
              Severity: Minor
              Found in src/base/component.js - About 45 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

              Function templateFunc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function templateFunc(str, data) {
              
                const func = function(obj) {
                  return str.replace(/<%=([^%]*)%>/g, match => {
                    //match t("...")
              Severity: Minor
              Found in src/base/component.js - About 45 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

                          utils.warn("Please, configure the 'model_expects' attribute accordingly in '" + _this.name + "' or check the models passed in '" + _this.parent.name + "'.\n\n" +
                            "Component: '" + _this.parent.name + "'\n" +
                            "Subcomponent: '" + _this.name + "'\n" +
                            "Expected Model: '" + _this.model_expects[i].type + "'\n" +
              Severity: Major
              Found in src/base/component.js and 1 other location - About 1 hr to fix
              src/base/component.js on lines 405..408

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

              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

                        utils.warn("Please, configure the 'model_expects' attribute accordingly in '" + _this.name + "' or check the models passed in '" + _this.parent.name + "'.\n\n" +
                          "Component: '" + _this.parent.name + "'\n" +
                          "Subcomponent: '" + _this.name + "'\n" +
                          "Number of Models Expected: " + _this.model_expects.length + "\n" +
              Severity: Major
              Found in src/base/component.js and 1 other location - About 1 hr to fix
              src/base/component.js on lines 394..397

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

              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

                getPresentationMode() {
                  // get profile from parent if layout is not available
                  return this.model.ui ?
                    this.model.ui.getPresentationMode() :
                    this.parent.getPresentationMode();
              Severity: Major
              Found in src/base/component.js and 1 other location - About 1 hr to fix
              src/base/component.js on lines 322..327

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

                getLayoutProfile() {
                  // get profile from parent if layout is not available
                  return this.model.ui ?
                    this.model.ui.currentProfile() :
                    this.parent.getLayoutProfile();
              Severity: Major
              Found in src/base/component.js and 1 other location - About 1 hr to fix
              src/base/component.js on lines 333..338

              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