haraka/haraka-plugin-spf

View on GitHub
lib/spf.js

Summary

Maintainability
F
1 wk
Test Coverage

Function check_host has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
Open

  async check_host(ip, domain, mail_from) {
    domain = domain.toLowerCase()
    mail_from = mail_from ? mail_from.toLowerCase() : `postmaster@${domain}`
    this.ipaddr = ipaddr.parse(ip)
    this.ip_ver = this.ipaddr.kind()
Severity: Minor
Found in lib/spf.js - About 1 day 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 spf.js has 562 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'
// spf

const dns = require('node:dns/promises')
const net = require('node:net')
Severity: Major
Found in lib/spf.js - About 1 day to fix

    Function mech_mx has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

      async mech_mx(qualifier, args) {
        this.count++
        // Parse any arguments
        let cm
        let cidr4
    Severity: Minor
    Found in lib/spf.js - About 6 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 expand_macros has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

      expand_macros(str) {
        const macro = /%{([slodipvh])((?:(?:\d+)?r?)?)?([-.+,/_=])?}/gi
        let match
        while ((match = macro.exec(str))) {
          // match[1] = macro-letter
    Severity: Minor
    Found in lib/spf.js - About 5 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 check_host has 121 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async check_host(ip, domain, mail_from) {
        domain = domain.toLowerCase()
        mail_from = mail_from ? mail_from.toLowerCase() : `postmaster@${domain}`
        this.ipaddr = ipaddr.parse(ip)
        this.ip_ver = this.ipaddr.kind()
    Severity: Major
    Found in lib/spf.js - About 4 hrs to fix

      Function mech_mx has 94 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async mech_mx(qualifier, args) {
          this.count++
          // Parse any arguments
          let cm
          let cidr4
      Severity: Major
      Found in lib/spf.js - About 3 hrs to fix

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

          async mech_a(qualifier, args) {
            this.count++
            // Parse any arguments
            let cm
            let cidr4
        Severity: Minor
        Found in lib/spf.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 mech_ptr has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          async mech_ptr(qualifier, args) {
            this.count++
            let dm
            let domain = this.domain
            if (args && (dm = /^:([^/ ]+)/.exec(args))) {
        Severity: Minor
        Found in lib/spf.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 mech_a has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async mech_a(qualifier, args) {
            this.count++
            // Parse any arguments
            let cm
            let cidr4
        Severity: Major
        Found in lib/spf.js - About 2 hrs to fix

          Function expand_macros has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            expand_macros(str) {
              const macro = /%{([slodipvh])((?:(?:\d+)?r?)?)?([-.+,/_=])?}/gi
              let match
              while ((match = macro.exec(str))) {
                // match[1] = macro-letter
          Severity: Major
          Found in lib/spf.js - About 2 hrs to fix

            Function mech_ptr has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async mech_ptr(qualifier, args) {
                this.count++
                let dm
                let domain = this.domain
                if (args && (dm = /^:([^/ ]+)/.exec(args))) {
            Severity: Major
            Found in lib/spf.js - About 2 hrs to fix

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

                async mech_ip(qualifier, args) {
                  const cidr = args.substr(1)
                  const match = /^([^/ ]+)(?:\/(\d+))?$/.exec(cidr)
                  if (!match) return this.SPF_NONE
              
              
              Severity: Minor
              Found in lib/spf.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 mech_include has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async mech_include(qualifier, args) {
                  const domain = args.substr(1)
                  // Avoid circular references
                  if (this.been_there[domain]) {
                    this.log_debug(`circular reference detected: ${domain}`)
              Severity: Minor
              Found in lib/spf.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                            if (this.ipaddr.match(range, cidr)) {
                              this.log_debug(
                                `mech_mx: ${this.ip} => ${address}/${cidr}: MATCH!`,
                              )
                              return this.return_const(qualifier)
                Severity: Major
                Found in lib/spf.js - About 45 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return this.SPF_NEUTRAL // default if no more mechanisms
                  Severity: Major
                  Found in lib/spf.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return this.return_const(qualifier)
                    Severity: Major
                    Found in lib/spf.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return this.SPF_NONE
                      Severity: Major
                      Found in lib/spf.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return this.SPF_PERMERROR
                        Severity: Major
                        Found in lib/spf.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                if (result && result !== this.SPF_NONE) return result
                          Severity: Major
                          Found in lib/spf.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  if (pending === 0) return this.SPF_NONE
                            Severity: Major
                            Found in lib/spf.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return this.SPF_PERMERROR
                              Severity: Major
                              Found in lib/spf.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                    return this.SPF_NONE
                                Severity: Major
                                Found in lib/spf.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                          return this.SPF_PERMERROR
                                  Severity: Major
                                  Found in lib/spf.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          if (result && result !== this.SPF_NONE) return result
                                    Severity: Major
                                    Found in lib/spf.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                              return this.SPF_PERMERROR
                                      Severity: Major
                                      Found in lib/spf.js - About 30 mins to fix

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

                                                    if (this.ipaddr.match(range, cidr)) {
                                                      this.log_debug(
                                                        `mech_mx: ${this.ip} => ${address}/${cidr}: MATCH!`,
                                                      )
                                                      return this.return_const(qualifier)
                                        Severity: Major
                                        Found in lib/spf.js and 1 other location - About 3 hrs to fix
                                        lib/spf.js on lines 441..446

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

                                        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.ipaddr.match(range, cidr)) {
                                                  this.log_debug(`mech_a: ${this.ip} => ${addr}/${cidr}: MATCH!`)
                                                  return this.return_const(qualifier)
                                                } else {
                                                  this.log_debug(`mech_a: ${this.ip} => ${addr}/${cidr}: NO MATCH`)
                                        Severity: Major
                                        Found in lib/spf.js and 1 other location - About 3 hrs to fix
                                        lib/spf.js on lines 534..543

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

                                        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

                                            try {
                                              const addrs = await dns.resolve(exists)
                                              this.log_debug(`mech_exists: ${exists} result=${addrs.join(',')}`)
                                              return this.return_const(qualifier)
                                            } catch (err) {
                                        Severity: Major
                                        Found in lib/spf.js and 1 other location - About 2 hrs to fix
                                        lib/spf.js on lines 421..433

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

                                        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

                                            try {
                                              addrs = await dns[resolve_method](domain)
                                            } catch (err) {
                                              this.log_debug(`mech_a: ${err}`)
                                              switch (err.code) {
                                        Severity: Major
                                        Found in lib/spf.js and 1 other location - About 2 hrs to fix
                                        lib/spf.js on lines 377..391

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

                                        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 (args && (cm = /\/(\d+)((?:\/\/(\d+))?)$/.exec(args))) {
                                              cidr4 = cm[1]
                                              cidr6 = cm[2]
                                            }
                                        Severity: Minor
                                        Found in lib/spf.js and 1 other location - About 30 mins to fix
                                        lib/spf.js on lines 400..403

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

                                        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 (args && (cm = /\/(\d+)(?:\/\/(\d+))?$/.exec(args))) {
                                              cidr4 = cm[1]
                                              cidr6 = cm[2]
                                            }
                                        Severity: Minor
                                        Found in lib/spf.js and 1 other location - About 30 mins to fix
                                        lib/spf.js on lines 464..467

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

                                        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