src/selection.js

Summary

Maintainability
F
1 wk
Test Coverage

File selection.js has 781 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const { Point, Range } = require('text-buffer');
const { pick } = require('underscore-plus');
const { Emitter } = require('event-kit');

const NonWhitespaceRegExp = /\S/;
Severity: Major
Found in src/selection.js - About 1 day to fix

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

    module.exports = class Selection {
      constructor({ cursor, marker, editor, id }) {
        this.id = id != null ? id : nextId++;
        this.cursor = cursor;
        this.marker = marker;
    Severity: Major
    Found in src/selection.js - About 1 day to fix

      Function insertText has 74 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        insertText(text, options = {}) {
          if (!this.ensureWritable('insertText', options)) return;
      
          let desiredIndentLevel, indentAdjustment;
          const oldBufferRange = this.getBufferRange();
      Severity: Major
      Found in src/selection.js - About 2 hrs to fix

        Function insertText has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          insertText(text, options = {}) {
            if (!this.ensureWritable('insertText', options)) return;
        
            let desiredIndentLevel, indentAdjustment;
            const oldBufferRange = this.getBufferRange();
        Severity: Minor
        Found in src/selection.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 joinLines has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          joinLines(options = {}) {
            if (!this.ensureWritable('joinLines', options)) return;
            let joinMarker;
            const selectedRange = this.getBufferRange();
            if (selectedRange.isEmpty()) {
        Severity: Minor
        Found in src/selection.js - About 1 hr to fix

          Function joinLines has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            joinLines(options = {}) {
              if (!this.ensureWritable('joinLines', options)) return;
              let joinMarker;
              const selectedRange = this.getBufferRange();
              if (selectedRange.isEmpty()) {
          Severity: Minor
          Found in src/selection.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 addSelectionAbove has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            addSelectionAbove() {
              const range = this.getGoalScreenRange().copy();
              const previousRow = range.end.row - 1;
          
              for (let row = previousRow; row >= 0; row--) {
          Severity: Minor
          Found in src/selection.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 addSelectionBelow has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            addSelectionBelow() {
              const range = this.getGoalScreenRange().copy();
              const nextRow = range.end.row + 1;
          
              for (
          Severity: Minor
          Found in src/selection.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 copy has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            copy(maintainClipboard = false, fullLine = false) {
              if (this.isEmpty()) return;
              const { start, end } = this.getBufferRange();
              const selectionText = this.editor.getTextInRange([start, end]);
              const precedingText = this.editor.getTextInRange([[start.row, 0], start]);
          Severity: Minor
          Found in src/selection.js - About 1 hr to fix

            Function markerDidChange has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              markerDidChange(e) {
                const {
                  oldHeadBufferPosition,
                  oldTailBufferPosition,
                  newHeadBufferPosition
            Severity: Minor
            Found in src/selection.js - About 1 hr to fix

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

                indent({ autoIndent, bypassReadOnly } = {}) {
                  if (!this.ensureWritable('indent', { bypassReadOnly })) return;
                  const { row } = this.cursor.getBufferPosition();
              
                  if (this.isEmpty()) {
              Severity: Minor
              Found in src/selection.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 addSelectionBelow has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                addSelectionBelow() {
                  const range = this.getGoalScreenRange().copy();
                  const nextRow = range.end.row + 1;
              
                  for (
              Severity: Minor
              Found in src/selection.js - About 1 hr to fix

                Function deleteLine has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  deleteLine(options = {}) {
                    if (!this.ensureWritable('deleteLine', options)) return;
                    const range = this.getBufferRange();
                    if (range.isEmpty()) {
                      const start = this.cursor.getScreenRow();
                Severity: Minor
                Found in src/selection.js - About 45 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 copy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  copy(maintainClipboard = false, fullLine = false) {
                    if (this.isEmpty()) return;
                    const { start, end } = this.getBufferRange();
                    const selectionText = this.editor.getTextInRange([start, end]);
                    const precedingText = this.editor.getTextInRange([[start.row, 0], start]);
                Severity: Minor
                Found in src/selection.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

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

                    for (
                      let row = nextRow, end = this.editor.getLastScreenRow();
                      row <= end;
                      row++
                    ) {
                Severity: Major
                Found in src/selection.js and 1 other location - About 1 day to fix
                src/selection.js on lines 1064..1086

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

                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

                    for (let row = previousRow; row >= 0; row--) {
                      range.start.row = row;
                      range.end.row = row;
                      const clippedRange = this.editor.clipScreenRange(range, {
                        skipSoftWrapIndentation: true
                Severity: Major
                Found in src/selection.js and 1 other location - About 1 day to fix
                src/selection.js on lines 1030..1056

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

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

                  deleteToBeginningOfSubword(options = {}) {
                    if (!this.ensureWritable('deleteToBeginningOfSubword', options)) return;
                    if (this.isEmpty()) this.selectToPreviousSubwordBoundary();
                    this.deleteSelectedText(options);
                  }
                Severity: Major
                Found in src/selection.js and 2 other locations - About 1 hr to fix
                src/selection.js on lines 629..633
                src/selection.js on lines 685..689

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

                  deleteToBeginningOfWord(options = {}) {
                    if (!this.ensureWritable('deleteToBeginningOfWord', options)) return;
                    if (this.isEmpty()) this.selectToBeginningOfWord();
                    this.deleteSelectedText(options);
                  }
                Severity: Major
                Found in src/selection.js and 2 other locations - About 1 hr to fix
                src/selection.js on lines 685..689
                src/selection.js on lines 696..700

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

                  deleteToEndOfWord(options = {}) {
                    if (!this.ensureWritable('deleteToEndOfWord', options)) return;
                    if (this.isEmpty()) this.selectToEndOfWord();
                    this.deleteSelectedText(options);
                  }
                Severity: Major
                Found in src/selection.js and 2 other locations - About 1 hr to fix
                src/selection.js on lines 629..633
                src/selection.js on lines 696..700

                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

                    if (!opts.bypassReadOnly && this.editor.isReadOnly()) {
                      if (atom.inDevMode() || atom.inSpecMode()) {
                        const e = new Error(
                          'Attempt to mutate a read-only TextEditor through a Selection'
                        );
                Severity: Major
                Found in src/selection.js and 1 other location - About 1 hr to fix
                src/text-editor.js on lines 2392..2403

                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

                There are no issues that match your filters.

                Category
                Status