lib/readline.js

Summary

Maintainability
F
1 wk
Test Coverage

File readline.js has 940 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
Severity: Major
Found in lib/readline.js - About 2 days to fix

    Consider simplifying this complex logical expression.
    Open

      if (code >= 0x1100 && (
          code <= 0x115f ||  // Hangul Jamo
          0x2329 === code || // LEFT-POINTING ANGLE BRACKET
          0x232a === code || // RIGHT-POINTING ANGLE BRACKET
          // CJK Radicals Supplement .. Enclosed CJK Letters and Months
    Severity: Critical
    Found in lib/readline.js - About 1 day to fix

      Function _ttyWrite has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
      Open

      Interface.prototype._ttyWrite = function(s, key) {
        key = key || {};
      
        // Ignore escape key - Fixes #2876
        if (key.name == 'escape') return;
      Severity: Minor
      Found in lib/readline.js - About 7 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 _ttyWrite has 165 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Interface.prototype._ttyWrite = function(s, key) {
        key = key || {};
      
        // Ignore escape key - Fixes #2876
        if (key.name == 'escape') return;
      Severity: Major
      Found in lib/readline.js - About 6 hrs to fix

        Function emitKeys has 144 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function emitKeys(stream, s) {
          if (util.isBuffer(s)) {
            if (s[0] > 127 && util.isUndefined(s[1])) {
              s[0] -= 128;
              s = '\x1b' + s.toString(stream.encoding || 'utf-8');
        Severity: Major
        Found in lib/readline.js - About 5 hrs to fix

          Function isFullWidthCodePoint has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

          function isFullWidthCodePoint(code) {
            if (isNaN(code)) {
              return false;
            }
          
          
          Severity: Minor
          Found in lib/readline.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 Interface has 77 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function Interface(input, output, completer, terminal) {
            if (!(this instanceof Interface)) {
              return new Interface(input, output, completer, terminal);
            }
          
          
          Severity: Major
          Found in lib/readline.js - About 3 hrs to fix

            Function Interface has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

            function Interface(input, output, completer, terminal) {
              if (!(this instanceof Interface)) {
                return new Interface(input, output, completer, terminal);
              }
            
            
            Severity: Minor
            Found in lib/readline.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 handleGroup has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            function handleGroup(self, group, width, maxColumns) {
              if (group.length == 0) {
                return;
              }
              var minRows = Math.ceil(group.length / maxColumns);
            Severity: Minor
            Found in lib/readline.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 _tabComplete has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            Interface.prototype._tabComplete = function() {
              var self = this;
            
              self.pause();
              self.completer(self.line.slice(0, self.cursor), function(err, rv) {
            Severity: Minor
            Found in lib/readline.js - About 1 hr to fix

              Function _getDisplayPos has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              Interface.prototype._getDisplayPos = function(str) {
                var offset = 0;
                var col = this.columns;
                var row = 0;
                var code;
              Severity: Minor
              Found in lib/readline.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 emitKeypressEvents has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              function emitKeypressEvents(stream) {
                if (stream._keypressDecoder) return;
                var StringDecoder = require('string_decoder').StringDecoder; // lazy load
                stream._keypressDecoder = new StringDecoder('utf8');
              
              
              Severity: Minor
              Found in lib/readline.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 _getDisplayPos has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Interface.prototype._getDisplayPos = function(str) {
                var offset = 0;
                var col = this.columns;
                var row = 0;
                var code;
              Severity: Minor
              Found in lib/readline.js - About 1 hr to fix

                Consider simplifying this complex logical expression.
                Open

                    } else if (parts = functionKeyCodeRe.exec(s)) {
                      // ansi escape sequence
                
                      // reassemble the key code leaving out leading \x1b's,
                      // the modifier key bitflag and any meaningless "1;" sequence
                Severity: Major
                Found in lib/readline.js - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                if (!self.paused) {
                                  // Stream must be paused and resumed after SIGCONT to catch
                                  // SIGINT, SIGTSTP, and EOF.
                                  self.pause();
                                  self.emit('SIGCONT');
                  Severity: Major
                  Found in lib/readline.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if (this._sawReturn)
                              this._sawReturn = false;
                            else
                              this._line();
                    Severity: Major
                    Found in lib/readline.js - About 45 mins to fix

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

                      function emitKeys(stream, s) {
                        if (util.isBuffer(s)) {
                          if (s[0] > 127 && util.isUndefined(s[1])) {
                            s[0] -= 128;
                            s = '\x1b' + s.toString(stream.encoding || 'utf-8');
                      Severity: Minor
                      Found in lib/readline.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

                      Avoid deeply nested control flow statements.
                      Open

                              if (util.isBuffer(s))
                                s = s.toString('utf-8');
                      Severity: Major
                      Found in lib/readline.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                if (s) {
                                  var lines = s.split(/\r\n|\n|\r/);
                                  for (var i = 0, len = lines.length; i < len; i++) {
                                    if (i > 0) {
                                      this._line();
                        Severity: Major
                        Found in lib/readline.js - About 45 mins to fix

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

                          Interface.prototype._moveCursor = function(dx) {
                            var oldcursor = this.cursor;
                            var oldPos = this._getCursorPos();
                            this.cursor += dx;
                          
                          
                          Severity: Minor
                          Found in lib/readline.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 getStringWidth has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function getStringWidth(str) {
                            var width = 0;
                            str = stripVTControlCharacters(str);
                            for (var i = 0, len = str.length; i < len; i++) {
                              var code = codePointAt(str, i);
                          Severity: Minor
                          Found in lib/readline.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

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

                          function cursorTo(stream, x, y) {
                            if (util.isNullOrUndefined(stream))
                              return;
                          
                            if (!util.isNumber(x) && !util.isNumber(y))
                          Severity: Minor
                          Found in lib/readline.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 onend() {
                              if (util.isString(self._line_buffer) && self._line_buffer.length > 0) {
                                self.emit('line', self._line_buffer);
                              }
                              self.close();
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 103..108

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

                          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 (this.historyIndex > 0) {
                              this.historyIndex--;
                              this.line = this.history[this.historyIndex];
                              this.cursor = this.line.length; // set cursor to end of line.
                              this._refreshLine();
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 576..582

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

                          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 (this.historyIndex + 1 < this.history.length) {
                              this.historyIndex++;
                              this.line = this.history[this.historyIndex];
                              this.cursor = this.line.length; // set cursor to end of line.
                          
                          
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 560..571

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

                          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

                            function ontermend() {
                              if (util.isString(self.line) && self.line.length > 0) {
                                self.emit('line', self.line);
                              }
                              self.close();
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 96..101

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

                          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 (dy < 0) {
                              stream.write('\x1b[' + (-dy) + 'A');
                            } else if (dy > 0) {
                              stream.write('\x1b[' + dy + 'B');
                            }
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 1214..1218

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

                          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 (dx < 0) {
                              stream.write('\x1b[' + (-dx) + 'D');
                            } else if (dx > 0) {
                              stream.write('\x1b[' + dx + 'C');
                            }
                          Severity: Major
                          Found in lib/readline.js and 1 other location - About 1 hr to fix
                          lib/readline.js on lines 1220..1224

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

                          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