CartoDB/cartodb20

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

Summary

Maintainability
F
6 days
Test Coverage

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

module.exports = function (CodeMirror) {
  /*eslint-disable */
  var Pos = CodeMirror.Pos;

  function SearchCursor(doc, query, pos, caseFold) {

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

module.exports = function (CodeMirror) {
  /*eslint-disable */
  var Pos = CodeMirror.Pos;

  function SearchCursor(doc, query, pos, caseFold) {

    Function SearchCursor has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function SearchCursor(doc, query, pos, caseFold) {
        this.atOccurrence = false; this.doc = doc;
        if (caseFold == null && typeof query == "string") caseFold = false;
    
        pos = pos ? doc.clipPos(pos) : Pos(0, 0);

      Function matches has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            this.matches = function(reverse, pos) {
              if (reverse) {
                query.lastIndex = 0;
                var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
                for (;;) {

        Consider simplifying this complex logical expression.
        Open

                if (reverse) {
                  query.lastIndex = 0;
                  var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
                  for (;;) {
                    query.lastIndex = cutOff;

          Avoid deeply nested control flow statements.
          Open

                        if (target[i] != fold(doc.getLine(ln))) return;

            Avoid deeply nested control flow statements.
            Open

                          if (target[i] != fold(doc.getLine(ln))) return;

              Avoid deeply nested control flow statements.
              Open

                            if (match > -1) {
                              match = adjustPos(orig, line, match);
                              return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
                            }

                Avoid deeply nested control flow statements.
                Open

                               if (match > -1) {
                                 match = adjustPos(orig, line, match) + pos.ch;
                                 return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
                               }

                  Avoid too many return statements within this function.
                  Open

                              if (pos.line + (target.length - 1) > doc.lastLine()) return;

                    Avoid too many return statements within this function.
                    Open

                                if (fold(line.slice(cut)) != target[0]) return;

                      Avoid too many return statements within this function.
                      Open

                                    if (target[i] != fold(doc.getLine(ln))) return;

                        Avoid too many return statements within this function.
                        Open

                                    return {from: Pos(ln, cut), to: to};

                          Avoid too many return statements within this function.
                          Open

                                      if (fold(doc.getLine(ln).slice(0, origTarget[last].length)) != target[last]) return;

                            Avoid too many return statements within this function.
                            Open

                                        return {from: from, to: Pos(ln, origTarget[last].length)};

                              There are no issues that match your filters.

                              Category
                              Status