enclose-io/compiler

View on GitHub
lts/lib/_http_agent.js

Summary

Maintainability
F
6 days
Test Coverage

File _http_agent.js has 314 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: Minor
Found in lts/lib/_http_agent.js - About 3 hrs to fix

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

    Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
                                                     localAddress/* legacy */) {
      // Legacy API: addRequest(req, host, port, localAddress)
      if (typeof options === 'string') {
        options = {
    Severity: Minor
    Found in lts/lib/_http_agent.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 Agent has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function Agent(options) {
      if (!(this instanceof Agent))
        return new Agent(options);
    
      EventEmitter.call(this);
    Severity: Major
    Found in lts/lib/_http_agent.js - About 2 hrs to fix

      Function addRequest has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
                                                       localAddress/* legacy */) {
        // Legacy API: addRequest(req, host, port, localAddress)
        if (typeof options === 'string') {
          options = {
      Severity: Minor
      Found in lts/lib/_http_agent.js - About 1 hr to fix

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

        Agent.prototype.removeSocket = function removeSocket(s, options) {
          const name = this.getName(options);
          debug('removeSocket', name, 'writable:', s.writable);
          const sets = [this.sockets];
        
        
        Severity: Minor
        Found in lts/lib/_http_agent.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 installListeners has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function installListeners(agent, s, options) {
          function onFree() {
            debug('CLIENT socket onFree');
            agent.emit('free', s, options);
          }
        Severity: Minor
        Found in lts/lib/_http_agent.js - About 1 hr to fix

          Function createSocket has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Agent.prototype.createSocket = function createSocket(req, options, cb) {
            options = { ...options, ...this.options };
            if (options.socketPath)
              options.path = options.socketPath;
          
          
          Severity: Minor
          Found in lts/lib/_http_agent.js - About 1 hr to fix

            Function calculateServerName has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function calculateServerName(options, req) {
              let servername = options.host;
              const hostHeader = req.getHeader('host');
              if (hostHeader) {
                // abc => abc
            Severity: Minor
            Found in lts/lib/_http_agent.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 createSocket has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            Agent.prototype.createSocket = function createSocket(req, options, cb) {
              options = { ...options, ...this.options };
              if (options.socketPath)
                options.path = options.socketPath;
            
            
            Severity: Minor
            Found in lts/lib/_http_agent.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 destroy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            Agent.prototype.destroy = function destroy() {
              for (const set of [this.freeSockets, this.sockets]) {
                for (const key of ObjectKeys(set)) {
                  for (const setName of set[key]) {
                    setName.destroy();
            Severity: Minor
            Found in lts/lib/_http_agent.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 installListeners has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            function installListeners(agent, s, options) {
              function onFree() {
                debug('CLIENT socket onFree');
                agent.emit('free', s, options);
              }
            Severity: Minor
            Found in lts/lib/_http_agent.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

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

            function installListeners(agent, s, options) {
              function onFree() {
                debug('CLIENT socket onFree');
                agent.emit('free', s, options);
              }
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 1 day to fix
            current/lib/_http_agent.js on lines 362..408

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

            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

            Agent.prototype.getName = function getName(options) {
              let name = options.host || 'localhost';
            
              name += ':';
              if (options.port)
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 6 hrs to fix
            current/lib/_http_agent.js on lines 206..226

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

            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 maybeEnableKeylog(eventName) {
              if (eventName === 'keylog') {
                this.removeListener('newListener', maybeEnableKeylog);
                // Future sockets will listen on keylog at creation.
                const agent = this;
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 4 hrs to fix
            current/lib/_http_agent.js on lines 186..199

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

            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 (hostHeader.startsWith('[')) {
                  const index = hostHeader.indexOf(']');
                  if (index === -1) {
                    // Leading '[', but no ']'. Need to do something...
                    servername = hostHeader;
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 3 hrs to fix
            current/lib/_http_agent.js on lines 344..354

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

            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

            Agent.prototype.destroy = function destroy() {
              for (const set of [this.freeSockets, this.sockets]) {
                for (const key of ObjectKeys(set)) {
                  for (const setName of set[key]) {
                    setName.destroy();
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 2 hrs to fix
            current/lib/_http_agent.js on lines 484..492

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

            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 setRequestSocket(agent, req, socket) {
              req.onSocket(socket);
              const agentTimeout = agent.options.timeout || 0;
              if (req.timeout === undefined || req.timeout === agentTimeout) {
                return;
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 2 hrs to fix
            current/lib/_http_agent.js on lines 494..501

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

            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 (handle && typeof handle.asyncReset === 'function') {
                  // Assign the handle a new asyncId and run any destroy()/init() hooks.
                  handle.asyncReset(new ReusedHandle(handle.getProviderType(), handle));
                  socket[async_id_symbol] = handle.getAsyncId();
                }
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 1 hr to fix
            current/lib/_http_agent.js on lines 506..510

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

            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

            Agent.prototype.reuseSocket = function reuseSocket(socket, req) {
              debug('have free socket');
              socket.removeListener('error', freeSocketErrorListener);
              req.reusedSocket = true;
              socket.ref();
            Severity: Major
            Found in lts/lib/_http_agent.js and 1 other location - About 1 hr to fix
            current/lib/_http_agent.js on lines 477..482

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

            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 freeSocketErrorListener(err) {
              const socket = this;
              debug('SOCKET ERROR on FREE socket:', err.message, err.stack);
              socket.destroy();
              socket.emit('agentRemove');
            Severity: Minor
            Found in lts/lib/_http_agent.js and 1 other location - About 55 mins to fix
            current/lib/_http_agent.js on lines 71..76

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

            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

            class ReusedHandle {
              constructor(type, handle) {
                this.type = type;
                this.handle = handle;
              }
            Severity: Minor
            Found in lts/lib/_http_agent.js and 1 other location - About 40 mins to fix
            current/lib/_http_agent.js on lines 64..69

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

            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