tkrotoff/throw-on

View on GitHub
src/util/format.ts

Summary

Maintainability
D
2 days
Test Coverage
A
100%

Function format has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

export function format(str?: any, ...values: any[]) {
  if (typeof str !== 'string') {
    return (str === undefined ? values : [str, ...values])
      .map(value => (typeof value === 'string' ? value : inspect(value)))
      .join(' ');
Severity: Minor
Found in src/util/format.ts - About 7 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 format has 100 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function format(str?: any, ...values: any[]) {
  if (typeof str !== 'string') {
    return (str === undefined ? values : [str, ...values])
      .map(value => (typeof value === 'string' ? value : inspect(value)))
      .join(' ');
Severity: Major
Found in src/util/format.ts - About 4 hrs to fix

    Function o has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        .replace(/%[%sdifjoOc]/g, match => {
          if (match === '%%') return '%';
    
          if (nbSpecifiers >= values.length) return match;
    
    
    Severity: Major
    Found in src/util/format.ts - About 3 hrs to fix

      Avoid too many return statements within this function.
      Open

                    return String(value);
      Severity: Major
      Found in src/util/format.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return Number.NaN.toString();
        Severity: Major
        Found in src/util/format.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                        return '[Circular]';
          Severity: Major
          Found in src/util/format.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return Number.NaN.toString();
            Severity: Major
            Found in src/util/format.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return Number.parseFloat(value).toString();
              Severity: Major
              Found in src/util/format.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return Number.parseInt(value, 10).toString();
                Severity: Major
                Found in src/util/format.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return JSON.stringify(value);
                  Severity: Major
                  Found in src/util/format.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return Number.NaN.toString();
                    Severity: Major
                    Found in src/util/format.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return inspect(value);
                      Severity: Major
                      Found in src/util/format.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return '';
                        Severity: Major
                        Found in src/util/format.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return Number(value).toString();
                          Severity: Major
                          Found in src/util/format.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                          return `${value}n`;
                            Severity: Major
                            Found in src/util/format.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                            return `${value}n`;
                              Severity: Major
                              Found in src/util/format.ts - About 30 mins to fix

                                There are no issues that match your filters.

                                Category
                                Status