nanoexpress/middlewares

View on GitHub

Showing 19 of 24 total issues

Function swaggerUiFrontend has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function swaggerUiFrontend(config = {}) {
  if (config.title === undefined) {
    config.title = 'nanoexpress - Swagger UI';
  }
  if (config.path === undefined) {
Severity: Major
Found in packages/swagger-ui/swagger-ui.es.js - About 3 hrs to fix

    Function swaggerUiFrontendHandler has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      return async function swaggerUiFrontendHandler(req, res) {
        if (config.url === undefined) {
          config.url = `//${
            req.headers !== undefined ? req.headers.host : req.getHeader('host')
          }/docs/swagger.json`;
    Severity: Major
    Found in packages/swagger-ui/swagger-ui.es.js - About 2 hrs to fix

      Function fileUpload has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function fileUpload(config = { limit: '256mb' }) {
        const FILE_SIZE_LIMIT = sizeConvert(config.limit);
        return async function fileUploadHandler(req, res) {
          const contentType =
            (req.headers && req.headers['content-type']) ||
      Severity: Minor
      Found in packages/file-upload/file-upload.es.js - 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 load has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function load(
        swaggerObject,
        config,
        ajvConfig = {
          removeAdditional: 'all',
      Severity: Minor
      Found in packages/schemator/methods/load.js - 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 bodyParser has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function bodyParser(config = {}) {
        return async function bodyParseHandler(req) {
          const { headers, body } = req;
      
          if (headers && body) {
      Severity: Minor
      Found in packages/body-parser/body-parser.es.js - 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 graphql has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function graphql(schema, root) {
        const cache = {};
        // eslint-disable-next-line @typescript-eslint/naming-convention
        const jitOptions = { customJSONSerializer: true };
        return async function graphqlHandler(req, res) {
      Severity: Minor
      Found in packages/graphql/graphql.es.js - 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 redoc has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export default function redoc(config = {}) {
        config = {
          title: 'nanoexpress - ReDoc',
          path: '/docs/',
          ...config
      Severity: Major
      Found in packages/redoc/redoc.es.js - About 2 hrs to fix

        Function staticMiddleware has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function staticMiddleware(path, config) {
          // Reduce risk of importing files out-of-folder
          if (path.length > 4 && path.charAt(path.length) !== '/') {
            path += '/';
          }
        Severity: Minor
        Found in packages/static/cacheable.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

        Function graphql has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function graphql(schema, root) {
          const cache = {};
          // eslint-disable-next-line @typescript-eslint/naming-convention
          const jitOptions = { customJSONSerializer: true };
          return async function graphqlHandler(req, res) {
        Severity: Minor
        Found in packages/graphql/graphql.es.js - About 1 hr to fix

          Function redocHandler has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            return async function redocHandler(req, res) {
              if (config.url === undefined) {
                config.url = `http://${
                  req.headers ? req.headers.origin : req.getHeader('host')
                }/docs/swagger.json`;
          Severity: Minor
          Found in packages/redoc/redoc.es.js - About 1 hr to fix

            Function fileUploadHandler has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              return async function fileUploadHandler(req, res) {
                const contentType =
                  (req.headers && req.headers['content-type']) ||
                  req.getHeader('content-type');
                const contentLength =
            Severity: Minor
            Found in packages/file-upload/file-upload.es.js - About 1 hr to fix

              Function graphqlHandler has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                return async function graphqlHandler(req, res) {
                  const { headers, body } = req;
              
                  if (headers && body) {
                    const contentType = headers['content-type'];
              Severity: Minor
              Found in packages/graphql/graphql.es.js - About 1 hr to fix

                Function swaggerUiFrontend has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                export default function swaggerUiFrontend(config = {}) {
                  if (config.title === undefined) {
                    config.title = 'nanoexpress - Swagger UI';
                  }
                  if (config.path === undefined) {
                Severity: Minor
                Found in packages/swagger-ui/swagger-ui.es.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

                Function sizeConvert has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export default function sizeConvert(size) {
                  let divideRatio = 1;
                
                  switch (size.toLowerCase().substr(-2)) {
                    case 'kb': {
                Severity: Minor
                Found in packages/file-upload/utils/size-converts.js - About 1 hr to fix

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

                  const importize = ({ path: _path, raw }, directory) => {
                    if (path && !raw) {
                      const resolveFile = path.join(directory.substring(1), _path);
                  
                      const readBuffer = fs.readFileSync(resolveFile, 'utf-8');
                  Severity: Minor
                  Found in packages/schemator/utils/importize.js - 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

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

                  export default function staticMiddleware(path, config) {
                    // eslint-disable-next-line consistent-return
                    return async function handleServe(req, res) {
                      if (!res[resAbortHandler]) {
                        res.onAborted(() => {
                  Severity: Minor
                  Found in packages/static/live.js - 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

                  Consider simplifying this complex logical expression.
                  Open

                    if (enableSmartFunctions && compiledJson && !this._serialized) {
                      this._route._middlewares.push(async (req, res) => {
                        const bodyContentType = req.headers['content-type'] || 'application/json';
                        const responseContentType = req.headers.accept || bodyContentType;
                  
                  
                  Severity: Major
                  Found in packages/schemator/methods/load.js - About 40 mins to fix

                    Function redoc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export default function redoc(config = {}) {
                      config = {
                        title: 'nanoexpress - ReDoc',
                        path: '/docs/',
                        ...config
                    Severity: Minor
                    Found in packages/redoc/redoc.es.js - About 35 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

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

                    export default function formidable(config, initialize) {
                      const form = Formidable(config ?? { multiples: true });
                      if (typeof initialize === 'function') {
                        initialize(form);
                      }
                    Severity: Minor
                    Found in packages/formidable/formidable.es.js - 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