SuitestAutomation/suitest-js-api

View on GitHub
lib/utils/logger.js

Summary

Maintainability
F
4 days
Test Coverage
B
84%

Function createLogger has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
Open

const createLogger = (config, pairedDeviceContext) => {
    /**
     * Prefix log with device id
     */
    function devicePrefix() {
Severity: Minor
Found in lib/utils/logger.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 createLogger has 180 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const createLogger = (config, pairedDeviceContext) => {
    /**
     * Prefix log with device id
     */
    function devicePrefix() {
Severity: Major
Found in lib/utils/logger.js - About 7 hrs to fix

    File logger.js has 297 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const colors = require('colors');
    const logLevels = require('../constants/logLevels');
    const jsonRenderer = require('prettyjson');
    const {formatOpType} = require('./opType');
    const timestamp = require('./timestamp');
    Severity: Minor
    Found in lib/utils/logger.js - About 3 hrs to fix

      Function getAppOutput has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              getAppOutput: (subtype, data) => {
                  // No need to display anything
                  if (config.logLevel === logLevels.silent) {
                      return;
                  }
      Severity: Major
      Found in lib/utils/logger.js - About 2 hrs to fix

        Function args has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                    const args = data.map(d => {
                        // If not an array, display as it is.
                        if (!Array.isArray(d)) {
                            return d;
                        }
        Severity: Minor
        Found in lib/utils/logger.js - About 1 hr to fix

          Function createDeviceLogger has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function createDeviceLogger() {
                  let logTime = 0;
          
                  // Create transform stream to prepend our custom prefix to each output new line.
                  const transformStream = new Transform({
          Severity: Minor
          Found in lib/utils/logger.js - About 1 hr to fix

            Avoid too many return statements within this function.
            Open

                            return val1;
            Severity: Major
            Found in lib/utils/logger.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                      return subtype === 'time'
                                          ? `Timer '${val1}' already exists`
                                          : `Timer '${val1}' does not exist`;
              Severity: Major
              Found in lib/utils/logger.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return `${val1}: ${val2}`;
                Severity: Major
                Found in lib/utils/logger.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                      return `${val1}: ${val2}ms`;
                  Severity: Major
                  Found in lib/utils/logger.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                            return `Count for '${val1}' does not exist`;
                    Severity: Major
                    Found in lib/utils/logger.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                          return val1.join('\n');
                      Severity: Major
                      Found in lib/utils/logger.js - About 30 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status