polkadot-js/wasm

View on GitHub

Showing 10 of 37 total issues

Function inflt has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring.
Open

const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
  const noSt = !st || st.i;
  if (!st) st = {};
  // source length
  const sl = dat.length;
Severity: Minor
Found in packages/wasm-util/src/fflate.ts - About 2 days 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 inflt has 112 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
  const noSt = !st || st.i;
  if (!st) st = {};
  // source length
  const sl = dat.length;
Severity: Major
Found in packages/wasm-util/src/fflate.ts - About 4 hrs to fix

    Function hMap has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
      const s = cd.length;
      // index
      let i = 0;
      // u16 "map": index -> # of codes with bit length = index
    Severity: Minor
    Found in packages/wasm-util/src/fflate.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 hMap has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
      const s = cd.length;
      // index
      let i = 0;
      // u16 "map": index -> # of codes with bit length = index
    Severity: Minor
    Found in packages/wasm-util/src/fflate.ts - About 1 hr to fix

      Function createWasmFn has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function createWasmFn <C extends WasmBaseInstance> (root: 'crypto', wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WasmImports) => C)): InitFn<C> {
        return async (wbg: WasmImports): InitPromise<C> => {
          const result: InitResult<C> = {
            error: null,
            type: 'none',
      Severity: Minor
      Found in packages/wasm-bridge/src/init.ts - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  if (noSt) throw 'unexpected EOF';
        Severity: Major
        Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                  if (!noSt && pos + tl * (clb + 7) > tbts) break;
          Severity: Major
          Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    for (let i = 0; i < hcLen; ++i) {
                      // use index map to get real code
                      clt[clim[i]] = bits(dat, pos + i * 3, 7);
                    }
            Severity: Major
            Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      for (let i = 0; i < tl;) {
                        const r = clm[bits(dat, pos, clbmsk)];
                        // bits read
                        pos += r & 15;
                        // symbol
              Severity: Major
              Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

                Function slc has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                const slc = <T extends Uint8Array | Uint16Array | Uint32Array>(v: T, s: number, e?: number): T => {
                  if (s == null || s < 0) s = 0;
                  if (e == null || e > v.length) e = v.length;
                  // can't use .constructor in case user-supplied
                  const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s) as T;
                Severity: Minor
                Found in packages/wasm-util/src/fflate.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

                Severity
                Category
                Status
                Source
                Language