enclose-io/compiler

View on GitHub
lts/lib/_stream_writable.js

Summary

Maintainability
F
6 days
Test Coverage

File _stream_writable.js has 505 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 lts/lib/_stream_writable.js - About 1 day to fix

    Function clearBuffer has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    function clearBuffer(stream, state) {
      state.bufferProcessing = true;
      var entry = state.bufferedRequest;
    
      if (stream._writev && entry && entry.next) {
    Severity: Minor
    Found in lts/lib/_stream_writable.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 clearBuffer has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function clearBuffer(stream, state) {
      state.bufferProcessing = true;
      var entry = state.bufferedRequest;
    
      if (stream._writev && entry && entry.next) {
    Severity: Minor
    Found in lts/lib/_stream_writable.js - About 1 hr to fix

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

      function onwrite(stream, er) {
        const state = stream._writableState;
        const sync = state.sync;
        const cb = state.writecb;
      
      
      Severity: Minor
      Found in lts/lib/_stream_writable.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 WritableState has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function WritableState(options, stream, isDuplex) {
        // Duplex streams are both readable and writable, but share
        // the same options object.
        // However, some cases require setting options to different
        // values for the readable and the writable sides of the duplex stream,
      Severity: Minor
      Found in lts/lib/_stream_writable.js - About 1 hr to fix

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

        function finishMaybe(stream, state) {
          const need = needFinish(state);
          if (need) {
            prefinish(stream, state);
            if (state.pendingcb === 0) {
        Severity: Minor
        Found in lts/lib/_stream_writable.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 onwrite has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function onwrite(stream, er) {
          const state = stream._writableState;
          const sync = state.sync;
          const cb = state.writecb;
        
        
        Severity: Minor
        Found in lts/lib/_stream_writable.js - About 1 hr to fix

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

          function writeOrBuffer(stream, state, chunk, encoding, cb) {
            if (!state.objectMode &&
                state.decodeStrings !== false &&
                encoding !== 'buffer' &&
                typeof chunk === 'string') {
          Severity: Minor
          Found in lts/lib/_stream_writable.js - About 1 hr to fix

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

            function Writable(options) {
              // Writable ctor is applied to Duplexes, too.
              // `realHasInstance` is necessary because using plain `instanceof`
              // would return false, as no `_writableState` property is attached.
            
            
            Severity: Minor
            Found in lts/lib/_stream_writable.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 writeOrBuffer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function writeOrBuffer(stream, state, chunk, encoding, cb) {
              if (!state.objectMode &&
                  state.decodeStrings !== false &&
                  encoding !== 'buffer' &&
                  typeof chunk === 'string') {
            Severity: Minor
            Found in lts/lib/_stream_writable.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 doWrite has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function doWrite(stream, state, writev, len, chunk, encoding, cb) {
            Severity: Major
            Found in lts/lib/_stream_writable.js - About 50 mins to fix

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

              function WritableState(options, stream, isDuplex) {
                // Duplex streams are both readable and writable, but share
                // the same options object.
                // However, some cases require setting options to different
                // values for the readable and the writable sides of the duplex stream,
              Severity: Minor
              Found in lts/lib/_stream_writable.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 write has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              Writable.prototype.write = function(chunk, encoding, cb) {
                const state = this._writableState;
                var ret = false;
                const isBuf = !state.objectMode && Stream._isUint8Array(chunk);
              
              
              Severity: Minor
              Found in lts/lib/_stream_writable.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 onwriteError has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function onwriteError(stream, state, sync, er, cb) {
              Severity: Minor
              Found in lts/lib/_stream_writable.js - About 35 mins to fix

                Function writeOrBuffer has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function writeOrBuffer(stream, state, chunk, encoding, cb) {
                Severity: Minor
                Found in lts/lib/_stream_writable.js - About 35 mins to fix

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

                  function doWrite(stream, state, writev, len, chunk, encoding, cb) {
                    state.writelen = len;
                    state.writecb = cb;
                    state.writing = true;
                    state.sync = true;
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 4 hrs to fix
                  current/lib/_stream_writable.js on lines 367..379

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

                  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 (options) {
                      if (typeof options.write === 'function')
                        this._write = options.write;
                  
                      if (typeof options.writev === 'function')
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 4 hrs to fix
                  current/lib/_stream_writable.js on lines 236..248

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

                  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 (sync) {
                        // It is a common case that the callback passed to .write() is always
                        // the same. In that case, we do not schedule a new nextTick(), but rather
                        // just increase a counter, to improve performance and avoid memory
                        // allocations.
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 4 hrs to fix
                  current/lib/_stream_writable.js on lines 421..435

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

                  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 prefinish(stream, state) {
                    if (!state.prefinished && !state.finalCalled) {
                      if (typeof stream._final === 'function' && !state.destroyed) {
                        state.pendingcb++;
                        state.finalCalled = true;
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 4 hrs to fix
                  current/lib/_stream_writable.js on lines 610..621

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

                  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 (typeof Symbol === 'function' && SymbolHasInstance) {
                    realHasInstance = FunctionPrototype[SymbolHasInstance];
                    ObjectDefineProperty(Writable, SymbolHasInstance, {
                      value: function(object) {
                        if (realHasInstance.call(this, object))
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 4 hrs to fix
                  current/lib/_stream_writable.js on lines 200..216

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

                  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

                  Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
                    // node::ParseEncoding() requires lower case.
                    if (typeof encoding === 'string')
                      encoding = encoding.toLowerCase();
                    if (!Buffer.isEncoding(encoding))
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 2 hrs to fix
                  current/lib/_stream_writable.js on lines 321..329

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

                  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

                    destroyed: {
                      get() {
                        return this._writableState ? this._writableState.destroyed : false;
                      },
                      set(value) {
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 1 hr to fix
                  current/lib/_stream_writable.js on lines 685..695

                  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 (typeof chunk === 'function') {
                      cb = chunk;
                      chunk = null;
                      encoding = null;
                    } else if (typeof encoding === 'function') {
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 1 hr to fix
                  current/lib/_stream_writable.js on lines 545..552

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

                  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 (state.autoDestroy) {
                          // In case of duplex streams we need a way to detect
                          // if the readable side is ready for autoDestroy as well
                          const rState = stream._readableState;
                          if (!rState || (rState.autoDestroy && rState.endEmitted)) {
                  Severity: Major
                  Found in lts/lib/_stream_writable.js and 1 other location - About 1 hr to fix
                  lts/lib/_stream_readable.js on lines 1222..1229

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

                  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 afterWriteTick({ stream, state, count, cb }) {
                    state.afterWriteTickInfo = null;
                    return afterWrite(stream, state, count, cb);
                  }
                  Severity: Minor
                  Found in lts/lib/_stream_writable.js and 1 other location - About 50 mins to fix
                  current/lib/_stream_writable.js on lines 439..442

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

                  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