holidayextras/jsonapi-server

View on GitHub

Showing 94 of 94 total issues

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

  if (resourceConfig.handlers.update) {
    relationPaths.post = swaggerPaths._getPathOperationObject({
      description: `Create ${description}`,
      handler: 'create',
      resourceName: relation,
Severity: Major
Found in lib/swagger/paths.js and 3 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 111..120
lib/swagger/paths.js on lines 133..142
lib/swagger/paths.js on lines 144..153

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

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

  if (resourceConfig.handlers.find) {
    relationPaths.get = swaggerPaths._getPathOperationObject({
      description: `Get ${description}`,
      handler: 'find',
      resourceName: relation,
Severity: Major
Found in lib/swagger/paths.js and 3 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 122..131
lib/swagger/paths.js on lines 133..142
lib/swagger/paths.js on lines 144..153

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

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

  if (resourceConfig.handlers.update) {
    relationPaths.delete = swaggerPaths._getPathOperationObject({
      description: `Delete ${description}`,
      handler: 'delete',
      resourceName: relation,
Severity: Major
Found in lib/swagger/paths.js and 3 other locations - About 1 hr to fix
lib/swagger/paths.js on lines 111..120
lib/swagger/paths.js on lines 122..131
lib/swagger/paths.js on lines 133..142

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

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 _filterKeepObject has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

filter._filterKeepObject = (someObject, filters) => {
  for (const filterName in filters) {
    const whitelist = filters[filterName]

    if (someObject.attributes.hasOwnProperty(filterName) || (filterName === 'id')) {
Severity: Minor
Found in lib/postProcessing/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

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

  if (resourceConfig.handlers.search) {
    genericPaths.get = swaggerPaths._getPathOperationObject({
      handler: 'search',
      resourceName,
      description: `Search for ${resourceName}`,
Severity: Major
Found in lib/swagger/paths.js and 1 other location - About 1 hr to fix
lib/swagger/paths.js on lines 55..63

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

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 (resourceConfig.handlers.create) {
    genericPaths.post = swaggerPaths._getPathOperationObject({
      handler: 'create',
      resourceName,
      description: `Create a new instance of ${resourceName}`,
Severity: Major
Found in lib/swagger/paths.js and 1 other location - About 1 hr to fix
lib/swagger/paths.js on lines 45..53

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

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

router.applyMiddleware = () => {
  app = app || jsonApi._apiConfig.router || express()
  app.use((req, res, next) => {
    res.set({
      'Content-Type': 'application/vnd.api+json',
Severity: Minor
Found in lib/router.js - About 1 hr to fix

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

    swaggerPaths._addBasicPaths = (paths, resourceName, resourceConfig) => {
      const genericPaths = { }
      const specificPaths = { }
      paths[`/${resourceName}`] = genericPaths
      paths[`/${resourceName}/{id}`] = specificPaths
    Severity: Minor
    Found in lib/swagger/paths.js - About 1 hr to fix

      Function register has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      searchRoute.register = () => {
        router.bindRoute({
          verb: 'get',
          path: ':type'
        }, (request, resourceConfig, res) => {
      Severity: Minor
      Found in lib/routes/search.js - About 1 hr to fix

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

            result[`create${uName}`] = {
              description: `Create a new ${resourceConfig.resource} resource`,
              args,
              type: allReadTypes[resource],
              resolve: resolvers.create.bind(resolvers, resourceConfig)
        Severity: Major
        Found in lib/graphQl/index.js and 1 other location - About 1 hr to fix
        lib/graphQl/index.js on lines 80..85

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

        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

            result[`update${uName}`] = {
              description: `Update an existing ${resourceConfig.resource} resource`,
              args,
              type: allReadTypes[resource],
              resolve: resolvers.update.bind(resolvers, resourceConfig)
        Severity: Major
        Found in lib/graphQl/index.js and 1 other location - About 1 hr to fix
        lib/graphQl/index.js on lines 73..78

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

        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 a Cognitive Complexity of 14 (exceeds 5 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

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

          const iterate = (text, node, filter) => {
            if (text.length === 0) return null
            const parts = text.split('.')
            const first = parts.shift()
            const rest = parts.join('.')
        Severity: Minor
        Found in lib/postProcessing/include.js - About 1 hr to fix

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

          jsonApi.define = resourceConfig => {
            if (!resourceConfig.resource.match(/^[A-Za-z0-9_]*$/)) {
              throw new Error(`Resource '${resourceConfig.resource}' contains illegal characters!`)
            }
            resourceConfig.namespace = resourceConfig.namespace || 'default'
          Severity: Minor
          Found in lib/jsonApi.js - About 1 hr to fix

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

                type: ourJoi.Joi.any().required().valid(resourceConfig.resource)
                  .description(`Always "${resourceConfig.resource}"`)
                  .example(resourceConfig.resource),
            Severity: Major
            Found in lib/jsonApi.js and 1 other location - About 1 hr to fix
            lib/jsonApi.js on lines 99..101

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

            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

                type: ourJoi.Joi.string().required().valid(resourceConfig.resource)
                  .description(`Always "${resourceConfig.resource}"`)
                  .example(resourceConfig.resource),
            Severity: Major
            Found in lib/jsonApi.js and 1 other location - About 1 hr to fix
            lib/jsonApi.js on lines 78..80

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

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

            findRoute.register = () => {
              router.bindRoute({
                verb: 'get',
                path: ':type/:id'
              }, (request, resourceConfig, res) => {
            Severity: Minor
            Found in lib/routes/find.js - About 1 hr to fix

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

              responseHelper._generateLink = (item, schemaProperty, linkProperty) => {
                const link = {
                  meta: {
                    relation: 'primary',
                    // type: schemaProperty._settings.__many || schemaProperty._settings.__one,
              Severity: Minor
              Found in lib/responseHelper.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 createReadType has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              readTypes.createReadType = (resourceConfig, otherTypes, allUnionTypes) => {
                const someType = {
                  name: resourceConfig.resource,
                  description: resourceConfig.description,
                  args: filterArgs.generate(resourceConfig.resource),
              Severity: Minor
              Found in lib/graphQl/readTypes.js - About 1 hr to fix

                Function _fetchRelatedResources has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                postProcess._fetchRelatedResources = (request, mainResource, callback) => {
                  // Fetch the other objects
                  let dataItems = mainResource[request.params.relation]
                
                  if (!dataItems) return callback(null, [ null ])
                Severity: Minor
                Found in lib/postProcess.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language