msimerson/Haraka

View on GitHub
plugins.js

Summary

Maintainability
F
3 days
Test Coverage

File plugins.js has 488 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
// load all defined plugins

// node built-ins
const fs          = require('fs');
Severity: Minor
Found in plugins.js - About 7 hrs to fix

    Function run_next_hook has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

    plugins.run_next_hook = (hook, object, params) => {
        if (client_disconnected(object) && !is_required_hook(hook)) {
            object.logdebug(`aborting ${hook} hook`);
            return;
        }
    Severity: Minor
    Found in plugins.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 run_next_hook has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    plugins.run_next_hook = (hook, object, params) => {
        if (client_disconnected(object) && !is_required_hook(hook)) {
            object.logdebug(`aborting ${hook} hook`);
            return;
        }
    Severity: Major
    Found in plugins.js - About 3 hrs to fix

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

          function callback (retval, msg) {
              if (timeout_id) clearTimeout(timeout_id);
              object.current_hook = null;
              if (cancelled) return; // This hook has been cancelled
      
      
      Severity: Minor
      Found in plugins.js - About 1 hr to fix

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

        function log_run_item (item, hook, retval, object, params, msg) {
            if (!item) return;
            if (hook === 'log') return;
        
            let log = 'logdebug';
        Severity: Minor
        Found in plugins.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 _compile has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _compile () {
        
                const pp = this.plugin_path;
                const code = this._get_code(pp);
                if (!code) return;
        Severity: Minor
        Found in plugins.js - About 1 hr to fix

          Function load_plugins has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          plugins.load_plugins = override => {
              logger.loginfo('Loading plugins');
              let plugin_list;
              if (override) {
                  if (!Array.isArray(override)) override = [ override ];
          Severity: Minor
          Found in plugins.js - About 1 hr to fix

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

            plugins.run_hooks = (hook, object, params) => {
                if (client_disconnected(object) && !is_required_hook(hook)) {
                    object.logdebug(`aborting ${hook} hook`);
                    return;
                }
            Severity: Minor
            Found in plugins.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 get_denyfn has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function get_denyfn (object, hook, params, retval, msg, respond_method) {
            Severity: Minor
            Found in plugins.js - About 45 mins to fix

              Function log_run_item has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function log_run_item (item, hook, retval, object, params, msg) {
              Severity: Minor
              Found in plugins.js - About 45 mins to fix

                Avoid too many return statements within this function.
                Open

                                return plugins.run_next_hook(hook, object, params);
                Severity: Major
                Found in plugins.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return 0;
                  Severity: Major
                  Found in plugins.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return require(path.join(path.dirname(this.plugin_path), module));
                    Severity: Major
                    Found in plugins.js - About 30 mins to fix

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

                          _get_code (pp) {
                      
                              if (this.hasPackageJson) {
                                  let packageDir = path.dirname(pp);
                                  if (/^win(32|64)/.test(process.platform)) {
                      Severity: Minor
                      Found in plugins.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

                      There are no issues that match your filters.

                      Category
                      Status