nanoexpress/middlewares

View on GitHub

Showing 24 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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    if (prepareCookiesValidator && req.cookies) {
                      if (!prepareCookiesValidator(req.cookies)) {
                        if (!errors) {
                          errors = {};
                        }
                Severity: Major
                Found in packages/schemator/methods/load.js and 2 other locations - About 1 hr to fix
                packages/schemator/methods/load.js on lines 135..142
                packages/schemator/methods/load.js on lines 151..159

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 64.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    if (prepareQueriesValidator && req.query) {
                      if (!prepareQueriesValidator(req.query)) {
                        if (!errors) {
                          errors = {};
                        }
                Severity: Major
                Found in packages/schemator/methods/load.js and 2 other locations - About 1 hr to fix
                packages/schemator/methods/load.js on lines 151..159
                packages/schemator/methods/load.js on lines 160..167

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 64.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    if (prepareHeadersValidator && req.headers) {
                      if (!prepareHeadersValidator(req.headers)) {
                        if (!errors) {
                          errors = {};
                        }
                Severity: Major
                Found in packages/schemator/methods/load.js and 2 other locations - About 1 hr to fix
                packages/schemator/methods/load.js on lines 135..142
                packages/schemator/methods/load.js on lines 160..167

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 64.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                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

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      if (req.path === config.path) {
                        return res.end(`
                        <!-- HTML for static distribution bundle build -->
                  <!DOCTYPE html>
                  <html lang="en">
                  Severity: Minor
                  Found in packages/swagger-ui/swagger-ui.es.js and 1 other location - About 50 mins to fix
                  packages/redoc/redoc.es.js on lines 28..67

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 51.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Severity
                  Category
                  Status
                  Source
                  Language