antongolub/npm-registry-firewall

View on GitHub

Showing 8 of 8 total issues

Function createRouter has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

export const createRouter = (routes, base = '/') => async (req, res, next = () => {}) => {
  if (base === '*') {
    const i = req.url.indexOf('/', 1)
    req.base = req.url.slice(0, i)
    req.url = req.url.slice(i)
Severity: Minor
Found in src/main/js/http/router.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 getMetricsDigest has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const getMetricsDigest = () => {
  const formatUptime = (uptime) => {
    const pad = s => (s < 10 ? '0' : '') + s
    const hours = Math.floor(uptime / (60 * 60))
    const minutes = Math.floor(uptime % (60 * 60) / 60)
Severity: Minor
Found in src/main/js/metric.js - About 1 hr to fix

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

    export const matchByOrg = (opts, org) =>
      opts.org?.some(n => {
          if (!org) {
            return false
          }
    Severity: Minor
    Found in src/main/js/firewall/plugins/std.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 matchByName has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export const matchByName = (opts, name, version) =>
      opts.name?.some(n => {
          if (n === name) {
            return true
          }
    Severity: Minor
    Found in src/main/js/firewall/plugins/std.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 trace has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    export const trace = async (req, res, next) => {
      req.id = res.id = genId()
    
      const ctx = getCtx()
      ctx.logExtra = Object.assign(ctx.logExtra || {}, {
    Severity: Minor
    Found in src/main/js/mwares/trace.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

    Avoid too many return statements within this function.
    Open

        return res
          .writeHead(FOUND, {Location: tarball})
          .end()
    Severity: Major
    Found in src/main/js/firewall/middleware.js - About 30 mins to fix

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

      const logDenied = (name, directives) => {
        const denied = Object.entries(directives).reduce((m, [v, {policy, pluginName, options}]) => {
          if (policy === 'deny') {
            const snap = JSON.stringify({pluginName, policy, options})
            if (!m[snap]) {
      Severity: Minor
      Found in src/main/js/firewall/packument.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 createServer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      export const createServer = ({host, port, secure, router, keepAliveTimeout, headersTimeout, requestTimeout }) => {
        const entrypoint = `${secure ? 'https' : 'http'}://${host}:${port}`
        const lib = secure ? https : http
        const options = {...secure}
        const sockets = createSocketPool()
      Severity: Minor
      Found in src/main/js/http/server.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

      Severity
      Category
      Status
      Source
      Language