haraka/haraka-plugin-spf

View on GitHub

Showing 68 of 68 total issues

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 hook_mail has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.hook_mail = async function (next, connection, params) {
        const plugin = this
      
        const txn = connection?.transaction
        if (!txn) return next()
      Severity: Minor
      Found in index.js - About 4 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 hook_mail has 102 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.hook_mail = async function (next, connection, params) {
        const plugin = this
      
        const txn = connection?.transaction
        if (!txn) return next()
      Severity: Major
      Found in index.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 return_results has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
          Open

          exports.return_results = function (
            next,
            connection,
            spf,
            scope,
          Severity: Minor
          Found in index.js - About 3 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

          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

          File index.js has 297 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          // spf
          
          const SPF = require('./lib/spf').SPF
          const net_utils = require('haraka-net-utils')
          const DSN = require('haraka-dsn')
          Severity: Minor
          Found in index.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

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

                case spf.SPF_NONE:
                  if (this.cfg[deny][`${scope}_none`]) {
                    text = this.cfg[deny].openspf_text
                      ? text
                      : `${msgpre} SPF record not found`
            Severity: Major
            Found in index.js and 2 other locations - About 2 hrs to fix
            index.js on lines 317..322
            index.js on lines 323..328

            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

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

                case spf.SPF_FAIL:
                  if (this.cfg[deny][`${scope}_fail`]) {
                    text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF Fail`
                    return next(DENY, text)
                  }
            Severity: Major
            Found in index.js and 2 other locations - About 2 hrs to fix
            index.js on lines 306..313
            index.js on lines 317..322

            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

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

                case spf.SPF_SOFTFAIL:
                  if (this.cfg[deny][`${scope}_softfail`]) {
                    text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF SoftFail`
                    return next(DENY, text)
                  }
            Severity: Major
            Found in index.js and 2 other locations - About 2 hrs to fix
            index.js on lines 306..313
            index.js on lines 323..328

            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

            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 load_spf_ini has 54 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports.load_spf_ini = function () {
                this.nu = net_utils // so tests can set public_ip
                this.SPF = SPF
              
                this.cfg = this.config.get(
              Severity: Major
              Found in index.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
                  Severity
                  Category
                  Status
                  Source
                  Language