thi-ng/umbrella

View on GitHub
packages/bencode/src/decode.ts

Summary

Maintainability
A
55 mins
Test Coverage

Function decode has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Wontfix

export const decode = (buf: Iterable<number>, utf8 = true) => {
    const iter = buf[Symbol.iterator]();
    const stack = [];
    let i: IteratorResult<number>;
    let x: any;
Severity: Minor
Found in packages/bencode/src/decode.ts - About 4 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 collect has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Wontfix

const collect = (stack: any[], x: any, utf8 = false) => {
    const parent = peek(stack);
    if (!parent) return x;
    if (parent.type === Type.LIST) {
        parent.val.push(utf8 && isArray(x) ? utf8Decode(x) : x);
Severity: Minor
Found in packages/bencode/src/decode.ts - 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

Function readInt has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

const readInt = (iter: Iterator<number>, acc: number, end = Lit.END) => {
    let i: IteratorResult<number>;
    let x: number;
    let isSigned = false;
    while (!(i = iter.next()).done) {
Severity: Minor
Found in packages/bencode/src/decode.ts - About 55 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

Avoid deeply nested control flow statements.
Wontfix

                        if (parent.type === Type.LIST) {
                            (<any[]>parent.val).push(x.val);
                        } else if (parent.type === Type.DICT) {
                            (<any>parent.val)[(<any>parent).key] = x.val;
                            (<any>parent).key = null;
Severity: Major
Found in packages/bencode/src/decode.ts - About 45 mins to fix

Avoid too many return statements within this function.
Wontfix

    return peek(stack).val;
Severity: Major
Found in packages/bencode/src/decode.ts - About 30 mins to fix

Function readFloat has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Wontfix

const readFloat = (iter: Iterator<number>) => {
    let i: IteratorResult<number>;
    let x: number;
    let acc = "";
    while (!(i = iter.next()).done) {
Severity: Minor
Found in packages/bencode/src/decode.ts - 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

There are no issues that match your filters.

Category
Status