adobe/brackets

View on GitHub
src/search/node/FindInFilesDomain.js

Summary

Maintainability
F
5 days
Test Coverage

File FindInFilesDomain.js has 457 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright (c) 2015 - present Adobe Systems Incorporated. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
Severity: Minor
Found in src/search/node/FindInFilesDomain.js - About 7 hrs to fix

    Function init has 111 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function init(domainManager) {
        if (!domainManager.hasDomain("FindInFiles")) {
            domainManager.registerDomain("FindInFiles", {major: 0, minor: 1});
        }
        _domainManager = domainManager;
    Severity: Major
    Found in src/search/node/FindInFilesDomain.js - About 4 hrs to fix

      Function getSearchMatches has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      function getSearchMatches(contents, queryExpr) {
          if (!contents) {
              return;
          }
          // Quick exit if not found or if we hit the limit
      Severity: Minor
      Found in src/search/node/FindInFilesDomain.js - About 2 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 getSearchMatches has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getSearchMatches(contents, queryExpr) {
          if (!contents) {
              return;
          }
          // Quick exit if not found or if we hit the limit
      Severity: Major
      Found in src/search/node/FindInFilesDomain.js - About 2 hrs to fix

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

        function doSearch(searchObject, nextPages) {
        
            savedSearchObject = searchObject;
            if (!files) {
                console.log("no file object found");
        Severity: Minor
        Found in src/search/node/FindInFilesDomain.js - About 1 hr to fix

          Function offsetToLineNum has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function offsetToLineNum(textOrLines, offset) {
              if (Array.isArray(textOrLines)) {
                  var lines = textOrLines,
                      total = 0,
                      line;
          Severity: Minor
          Found in src/search/node/FindInFilesDomain.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 fileCrawler has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function fileCrawler() {
              if (!files || (files && files.length === 0)) {
                  setTimeout(fileCrawler, 1000);
                  return;
              }
          Severity: Minor
          Found in src/search/node/FindInFilesDomain.js - About 55 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function doSearch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function doSearch(searchObject, nextPages) {
          
              savedSearchObject = searchObject;
              if (!files) {
                  console.log("no file object found");
          Severity: Minor
          Found in src/search/node/FindInFilesDomain.js - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function parseQueryInfo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function parseQueryInfo(queryInfo) {
              var queryExpr;
          
              // TODO: only major difference between this one and the one in FindReplace is that
              // this always returns a regexp even for simple strings. Reconcile.
          Severity: Minor
          Found in src/search/node/FindInFilesDomain.js - About 35 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

          Avoid too many return statements within this function.
          Open

                  return textOrLines.substr(0, offset).split("\n").length - 1;
          Severity: Major
          Found in src/search/node/FindInFilesDomain.js - About 30 mins to fix

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

            function addFilesToCache(updateObject) {
                var fileList = updateObject.fileList || [],
                    filesInSearchScope = updateObject.filesInSearchScope || [],
                    i = 0,
                    changedFilesAlreadyInList = [],
            Severity: Minor
            Found in src/search/node/FindInFilesDomain.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

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

            function offsetToLineNum(textOrLines, offset) {
                if (Array.isArray(textOrLines)) {
                    var lines = textOrLines,
                        total = 0,
                        line;
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 7 hrs to fix
            src/utils/StringUtils.js on lines 91..117

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

            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 (highlightEndCh <= MAX_DISPLAY_LENGTH) {
                        // Don't store more than 200 chars per line
                        line = line.substr(0, Math.min(MAX_DISPLAY_LENGTH, line.length));
                    } else if (totalMatchLength > MAX_DISPLAY_LENGTH) {
                        // impossible to display the whole match
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 5 hrs to fix
            src/search/FindInFiles.js on lines 160..174

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

            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

                    matches.push({
                        start:       {line: lineNum, ch: ch},
                        end:         {line: lineNum + numMatchedLines - 1, ch: endCh},
            
                        highlightOffset: highlightOffset,
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 3 hrs to fix
            src/search/FindInFiles.js on lines 176..194

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

            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 (queryInfo.isRegexp) {
                    try {
                        queryExpr = new RegExp(queryInfo.query, flags);
                    } catch (e) {
                        return {valid: false, error: e.message};
            Severity: Minor
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 50 mins to fix
            src/search/FindUtils.js on lines 324..333

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

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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "filesRemoved",    // command name
                    removeFilesFromCache,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 4 other locations - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 611..621
            src/search/node/FindInFilesDomain.js on lines 622..632
            src/search/node/FindInFilesDomain.js on lines 633..643
            src/search/node/FindInFilesDomain.js on lines 655..665

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

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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "documentChanged",    // command name
                    documentChanged,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 4 other locations - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 611..621
            src/search/node/FindInFilesDomain.js on lines 622..632
            src/search/node/FindInFilesDomain.js on lines 644..654
            src/search/node/FindInFilesDomain.js on lines 655..665

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

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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "initCache",    // command name
                    initCache,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 4 other locations - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 611..621
            src/search/node/FindInFilesDomain.js on lines 622..632
            src/search/node/FindInFilesDomain.js on lines 633..643
            src/search/node/FindInFilesDomain.js on lines 644..654

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

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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "collapseResults",    // command name
                    setCollapseResults,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 4 other locations - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 622..632
            src/search/node/FindInFilesDomain.js on lines 633..643
            src/search/node/FindInFilesDomain.js on lines 644..654
            src/search/node/FindInFilesDomain.js on lines 655..665

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

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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "filesChanged",    // command name
                    addFilesToCache,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Major
            Found in src/search/node/FindInFilesDomain.js and 4 other locations - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 611..621
            src/search/node/FindInFilesDomain.js on lines 633..643
            src/search/node/FindInFilesDomain.js on lines 644..654
            src/search/node/FindInFilesDomain.js on lines 655..665

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

            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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "nextPage",    // command name
                    getNextPage,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Minor
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 600..610

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

            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

                domainManager.registerCommand(
                    "FindInFiles",       // domain name
                    "getAllResults",    // command name
                    getAllResults,   // command handler function
                    false,          // this command is synchronous in Node
            Severity: Minor
            Found in src/search/node/FindInFilesDomain.js and 1 other location - About 35 mins to fix
            src/search/node/FindInFilesDomain.js on lines 589..599

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

            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