haraka/haraka-plugin-uribl

View on GitHub

Showing 15 of 15 total issues

Function do_lookups has a Cognitive Complexity of 81 (exceeds 5 allowed). Consider refactoring.
Open

exports.do_lookups = function (connection, next, hosts, type) {
  const plugin = this;

  // Store the results in the correct place based on the lookup type
  const results = connection?.transaction?.results || connection?.results;
Severity: Minor
Found in index.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

Function do_lookups has 157 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.do_lookups = function (connection, next, hosts, type) {
  const plugin = this;

  // Store the results in the correct place based on the lookup type
  const results = connection?.transaction?.results || connection?.results;
Severity: Major
Found in index.js - About 6 hrs to fix

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

    // Look up URLs in SURBL
    
    const url       = require('url');
    const dns       = require('dns');
    const net       = require('net');
    Severity: Minor
    Found in index.js - About 4 hrs to fix

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

        function do_replyto_header (cb) {
          const replyto = trans.header.get('reply-to');
          const rmatch = email_re.exec(replyto);
          if (rmatch) {
            return plugin.do_lookups(connection, cb, rmatch[1], 'replyto');
      Severity: Major
      Found in index.js and 1 other location - About 2 hrs to fix
      index.js on lines 360..367

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

      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

        function do_from_header (cb) {
          const from = trans.header.get_decoded('from');
          const fmatch = email_re.exec(from);
          if (fmatch) {
            return plugin.do_lookups(connection, cb, fmatch[1], 'from');
      Severity: Major
      Found in index.js and 1 other location - About 2 hrs to fix
      index.js on lines 370..377

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

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

      exports.lookup_header_zones = function (next, connection) {
      
        const email_re = /<?[^@]+@([^> ]+)>?/;
        const plugin = this;
        const trans = connection.transaction;
      Severity: Minor
      Found in index.js - About 1 hr to fix

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

        function extract_urls (urls, body, connection, self) {
          // extract from body.bodytext
          let match;
          if (!body || !body.bodytext) { return; }
        
        
        Severity: Minor
        Found in index.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 extract_urls has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function extract_urls (urls, body, connection, self) {
          // extract from body.bodytext
          let match;
          if (!body || !body.bodytext) { return; }
        
        
        Severity: Minor
        Found in index.js - About 1 hr to fix

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

          exports.lookup_header_zones = function (next, connection) {
          
            const email_re = /<?[^@]+@([^> ]+)>?/;
            const plugin = this;
            const trans = connection.transaction;
          Severity: Minor
          Found in index.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

          Avoid deeply nested control flow statements.
          Open

                else if (/^(?:1|true|yes|enabled|on)$/i.test(plugin.cfg[zone].strip_to_domain)) {
                  lookup = (tlds.split_hostname(host, 3))[1];
                }
                // Anything else..
                else {
          Severity: Major
          Found in index.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    if (net_utils.is_private_ip(host)) {
                      results.add(plugin, {skip: 'private IP' });
                      continue;
                    }
            Severity: Major
            Found in index.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      if (/^(?:1|true|yes|enabled|on)$/i.test(plugin.cfg[zone].not_ipv6_compatible) || /^(?:1|true|yes|enabled|on)$/i.test(plugin.cfg[zone].no_ip_lookups)) {
                        results.add(plugin, {skip: `IP (${host}) not supported for ${zone}` });
                        continue;
                      }
              Severity: Major
              Found in index.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                        else if ( ip_format === 'ip6') {
                          if (arpa.length < 32) continue; // Only full IP addresses
                          host = arpa.join('.');
                        }
                Severity: Major
                Found in index.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if (arpa.length < 4) continue; // Only full IP addresses
                  Severity: Major
                  Found in index.js - About 45 mins to fix

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

                    function check_excludes_list (host) {
                      host = host.split('.').reverse();
                      for (let i=0; i < host.length; i++) {
                        let check;
                        if (i === 0) {
                    Severity: Minor
                    Found in index.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