haraka/haraka-plugin-geoip

View on GitHub

Showing 4 of 6 total issues

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

const fs        = require('fs')
const net       = require('net')
const path      = require('path')

const net_utils = require('haraka-net-utils')
Severity: Minor
Found in index.js - About 3 hrs to fix

    Function get_geoip has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
    Open

    exports.get_geoip = function (ip) {
    
      switch (true) {
        case (!ip):
        case (!net.isIPv4(ip) && !net.isIPv6(ip)):
    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 calculate_distance has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

    exports.calculate_distance = function (connection, rll, done) {
      const plugin = this
    
      function cb (err, l_ip) {
        if (err) {
    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 add_headers has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
    Open

    exports.add_headers = function (next, connection) {
      const txn = connection.transaction
      if (!txn) return
    
      txn.remove_header('X-Haraka-GeoIP')
    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