Showing 30 of 123 total issues

File http-api.js has 406 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const toxy = require('../..')
const expect = require('chai').expect
const supertest = require('supertest')

suite('http api', function () {
Severity: Minor
Found in test/admin/http-api.js - About 5 hrs to fix

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

    module.exports = function slowRead (opts) {
      opts = opts || {}
    
      var threshold = +opts.threshold || 1000
      var chunkSize = +opts.chunk || +opts.bps || 1024
    Severity: Minor
    Found in lib/poisons/slow-read.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 throttle has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function throttle (opts) {
      opts = opts || {}
    
      const delay = +opts.threshold || +opts.delay || 100
      const chunkSize = +opts.bps || +opts.bytes || +opts.chunk || 1024
    Severity: Minor
    Found in lib/poisons/throttle.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 abort has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = function abort (opts) {
      if (typeof opts === 'number') {
        opts = { delay: opts }
      }
    
    
    Severity: Minor
    Found in lib/poisons/abort.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

    File toxy.js has 263 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const http = require('http')
    const sinon = require('sinon')
    const expect = require('chai').expect
    const toxy = require('..')
    const supertest = require('supertest')
    Severity: Minor
    Found in test/toxy.js - About 2 hrs to fix

      Function exports has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      module.exports = function (opts) {
        opts = opts || {}
      
        const admin = new Admin(opts)
      
      
      Severity: Major
      Found in lib/admin/index.js - About 2 hrs to fix

        Function slowRead has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = function slowRead (opts) {
          opts = opts || {}
        
          var threshold = +opts.threshold || 1000
          var chunkSize = +opts.chunk || +opts.bps || 1024
        Severity: Minor
        Found in lib/poisons/slow-read.js - About 1 hr to fix

          Function responseStatus has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports = function responseStatus (opts) {
            opts = parseOptions(opts)
          
            const lower = +opts.lower
            const higher = +opts.higher
          Severity: Minor
          Found in lib/rules/response-status.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 throttle has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = function throttle (opts) {
            opts = opts || {}
          
            const delay = +opts.threshold || +opts.delay || 100
            const chunkSize = +opts.bps || +opts.bytes || +opts.chunk || 1024
          Severity: Minor
          Found in lib/poisons/throttle.js - About 1 hr to fix

            Function slowRead has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              return function slowRead (req, res, next) {
                var buf = []
                var ended = false
                var closed = false
                var _push = Object.getPrototypeOf(req).push
            Severity: Minor
            Found in lib/poisons/slow-read.js - About 1 hr to fix

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

                return function throttle (req, res, next) {
                  var _end = res.end
                  var _write = res.write
              
                  // Cache payload
              Severity: Minor
              Found in lib/poisons/throttle.js - About 1 hr to fix

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

                module.exports = function slowClose (opts) {
                  opts = opts || {}
                  const delay = +opts || +opts.delay || 1000
                
                  return function slowClose (req, res, next) {
                Severity: Minor
                Found in lib/poisons/slow-close.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 matchHeaders has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                module.exports = function matchHeaders (httpObj, headers) {
                  return Object.keys(headers).every(function (key) {
                    const rule = headers[key]
                    const value = (httpObj.headers || httpObj._headers || {})[key.toLowerCase()]
                
                
                Severity: Minor
                Found in lib/helpers/match-headers.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 body has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                module.exports = function body (opts) {
                  opts = opts || {}
                
                  const match = opts.match
                  const limit = opts.limit || '5mb'
                Severity: Minor
                Found in lib/rules/body.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 rateLimit has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                module.exports = function rateLimit (opts) {
                  opts = opts || {}
                
                  const code = +opts.code || 429
                  const limit = +opts.limit || 10
                Severity: Minor
                Found in lib/poisons/rate-limit.js - About 1 hr to fix

                  Function slowClose has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports = function slowClose (opts) {
                    opts = opts || {}
                    const delay = +opts || +opts.delay || 1000
                  
                    return function slowClose (req, res, next) {
                  Severity: Minor
                  Found in lib/poisons/slow-close.js - About 1 hr to fix

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

                    module.exports = function body (opts) {
                      opts = opts || {}
                    
                      const match = opts.match
                      const limit = opts.limit || '5mb'
                    Severity: Minor
                    Found in lib/rules/body.js - About 1 hr to fix

                      Function createDirective has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function createDirective (req, res, type) {
                        const body = req.body
                        const toxy = getStack(req)
                        const directives = req.toxy[type]
                      
                      
                      Severity: Minor
                      Found in lib/admin/routes/directives.js - About 1 hr to fix

                        Function create has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        exports.create = function (req, res) {
                          const toxy = req.toxy
                          const body = req.body
                        
                          if (!body || !body.path) {
                        Severity: Minor
                        Found in lib/admin/routes/routes.js - About 1 hr to fix

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

                            return function slowClose (req, res, next) {
                              // Cache native methods
                              const proto = Object.getPrototypeOf(res)
                          
                              // Store state
                          Severity: Minor
                          Found in lib/poisons/slow-close.js - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language