CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/builder/components/code-mirror/code-mirror-view.js

Summary

Maintainability
D
1 day
Test Coverage

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

module.exports = CoreView.extend({
  module: 'components:code-mirror:code-mirror-view',

  className: 'Editor-content',

    File code-mirror-view.js has 297 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var CoreView = require('backbone/core-view');
    var _ = require('underscore');
    var CodeMirror = require('codemirror');
    var ColorPicker = require('./colorpicker.code-mirror');
    var template = require('./code-mirror.tpl');

      Function _initViews has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _initViews: function () {
          var options = _.defaults(_.extend({}, this.model.toJSON()), this.options);
      
          var isReadOnly = options.readonly;
          var hasLineNumbers = options.lineNumbers;

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

          _onKeyUpEditor: function (cm, event) {
            var code = event.keyCode;
            var hints = this._hints;
            var autocompleteChars = this._autocompleteChars - 1;
            var autocompletePrefix = this._autocompletePrefix;

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

            initialize: function (opts) {
              if (!opts) throw new Error('options for codemirror are required.');
              if (!opts.model) throw new Error('Model for codemirror is required.');
              if (opts.model.get('content') === void 0 &&
                  opts.placeholder === void 0) throw new Error('Content property or placeholder for codemirror is required.');

          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 _onKeyUpEditor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            _onKeyUpEditor: function (cm, event) {
              var code = event.keyCode;
              var hints = this._hints;
              var autocompleteChars = this._autocompleteChars - 1;
              var autocompletePrefix = this._autocompletePrefix;

          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

              this.$el.html(
                template({
                  content: this.model.get('content'),
                  tips: this._tips.join(' '),
                  warnings: this._warnings
          lib/assets/javascripts/builder/components/input-color/input-qualitative-ramps/categories-list/list-view/input-categories-list-view.js on lines 29..33

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

          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

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

                  if (autocompletePrefix &&
                      cm.getRange(CodeMirror.Pos(cur.line, cur.ch - autocompletePrefix.length), cur) !== autocompletePrefix) {
                    opts = { autocompletePrefix: autocompletePrefix };
                  }
          lib/assets/javascripts/builder/components/code-mirror/code-mirror-view.js on lines 130..133

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

          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

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

              if (autocompletePrefix &&
                  cm.getRange(CodeMirror.Pos(cur.line, cur.ch - autocompletePrefix.length), cur) !== autocompletePrefix) {
                opts = { autocompletePrefix: autocompletePrefix };
              }
          lib/assets/javascripts/builder/components/code-mirror/code-mirror-view.js on lines 159..162

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

          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

              this.model.on('change:content', function () {
                this.setContent(this.model.get('content'));
              }, this);
          lib/assets/javascripts/builder/components/code-mirror/code-mirror-view.js on lines 250..252

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

          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

              this.model.on('undo redo', function () {
                this.setContent(this.model.get('content'));
              }, this);
          lib/assets/javascripts/builder/components/code-mirror/code-mirror-view.js on lines 240..242

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

          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