ArzDigitalLabs/reduce-precision

View on GitHub

Showing 7 of 15 total issues

Function reducePrecision has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
Open

  private reducePrecision(
    numberString: string,
    precision = 30,
    nonZeroDigits = 4,
    round = false,
Severity: Minor
Found in src/format/index.ts - 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

File index.ts has 483 lines of code (exceeds 250 allowed). Consider refactoring.
Open

type Template = 'number' | 'usd' | 'irt' | 'irr' | 'percent';
type Precision = 'auto' | 'high' | 'medium' | 'low';
type Language = 'en' | 'fa';
type OutputFormat = 'plain' | 'html' | 'markdown';

Severity: Minor
Found in src/format/index.ts - About 7 hrs to fix

Function format has 188 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private format(input: string | number): FormattedObject {
    let { precision, template } = this.options;

    const {
      language,
Severity: Major
Found in src/format/index.ts - About 7 hrs to fix

Function reducePrecision has 183 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private reducePrecision(
    numberString: string,
    precision = 30,
    nonZeroDigits = 4,
    round = false,
Severity: Major
Found in src/format/index.ts - About 7 hrs to fix

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

  private format(input: string | number): FormattedObject {
    let { precision, template } = this.options;

    const {
      language,
Severity: Minor
Found in src/format/index.ts - About 6 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

Avoid deeply nested control flow statements.
Open

            if (fractionalZeroStr.length > 0) {
              fractionalZeroStr = fractionalZeroStr.substring(
                0,
                fractionalZeroStr.length - 1
              );
Severity: Major
Found in src/format/index.ts - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

      if (language === 'en') {
        unitPostfix += '%';
      } else {
        unitPostfix += !unitPostfix ? '٪' : ' درصد';
      }
Severity: Major
Found in src/format/index.ts - About 45 mins to fix
Severity
Category
Status
Source
Language