hidori/node-json-logger

View on GitHub

Showing 64 of 64 total issues

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

    constructor(options) {
        this.options = Object.create(options || {});
        this.options.timestamp = this.options.timestamp !== false;
        this.options.timezone = this.options.timezone || false;
        this.options.level = (this.options.level || 'debug').toLowerCase();
Severity: Minor
Found in lib/logger.js - About 1 hr to fix

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

    constructor(options) {
        this.options = Object.create(options || {});
        this.options.timestamp = this.options.timestamp !== false;
        this.options.timezone = this.options.timezone || false;
        this.options.level = (this.options.level || 'debug').toLowerCase();
Severity: Minor
Found in lib/logger.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

Delete ······
Open

            if (this.options.timestamp) {
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete ······
Open

            }
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete ······
Open

            }
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ····case·'warn' with };⏎······case·"warn"
Open

            case 'warn':
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete
Open

    }
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ········([head].concat($arguments).concat([head])) with ····[head].concat($arguments).concat([head])
Open

        ([head].concat($arguments).concat([head])).forEach(_ => {
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ············if·(typeof·_·===·'string' with ······if·(typeof·_·===·"string"
Open

            if (typeof _ === 'string') {
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete ········
Open

                Object.assign($object, _);
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ············ with ······
Open

            const data = {};
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ················this.debug·=·function·()·{·this.output('debug',·Array.from(arguments))·} with ········this.debug·=·function()·{⏎··········this.output("debug",·Array.from(arguments))
Open

                this.debug = function () { this.output('debug', Array.from(arguments)) };
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete ····
Open

        let i = 0;
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ············ with ······
Open

            }
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Delete ····
Open

        this.writeln($object);
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ········this.options.level·=·(this.options.level·||·'debug' with ····this.options.level·=·(this.options.level·||·"debug"
Open

        this.options.level = (this.options.level || 'debug').toLowerCase();
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Unexpected console statement.
Open

        this.writeln = $object => console.log(JSON.stringify($object));
Severity: Minor
Found in lib/logger.js by eslint

disallow the use of console (no-console)

In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

console.log("Made it here.");
console.error("That shouldn't have happened.");

Rule Details

This rule disallows calls to methods of the console object.

Examples of incorrect code for this rule:

/*eslint no-console: "error"*/

console.log("Log a debug level message.");
console.warn("Log a warn level message.");
console.error("Log an error level message.");

Examples of correct code for this rule:

/*eslint no-console: "error"*/

// custom console
Console.log("Hello world!");

Options

This rule has an object option for exceptions:

  • "allow" has an array of strings which are allowed methods of the console object

Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] } option:

/*eslint no-console: ["error", { allow: ["warn", "error"] }] */

console.warn("Log a warn level message.");
console.error("Log an error level message.");

When Not To Use It

If you're using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

Related Rules

Expected a 'break' statement before 'case'.
Open

            case 'debug':
Severity: Minor
Found in lib/logger.js by eslint

Disallow Case Statement Fallthrough (no-fallthrough)

The switch statement in JavaScript is one of the more error-prone constructs of the language thanks in part to the ability to "fall through" from one case to the next. For example:

switch(foo) {
    case 1:
        doSomething();

    case 2:
        doSomethingElse();
}

In this example, if foo is 1, then execution will flow through both cases, as the first falls through to the second. You can prevent this by using break, as in this example:

switch(foo) {
    case 1:
        doSomething();
        break;

    case 2:
        doSomethingElse();
}

That works fine when you don't want a fallthrough, but what if the fallthrough is intentional, there is no way to indicate that in the language. It's considered a best practice to always indicate when a fallthrough is intentional using a comment which matches the /falls?\s?through/i regular expression:

switch(foo) {
    case 1:
        doSomething();
        // falls through

    case 2:
        doSomethingElse();
}

switch(foo) {
    case 1:
        doSomething();
        // fall through

    case 2:
        doSomethingElse();
}

switch(foo) {
    case 1:
        doSomething();
        // fallsthrough

    case 2:
        doSomethingElse();
}

In this example, there is no confusion as to the expected behavior. It is clear that the first case is meant to fall through to the second case.

Rule Details

This rule is aimed at eliminating unintentional fallthrough of one case to the other. As such, it flags any fallthrough scenarios that are not marked by a comment.

Examples of incorrect code for this rule:

/*eslint no-fallthrough: "error"*/

switch(foo) {
    case 1:
        doSomething();

    case 2:
        doSomething();
}

Examples of correct code for this rule:

/*eslint no-fallthrough: "error"*/

switch(foo) {
    case 1:
        doSomething();
        break;

    case 2:
        doSomething();
}

function bar(foo) {
    switch(foo) {
        case 1:
            doSomething();
            return;

        case 2:
            doSomething();
    }
}

switch(foo) {
    case 1:
        doSomething();
        throw new Error("Boo!");

    case 2:
        doSomething();
}

switch(foo) {
    case 1:
    case 2:
        doSomething();
}

switch(foo) {
    case 1:
        doSomething();
        // falls through

    case 2:
        doSomething();
}

Note that the last case statement in these examples does not cause a warning because there is nothing to fall through into.

Options

This rule accepts a single options argument:

  • Set the commentPattern option to a regular expression string to change the test for intentional fallthrough comment

commentPattern

Examples of correct code for the { "commentPattern": "break[\\s\\w]*omitted" } option:

/*eslint no-fallthrough: ["error", { "commentPattern": "break[\\s\\w]*omitted" }]*/

switch(foo) {
    case 1:
        doSomething();
        // break omitted

    case 2:
        doSomething();
}

switch(foo) {
    case 1:
        doSomething();
        // caution: break is omitted intentionally

    default:
        doSomething();
}

When Not To Use It

If you don't want to enforce that each case statement should end with a throw, return, break, or comment, then you can safely turn this rule off.

Related Rules

Replace ·····case·'info' with ·};⏎······case·"info"
Open

            case 'info':
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Replace ········ with ····
Open

        });
Severity: Minor
Found in lib/logger.js by eslint

For more information visit Source: http://eslint.org/docs/rules/

Severity
Category
Status
Source
Language