tunnckoCore/gibon

View on GitHub
modules/formidable-mini/src/multipart.js

Summary

Maintainability
F
4 days
Test Coverage

Function write has a Cognitive Complexity of 112 (exceeds 5 allowed). Consider refactoring.
Open

  write(data) {
    let i = 0;
    const length_ = data.length;
    let previousIndex = this.index;
    let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
Severity: Minor
Found in modules/formidable-mini/src/multipart.js - 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 write has 197 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  write(data) {
    let i = 0;
    const length_ = data.length;
    let previousIndex = this.index;
    let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
Severity: Major
Found in modules/formidable-mini/src/multipart.js - About 7 hrs to fix

    File multipart.js has 365 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* eslint-disable */
    
    import { FormData } from 'formdata-polyfill/esm.min.js';
    import { FormidableFile } from './FormidableFile.js';
    
    
    Severity: Minor
    Found in modules/formidable-mini/src/multipart.js - About 4 hrs to fix

      Function multipart has 85 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export async function multipart(req, options = {}) {
        const ct = req.headers['content-type'];
      
        if (!/multipart/i.test(ct)) {
          throw new TypeError('Failed to fetch');
      Severity: Major
      Found in modules/formidable-mini/src/multipart.js - About 3 hrs to fix

        Function multipart has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        export async function multipart(req, options = {}) {
          const ct = req.headers['content-type'];
        
          if (!/multipart/i.test(ct)) {
            throw new TypeError('Failed to fetch');
        Severity: Minor
        Found in modules/formidable-mini/src/multipart.js - 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

        Avoid deeply nested control flow statements.
        Open

                    if (c === CR) {
                      // CR = part boundary
                      flags |= F.PART_BOUNDARY;
                    } else if (c === HYPHEN) {
                      // HYPHEN = end boundary
        Severity: Major
        Found in modules/formidable-mini/src/multipart.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
                        state = S.END;
                        flags = 0;
                      } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
                        index = 0;
          Severity: Major
          Found in modules/formidable-mini/src/multipart.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                          if (index === 0) {
                            dataCallback('onPartData', true);
                          }
            Severity: Major
            Found in modules/formidable-mini/src/multipart.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        } else if (index - 1 === boundary.length) {
                          if (flags & F.PART_BOUNDARY) {
                            index = 0;
                            if (c === LF) {
                              // unset the PART_BOUNDARY flag
              Severity: Major
              Found in modules/formidable-mini/src/multipart.js - About 45 mins to fix

                Avoid too many return statements within this function.
                Open

                            return;
                Severity: Major
                Found in modules/formidable-mini/src/multipart.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return;
                  Severity: Major
                  Found in modules/formidable-mini/src/multipart.js - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status