haraka/haraka-plugin-rspamd

View on GitHub

Showing 17 of 20 total issues

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

'use strict';

// node built-ins
const http = require('http');

Severity: Minor
Found in index.js - About 4 hrs to fix

    Function get_options has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.get_options = function (connection) {
    
      // https://rspamd.com/doc/architecture/protocol.html
      // https://github.com/vstakhov/rspamd/blob/master/rules/http_headers.lua
      const options = {
    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

    Function do_milter_headers has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.do_milter_headers = function (connection, data) {
    
      if (!this.cfg.rmilter_headers.enabled) return;
      if (!data.milter) return;
    
    
    Severity: Minor
    Found in index.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 get_options has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.get_options = function (connection) {
    
      // https://rspamd.com/doc/architecture/protocol.html
      // https://github.com/vstakhov/rspamd/blob/master/rules/http_headers.lua
      const options = {
    Severity: Major
    Found in index.js - About 2 hrs to fix

      Function hook_data_post has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.hook_data_post = function (next, connection) {
        const plugin = this;
      
        if (!connection.transaction) return next();
        if (!plugin.should_check(connection)) return next();
      Severity: Major
      Found in index.js - About 2 hrs to fix

        Function add_headers has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        exports.add_headers = function (connection, data) {
          const cfg = this.cfg;
        
          if (!this.wants_headers_added(data)) return;
        
        
        Severity: Minor
        Found in index.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 load_rspamd_ini has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.load_rspamd_ini = function () {
          const plugin = this;
        
          plugin.cfg = plugin.config.get('rspamd.ini', {
            booleans: [
        Severity: Minor
        Found in index.js - About 1 hr to fix

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

          exports.get_clean = function (data, connection) {
            const clean = { symbols: {} };
          
            if (data.symbols) {
              Object.keys(data.symbols).forEach(key => {
          Severity: Minor
          Found in index.js - About 1 hr to fix

            Function do_milter_headers has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exports.do_milter_headers = function (connection, data) {
            
              if (!this.cfg.rmilter_headers.enabled) return;
              if (!data.milter) return;
            
            
            Severity: Minor
            Found in index.js - About 1 hr to fix

              Function add_headers has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports.add_headers = function (connection, data) {
                const cfg = this.cfg;
              
                if (!this.wants_headers_added(data)) return;
              
              
              Severity: Minor
              Found in index.js - About 1 hr to fix

                Function get_clean has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                exports.get_clean = function (data, connection) {
                  const clean = { symbols: {} };
                
                  if (data.symbols) {
                    Object.keys(data.symbols).forEach(key => {
                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 req has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  const req = http.request(plugin.get_options(connection), (res) => {
                    let rawData = '';
                
                    res.on('data', (chunk) => { rawData += chunk; });
                
                
                Severity: Minor
                Found in index.js - About 1 hr to fix

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

                  exports.load_rspamd_ini = function () {
                    const plugin = this;
                  
                    plugin.cfg = plugin.config.get('rspamd.ini', {
                      booleans: [
                  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 should_check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  exports.should_check = function (connection) {
                  
                    let result = true;  // default
                  
                    if (this.cfg.check.authenticated == false && connection.notes.auth_user) {
                  Severity: Minor
                  Found in index.js - About 45 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 wants_reject has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  exports.wants_reject = function (connection, data) {
                  
                    if (data.action !== 'reject') return false;
                  
                    if (connection.notes.auth_user) {
                  Severity: Minor
                  Found in index.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 {
                      data,
                      'log' : this.get_clean(data, connection),
                    };
                  Severity: Major
                  Found in index.js - About 30 mins to fix

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

                    exports.hook_data_post = function (next, connection) {
                      const plugin = this;
                    
                      if (!connection.transaction) return next();
                      if (!plugin.should_check(connection)) return next();
                    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