faasjs/faasjs

View on GitHub
packages/http/src/validator.ts

Summary

Maintainability
C
1 day
Test Coverage
A
100%

Function validContent has a Cognitive Complexity of 137 (exceeds 5 allowed). Consider refactoring.
Wontfix

  public validContent(
    type: string,
    params: {
      [key: string]: any
    },
Severity: Minor
Found in packages/http/src/validator.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

File validator.ts has 257 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

import type { Cookie } from './cookie'
import type { Session } from './session'
import type { Logger } from '@faasjs/logger'
import { HttpError } from '.'

Severity: Minor
Found in packages/http/src/validator.ts - About 2 hrs to fix

    Function valid has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Wontfix

      public async valid(
        request: Request<TParams, TCookie, TSession>,
        logger: Logger
      ): Promise<void> {
        if (this.before) {
    Severity: Minor
    Found in packages/http/src/validator.ts - 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.
    Wontfix

                if (res) throw new HttpError(res)
    Severity: Major
    Found in packages/http/src/validator.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                else if (typeof value === 'object')
                  // object
                  this.validContent(
                    type,
                    value,
      Severity: Major
      Found in packages/http/src/validator.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Wontfix

                    if (res) throw new HttpError(res)
        Severity: Major
        Found in packages/http/src/validator.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      for (const val of value)
                        this.validContent(
                          type,
                          val,
                          baseKey ? `${baseKey}.${key}.` : `${key}.`,
          Severity: Major
          Found in packages/http/src/validator.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Wontfix

                        if (!typed) {
                          const error = Error(
                            `[${type}] ${baseKey}${key} must be a ${rule.type}.`
                          )
                          if (config.onError) {
            Severity: Major
            Found in packages/http/src/validator.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          switch (rule.type) {
                            case 'array':
                              typed = Array.isArray(value)
                              break
                            case 'object':
              Severity: Major
              Found in packages/http/src/validator.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Wontfix

                            if (res) throw new HttpError(res)
                Severity: Major
                Found in packages/http/src/validator.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Wontfix

                              if (res) throw new HttpError(res)
                  Severity: Major
                  Found in packages/http/src/validator.ts - About 45 mins to fix

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

                                if (!typed) {
                                  const error = Error(
                                    `[${type}] ${baseKey}${key} must be a ${rule.type}.`
                                  )
                                  if (config.onError) {
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 3 hrs to fix
                    packages/http/src/validator.ts on lines 233..250

                    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 104.

                    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 2 locations. Consider refactoring.
                    Wontfix

                            if (
                              rule.regexp &&
                              (rule.type === 'string' || !rule.type) &&
                              !rule.regexp.test(value)
                            ) {
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 3 hrs to fix
                    packages/http/src/validator.ts on lines 216..229

                    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 104.

                    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

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

                                switch (rule.type) {
                                  case 'array':
                                    typed = Array.isArray(value)
                                    break
                                  case 'object':
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 2 hrs to fix
                    packages/cloud_function/src/validator.ts on lines 117..129

                    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 82.

                    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 2 locations. Consider refactoring.
                    Open

                        if (this.sessionConfig && request.session) {
                          logger.debug('Valid Session')
                          if (request.session == null) throw Error('Not found Session')
                          this.validContent(
                            'session',
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 2 hrs to fix
                    packages/http/src/validator.ts on lines 107..118

                    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 76.

                    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 2 locations. Consider refactoring.
                    Open

                        if (this.cookieConfig && request.cookie) {
                          logger.debug('Valid Cookie')
                          if (request.cookie == null) throw Error('Not found Cookie')
                    
                          this.validContent(
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 2 hrs to fix
                    packages/http/src/validator.ts on lines 120..130

                    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 76.

                    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 2 locations. Consider refactoring.
                    Open

                            if (type === 'cookie' || type === 'session')
                              logger.warn('Cookie and Session not support default rule.')
                            else if (typeof value === 'undefined' && rule.default) {
                              value =
                                typeof rule.default === 'function'
                    Severity: Major
                    Found in packages/http/src/validator.ts and 1 other location - About 1 hr to fix
                    packages/cloud_function/src/validator.ts on lines 90..98

                    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 72.

                    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 2 locations. Consider refactoring.
                    Open

                                  this.validContent(
                                    type,
                                    val,
                                    baseKey ? `${baseKey}.${key}.` : `${key}.`,
                                    rule.config as ValidatorOptions,
                    Severity: Minor
                    Found in packages/http/src/validator.ts and 1 other location - About 50 mins to fix
                    packages/http/src/validator.ts on lines 283..289

                    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 52.

                    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 2 locations. Consider refactoring.
                    Open

                                this.validContent(
                                  type,
                                  value,
                                  baseKey ? `${baseKey}.${key}.` : `${key}.`,
                                  rule.config as ValidatorOptions,
                    Severity: Minor
                    Found in packages/http/src/validator.ts and 1 other location - About 50 mins to fix
                    packages/http/src/validator.ts on lines 274..280

                    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 52.

                    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

                    There are no issues that match your filters.

                    Category
                    Status