RocketChat/Rocket.Chat

View on GitHub
packages/base64/src/base64.ts

Summary

Maintainability
C
1 day
Test Coverage

Function decode has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

const decode = (str: string) => {
    let len = Math.floor((str.length * 3) / 4);
    if (str.charAt(str.length - 1) === '=') {
        len--;
        if (str.charAt(str.length - 2) === '=') {
Severity: Minor
Found in packages/base64/src/base64.ts - About 2 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 encode has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const encode = (array: ArrayLike<number> | string) => {
    if (typeof array === 'string') {
        const str = array;
        const binary = newBinary(str.length);
        for (let i = 0; i < str.length; i++) {
Severity: Major
Found in packages/base64/src/base64.ts - About 2 hrs to fix

    Function encode has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    const encode = (array: ArrayLike<number> | string) => {
        if (typeof array === 'string') {
            const str = array;
            const binary = newBinary(str.length);
            for (let i = 0; i < str.length; i++) {
    Severity: Minor
    Found in packages/base64/src/base64.ts - About 2 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 decode has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const decode = (str: string) => {
        let len = Math.floor((str.length * 3) / 4);
        if (str.charAt(str.length - 1) === '=') {
            len--;
            if (str.charAt(str.length - 2) === '=') {
    Severity: Minor
    Found in packages/base64/src/base64.ts - About 1 hr to fix

      There are no issues that match your filters.

      Category
      Status