holidayextras/jsonapi-server

View on GitHub

Showing 94 of 94 total issues

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

      (sanitisedData, callback) => {
        sanitisedData = sanitisedData.relationships[request.params.relation].data
        response = responseHelper._generateResponse(request, resourceConfig, sanitisedData)
        postProcess.handle(request, response, callback)
      }
Severity: Major
Found in lib/routes/updateRelation.js and 2 other locations - About 1 hr to fix
lib/routes/addRelation.js on lines 59..63
lib/routes/removeRelation.js on lines 88..92

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

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

      (sanitisedData, callback) => {
        sanitisedData = sanitisedData.relationships[request.params.relation].data
        response = responseHelper._generateResponse(request, resourceConfig, sanitisedData)
        postProcess.handle(request, response, callback)
      }
Severity: Major
Found in lib/routes/removeRelation.js and 2 other locations - About 1 hr to fix
lib/routes/addRelation.js on lines 59..63
lib/routes/updateRelation.js on lines 56..60

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

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

      (sanitisedData, callback) => {
        sanitisedData = sanitisedData.relationships[request.params.relation].data
        response = responseHelper._generateResponse(request, resourceConfig, sanitisedData)
        postProcess.handle(request, response, callback)
      }
Severity: Major
Found in lib/routes/addRelation.js and 2 other locations - About 1 hr to fix
lib/routes/removeRelation.js on lines 88..92
lib/routes/updateRelation.js on lines 56..60

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

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 (resourceConfig.handlers.update) {
    specificPaths.patch = swaggerPaths._getPathOperationObject({
      handler: 'update',
      resourceName,
      description: `Update an instance of ${resourceName}`,
Severity: Major
Found in lib/swagger/paths.js and 2 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 65..72
lib/swagger/paths.js on lines 74..81

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 (resourceConfig.handlers.delete) {
    specificPaths.delete = swaggerPaths._getPathOperationObject({
      handler: 'delete',
      resourceName,
      description: `Delete an instance of ${resourceName}`,
Severity: Major
Found in lib/swagger/paths.js and 2 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 65..72
lib/swagger/paths.js on lines 83..90

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 (resourceConfig.handlers.find) {
    specificPaths.get = swaggerPaths._getPathOperationObject({
      handler: 'find',
      resourceName,
      description: `Get a specific instance of ${resourceName}`,
Severity: Major
Found in lib/swagger/paths.js and 2 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 74..81
lib/swagger/paths.js on lines 83..90

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 generatePageLinks has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

pagination.generatePageLinks = (request, handlerTotal) => {
  const pageData = request.params.page
  if (!handlerTotal || !pageData) {
    return { }
  }
Severity: Minor
Found in lib/pagination.js - About 1 hr to fix

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

    filter.parseAndValidate = request => {
      if (!request.params.filter) return null
    
      const resourceConfig = request.resourceConfig
    
    
    Severity: Minor
    Found in lib/filter.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 simpleAttribute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    joiConverter.simpleAttribute = joiScheme => {
      let type = joiScheme._type
      if (type === 'any') {
        // { _valids: { _set: [ 'M', 'F' ] } }
        type = typeof (joiScheme._valids._set || [ ])[0]
    Severity: Minor
    Found in lib/graphQl/joiConverter.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

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

      if (!theResource) {
        return callback({ // eslint-disable-line standard/no-callback-literal
          status: '404',
          code: 'ENOTFOUND',
          title: 'Requested resource does not exist',
    Severity: Major
    Found in lib/MemoryHandler.js and 1 other location - About 1 hr to fix
    lib/MemoryHandler.js on lines 68..75

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

    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 route has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    rerouter.route = (newRequest, callback) => {
      const validRoutes = router._routes[newRequest.method.toLowerCase()]
    
      const path = rerouter._generateSanePath(newRequest)
      const route = rerouter._pickFirstMatchingRoute(validRoutes, path)
    Severity: Minor
    Found in lib/rerouter.js - About 1 hr to fix

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

        if (index !== -1) {
          return callback({ // eslint-disable-line standard/no-callback-literal
            status: '403',
            code: 'EFORBIDDEN',
            title: 'Requested resource already exists',
      Severity: Major
      Found in lib/MemoryHandler.js and 1 other location - About 1 hr to fix
      lib/MemoryHandler.js on lines 49..56

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

      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 _getParams has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      router._getParams = req => {
        let urlParts = req.url.split(jsonApi._apiConfig.base)
        urlParts.shift()
        urlParts = urlParts.join(jsonApi._apiConfig.base).split('?')
      
      
      Severity: Minor
      Found in lib/router.js - About 1 hr to fix

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

            if (!resourceAttribute) {
              return validationErrors.push({
                status: '403',
                code: 'EFORBIDDEN',
                title: 'Invalid inclusion',
        Severity: Major
        Found in lib/postProcessing/include.js and 1 other location - About 1 hr to fix
        lib/postProcessing/include.js on lines 64..71

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

        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 (!resourceAttribute) {
              return validationErrors.push({
                status: '403',
                code: 'EFORBIDDEN',
                title: 'Invalid inclusion',
        Severity: Major
        Found in lib/postProcessing/include.js and 1 other location - About 1 hr to fix
        lib/postProcessing/include.js on lines 55..62

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

        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 action has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        fields.action = (request, response, callback) => {
          const resourceList = request.params.fields
          if (!resourceList || !(resourceList instanceof Object)) return callback()
        
          const allDataItems = response.included.concat(response.data)
        Severity: Minor
        Found in lib/postProcessing/fields.js - About 1 hr to fix

          Function generateWriteSchema has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          jsonApiGraphQL.generateWriteSchema = (allReadTypes, allResourceConfig, allWriteTypes) => {
            const result = { }
          
            Object.keys(allResourceConfig).forEach(resource => {
              const resourceConfig = allResourceConfig[resource]
          Severity: Minor
          Found in lib/graphQl/index.js - About 1 hr to fix

            Function verifyRequest has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            helper.verifyRequest = (request, resourceConfig, res, handlerRequest, callback) => {
              if (!resourceConfig) {
                return helper.handleError(request, res, {
                  status: '404',
                  code: 'ENOTFOUND',
            Severity: Minor
            Found in lib/routes/helper.js - About 1 hr to fix

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

                  {
                    id: 'fbaefe1b-8b80-42c2-b17c-0c397e5b7a0b',
                    type: 'tuples',
                    media: [
                      { type: 'articles', id: 'fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5' },
              Severity: Major
              Found in example/resources/tuples.js and 1 other location - About 1 hr to fix
              example/resources/tuples.js on lines 26..34

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

              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

                  {
                    id: '53e4151d-d47d-4188-be22-2b3a290f6690',
                    type: 'tuples',
                    media: [
                      { type: 'articles', id: 'd850ea75-4427-4f81-8595-039990aeede5' },
              Severity: Major
              Found in example/resources/tuples.js and 1 other location - About 1 hr to fix
              example/resources/tuples.js on lines 17..25

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

              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