CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/builder/helpers/parser-css.js

Summary

Maintainability
F
5 days
Test Coverage

Function _extract has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  _extract: function (method, extractVariables) {
    var self = this;
    var columns = [];
    var definitions;
    var def;
Severity: Minor
Found in lib/assets/javascripts/builder/helpers/parser-css.js - 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

Function parse has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

  parse: function (cartocss) {
    this.parse_env = {
      validation_data: false,
      frames: [],
      errors: [],
Severity: Minor
Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 3 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 parse has 75 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  parse: function (cartocss) {
    this.parse_env = {
      validation_data: false,
      frames: [],
      errors: [],
Severity: Major
Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 3 hrs to fix

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

    var carto = require('carto');
    var torque = require('torque.js');
    var Utils = require('builder/helpers/utils');
    var _ = require('underscore');
    
    
    Severity: Minor
    Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 2 hrs to fix

      Function _extract has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _extract: function (method, extractVariables) {
          var self = this;
          var columns = [];
          var definitions;
          var def;
      Severity: Minor
      Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 1 hr to fix

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

          _varsFromRule: function (rule) {
            function searchRecursiveByType (v, t) {
              var res = [];
              var i;
              var r;
        Severity: Minor
        Found in lib/assets/javascripts/builder/helpers/parser-css.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 _colorsFromRule has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          _colorsFromRule: function (rule) {
            function searchRecursiveByType (v, t) {
              var res = [];
              var i;
              var r;
        Severity: Minor
        Found in lib/assets/javascripts/builder/helpers/parser-css.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

        Avoid deeply nested control flow statements.
        Open

                    for (f in def.filters) {
                      filter = def.filters[f];
                      for (k in filter) {
                        filter_key = filter[k];
                        if (filter_key.key && filter_key.key.value) {
        Severity: Major
        Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

              return true;
          Severity: Major
          Found in lib/assets/javascripts/builder/helpers/parser-css.js - About 30 mins to fix

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

              _checkValidType: function (e, type) {
                if (['number', 'float'].indexOf(type) > -1) {
                  return typeof e.value === 'number';
                } else if (type === 'string') {
                  return e.value !== 'undefined' && typeof e.value === 'string';
            Severity: Minor
            Found in lib/assets/javascripts/builder/helpers/parser-css.js - 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

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

                function searchRecursiveByType (v, t) {
                  var res = [];
                  var i;
                  var r;
            
            
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 4 hrs to fix
            lib/assets/javascripts/builder/helpers/parser-css.js on lines 165..180

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

            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 searchRecursiveByType (v, t) {
                  var res = [];
                  var i;
                  var r;
                  for (i in v) {
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 4 hrs to fix
            lib/assets/javascripts/builder/helpers/parser-css.js on lines 185..201

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

            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

              getRuleByName: function (definition, ruleName) {
                if (!definition._rulesByName) {
                  var rulesMap = definition._rulesByName = {};
                  for (var r in definition.rules) {
                    var rule = definition.rules[r];
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 3 hrs to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 1033..1042

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

            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

                this.parse_env = {
                  validation_data: false,
                  frames: [],
                  errors: [],
                  error: function (obj) {
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 2 hrs to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 761..769

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

            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

                  for (i in defs) {
                    if (defs[i].elements.length > 0) {
                      if (defs[i].elements[0].value === 'Map') {
                        mapDef = defs.splice(i, 1)[0];
                      }
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 786..792

            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

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

              variablesUsed: function () {
                // extraction method
                var method = function (self, rule) {
                  return _.map(self._varsFromRule(rule), function (f) {
                    return f.value;
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 1000..1010

            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

                  if (def.zoom === 8388607 && _.size(def.filters.filters) === 0 && def.attachment === '__default__') {
                    rules = rules.concat(def.rules);
                  }
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 1020..1022

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

            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

              _checkValidColor: function (e) {
                var expectedArguments = {rgb: 3, hsl: 3, rgba: 4, hsla: 4};
                return typeof e.rgb !== 'undefined' || expectedArguments[e.name] === e.args;
              },
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 853..856

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

            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 (opt && opt.mode === 'hex') {
                    colors = _.map(colors, function (color) {
                      return Utils.rgbToHex(color[0], color[1], color[2]);
                    });
                  }
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/builder/helpers/parser-css.js on lines 270..274

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

            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 (opt && opt.mode === 'hex') {
                  colors = _.map(colors, function (color) {
                    return Utils.rgbToHex(color[0], color[1], color[2]);
                  });
                }
            Severity: Major
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 1 hr to fix
            lib/assets/javascripts/builder/helpers/parser-css.js on lines 293..297

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

            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

            var CartoParser = function (cartocss) {
              this.parse_env = null;
              this.ruleset = null;
              if (cartocss) {
                this.parse(cartocss);
            Severity: Minor
            Found in lib/assets/javascripts/builder/helpers/parser-css.js and 1 other location - About 35 mins to fix
            lib/assets/javascripts/cartodb/models/carto.js on lines 747..753

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

            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