CartoDB/cartodb20

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

Summary

Maintainability
F
2 wks
Test Coverage

Function exports has a Cognitive Complexity of 241 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function (CodeMirror) {
  CodeMirror.defineMode('cartocss', function (config) {
    var indentUnit = config.indentUnit;
    var type;

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 exports has 271 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function (CodeMirror) {
  CodeMirror.defineMode('cartocss', function (config) {
    var indentUnit = config.indentUnit;
    var type;

    Function tokenBase has 163 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function tokenBase (stream, state) {
          var ch = stream.next();
    
          if (ch === '@') {
            stream.eatWhile(/[\w\-]/);

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

      var COLOR_KEYWORDS = require('builder/helpers/color-keywords');
      
      /*
        LESS mode - http://www.lesscss.org/
        Ported to CodeMirror by Peter Kroon <plakroon@gmail.com>

        Avoid deeply nested control flow statements.
        Open

                if (type === '(' || type === 'string') {
                  return ret('string', 'string'); // allow url(../image.png)
                }

          Avoid deeply nested control flow statements.
          Open

                } else if (ch === '#') {
                  // we don't eat white-space, we want the hex color and or id only
                  stream.eatWhile(/[A-Za-z0-9]/);
                  // check if there is a proper hex color length e.g. #eee || #eeeEEE
                  if (stream.current().length === 4 || stream.current().length === 7) {

            Avoid deeply nested control flow statements.
            Open

                      if (selectors.test(stream.current())) {
                        return ret('tag', 'tag');
                      } else if (stream.peek() === ':') { // ::-webkit-search-decoration
                        stream.next();
                        stream.eatWhile(/[a-z\\\-]/);

              Avoid deeply nested control flow statements.
              Open

                      } else if (ch === '~') {
                        if (type === 'r') {
                          return ret('string', 'string');
                        }
                      } else {

                Avoid deeply nested control flow statements.
                Open

                        if (stream.peek() === ' ') {
                          stream.eatSpace();
                        }

                  Avoid deeply nested control flow statements.
                  Open

                          if (stream.peek() === ')') {
                            return ret('number', 'unit'); // rgba(0,0,0,.25);
                          }

                    Avoid too many return statements within this function.
                    Open

                            return ret(null, 'select-op');

                      Avoid too many return statements within this function.
                      Open

                                    return ret('atom', 'tag');

                        Avoid too many return statements within this function.
                        Open

                                return ret('number', 'unit');

                          Avoid too many return statements within this function.
                          Open

                                        return ret('color', 'unit');

                            Avoid too many return statements within this function.
                            Open

                                      return tokenSComment(stream, state);

                              Avoid too many return statements within this function.
                              Open

                                            return ret('color', 'unit');

                                Avoid too many return statements within this function.
                                Open

                                            return ret('string', 'string'); // let url(/images/logo.png) without quotes return as string

                                  Avoid too many return statements within this function.
                                  Open

                                            return ret(null, ch);

                                    Avoid too many return statements within this function.
                                    Open

                                                  return ret('atom', 'tag');

                                      Avoid too many return statements within this function.
                                      Open

                                                  return ret('string', 'string');

                                        Avoid too many return statements within this function.
                                        Open

                                                  return ret('string', 'string');

                                          Avoid too many return statements within this function.
                                          Open

                                                      return ret(null, ch);

                                            Avoid too many return statements within this function.
                                            Open

                                                        return ret('string', 'string');

                                              Avoid too many return statements within this function.
                                              Open

                                                            return ret('color', 'unit');

                                                Avoid too many return statements within this function.
                                                Open

                                                          return ret('atom', 'tag');

                                                  Avoid too many return statements within this function.
                                                  Open

                                                          return ret(null, ch);

                                                    Avoid too many return statements within this function.
                                                    Open

                                                                return ret('atom', 'tag');

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                  return ret('tag', 'tag');

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                  return ret('string', 'string');

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                  return ret('keyword', 'important');

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                        return ret(null, ch);

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                      return state.tokenize(stream, state);

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                          return ret('number', 'unit'); // rgba(0,0,0,.25);

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                                return ret('string', 'string');

                                                                    Avoid too many return statements within this function.
                                                                    Open

                                                                                  return ret('color', 'unit');

                                                                      Avoid too many return statements within this function.
                                                                      Open

                                                                                  return ret(null, ch);

                                                                        Avoid too many return statements within this function.
                                                                        Open

                                                                                      return ret('tag', 'tag');

                                                                          Avoid too many return statements within this function.
                                                                          Open

                                                                                    return ret('string', 'string'); // allow url(../image.png)

                                                                            Avoid too many return statements within this function.
                                                                            Open

                                                                                    return ret('tag', 'tag');

                                                                              Avoid too many return statements within this function.
                                                                              Open

                                                                                        return ret(null, ch);

                                                                                Avoid too many return statements within this function.
                                                                                Open

                                                                                          return ret('string', 'string');

                                                                                  Avoid too many return statements within this function.
                                                                                  Open

                                                                                            return ret('number', 'unit');

                                                                                    Avoid too many return statements within this function.
                                                                                    Open

                                                                                                return ret('tag', 'tag');

                                                                                      Avoid too many return statements within this function.
                                                                                      Open

                                                                                                    return ret('tag', 'tag');

                                                                                        Avoid too many return statements within this function.
                                                                                        Open

                                                                                                  else return ret('variable', 'variable');

                                                                                          Avoid too many return statements within this function.
                                                                                          Open

                                                                                                    return ret('string', 'string');

                                                                                            Avoid too many return statements within this function.
                                                                                            Open

                                                                                                      return ret(null, ch);

                                                                                              Avoid too many return statements within this function.
                                                                                              Open

                                                                                                        return ret('string', 'string');

                                                                                                Avoid too many return statements within this function.
                                                                                                Open

                                                                                                          return ret('variable', 'variable');

                                                                                                  Avoid too many return statements within this function.
                                                                                                  Open

                                                                                                            return ret('tag', 'tag');

                                                                                                    Avoid too many return statements within this function.
                                                                                                    Open

                                                                                                              if (t_v) return ret('tag', 'tag');

                                                                                                      Avoid too many return statements within this function.
                                                                                                      Open

                                                                                                                return ret('tag', 'tag');

                                                                                                        Avoid too many return statements within this function.
                                                                                                        Open

                                                                                                                  return ret('color', 'unit');

                                                                                                          Avoid too many return statements within this function.
                                                                                                          Open

                                                                                                                    return ret('tag', 'tag');

                                                                                                            Avoid too many return statements within this function.
                                                                                                            Open

                                                                                                                      return ret('string', 'string'); // let url(/images/logo.png) without quotes return as string

                                                                                                              Avoid too many return statements within this function.
                                                                                                              Open

                                                                                                                        if (/[{<>.a-zA-Z\/]/.test(stream.peek()) || stream.eol()) return ret('tag', 'tag'); // e.g. button.icon-plus

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

                                                                                                                          if (!t_v) {
                                                                                                                            var old_pos = stream.pos;
                                                                                                                            var sc = stream.current().length;
                                                                                                                            stream.eatWhile(/[a-z\\\-]/);
                                                                                                                            var new_pos = stream.pos;
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 159..170

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

                                                                                                                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

                                                                                                                        } else if (/\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() === '/')) && stream.current().indexOf('.') !== -1) {
                                                                                                                          if (stream.current().substring(stream.current().length - 1, stream.current().length) === '{') {
                                                                                                                            stream.backUp(1);
                                                                                                                            return ret('tag', 'tag');
                                                                                                                          } // end if
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 141..178

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

                                                                                                                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 (type === '{') {
                                                                                                                          if (context === '@media') state.stack[state.stack.length - 1] = '@media{';
                                                                                                                          else state.stack.push('{');
                                                                                                                        } else if (type === '}') state.stack.pop();
                                                                                                                        else if (type === '@media') state.stack.push('@media');
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 256..262

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

                                                                                                                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 (type === 'hash' && context === 'rule') style = 'atom';
                                                                                                                        else if (style === 'variable') {
                                                                                                                          if (context === 'rule') style = null; // 'tag'
                                                                                                                          else if (!context || context === '@media{') {
                                                                                                                            style = stream.current() === 'when' ? 'variable' : /[\s,|\s\)|\s]/.test(stream.peek()) ? 'tag' : type;
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 245..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 117.

                                                                                                                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

                                                                                                                      while ((ch = stream.next()) != null) {
                                                                                                                        if (dashes >= 2 && ch === '>') {
                                                                                                                          state.tokenize = tokenBase;
                                                                                                                          break;
                                                                                                                        }
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 210..216

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

                                                                                                                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

                                                                                                                        } else if (stream.eol() || stream.peek() === '[' || stream.peek() === '#' || type === 'tag') {
                                                                                                                          if (stream.current().substring(stream.current().length - 1, stream.current().length) === '{') stream.backUp(1);
                                                                                                                          return ret('tag', 'tag');
                                                                                                                        } else if (type === 'compare' || type === 'a' || type === '(') {
                                                                                                                          return ret('string', 'string');
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 149..178

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

                                                                                                                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

                                                                                                                    function keySet (array) {
                                                                                                                      var keys = {};
                                                                                                                      for (var i = 0; i < array.length; ++i) {
                                                                                                                        keys[array[i]] = true;
                                                                                                                      }
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 182..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 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

                                                                                                                      while ((ch = stream.next()) != null) {
                                                                                                                        if (maybeEnd && ch === '/') {
                                                                                                                          state.tokenize = tokenBase;
                                                                                                                          break;
                                                                                                                        }
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 198..204

                                                                                                                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 (/\/|\)|#/.test(stream.peek() || (stream.eatSpace() && stream.peek() === ')')) || stream.eol()) {
                                                                                                                            return ret('string', 'string'); // let url(/images/logo.png) without quotes return as string
                                                                                                                          }
                                                                                                                lib/assets/javascripts/utils/carto.codemirror.js on lines 46..46

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

                                                                                                                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