jmeas/api-pls

View on GitHub

Showing 66 of 66 total issues

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

module.exports = {
  outOfBoundsPagination: {
    code: 400,
    body(paramName) {
      return {
Severity: Major
Found in packages/api-pls-utils/server-errors.js and 1 other location - About 1 day to fix
packages/api-pls-express-router/util/server-errors.js on lines 3..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 317.

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

module.exports = {
  outOfBoundsPagination: {
    code: 400,
    body(paramName) {
      return {
Severity: Major
Found in packages/api-pls-express-router/util/server-errors.js and 1 other location - About 1 day to fix
packages/api-pls-utils/server-errors.js on lines 3..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 317.

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

module.exports = async function(req) {
  const pls = req.pls;

  pls.log.info({req}, 'A read request is being processed.');
  const selfLink = req.originalUrl;
Severity: Major
Found in packages/api-pls-postgres-adapter/middleware/read.js - About 6 hrs to fix

    Function exports has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports = async function(req) {
      const pls = req.pls;
    
      pls.log.info({req}, 'A read request is being processed.');
      const selfLink = req.originalUrl;
    Severity: Minor
    Found in packages/api-pls-postgres-adapter/middleware/read.js - About 6 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 exports has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function(options) {
      let confirmation;
    
      if (options.force) {
        confirmation = Promise.resolve({confirmation: true});
    Severity: Major
    Found in packages/api-pls-cli/commands/sync.js - About 3 hrs to fix

      Function generateCreateOrUpdateValidation has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function generateCreateOrUpdateValidation(pluralResourceName, attributes, meta, isCreate) {
        const validation = {
          type: 'object',
          // There must be *something* to update.
          required: ['body'],
      Severity: Major
      Found in packages/api-pls-utils/resource-definition/build-json-schema/index.js - About 2 hrs to fix

        Function exports has 70 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = function(options) {
          const router = express.Router();
          router.use(jsonApiHeaders);
        
          const apiVersion = options.apiVersion;
        Severity: Major
        Found in packages/api-pls-express-router/index.js - About 2 hrs to fix

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

            if (!_.size(columns)) {
              pls.log.info({reqId: req.id}, 'A create request had no columns to update');
              return {
                code: serverErrors.noValidFields.code,
                body: {
          Severity: Major
          Found in packages/api-pls-postgres-adapter/middleware/create.js and 1 other location - About 2 hrs to fix
          packages/api-pls-postgres-adapter/middleware/read.js on lines 64..76

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

          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 (fieldsIsArray && fieldsToReturn.length === 0) {
              pls.log.info({reqId: req.id}, 'A read request specified sparse fields, but provided no valid fields.');
          
              return {
                code: serverErrors.noValidFields.code,
          Severity: Major
          Found in packages/api-pls-postgres-adapter/middleware/read.js and 1 other location - About 2 hrs to fix
          packages/api-pls-postgres-adapter/middleware/create.js on lines 39..50

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

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

          module.exports = async function(req) {
            const pls = req.pls;
          
            pls.log.info({req}, 'A create request is being processed.');
            const selfLinkBase = req.path;
          Severity: Major
          Found in packages/api-pls-postgres-adapter/middleware/create.js - About 2 hrs to fix

            Function exports has 54 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = async function(req) {
              const pls = req.pls;
            
              pls.log.info({req}, 'An update request is being processed.');
              const selfLink = req.path;
            Severity: Major
            Found in packages/api-pls-postgres-adapter/middleware/update.js - About 2 hrs to fix

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

                if (requiredAttrsArray.length) {
                  if (isCreate) {
                    validation.properties.body.properties.data.required.push('attributes');
                  }
                  validation.properties.body.properties.data.properties.attributes.required = requiredAttrsArray;
              packages/api-pls-utils/resource-definition/build-json-schema/index.js on lines 114..119

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

              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 (requiredMetaArray.length) {
                  if (isCreate) {
                    validation.properties.body.properties.data.required.push('meta');
                  }
                  validation.properties.body.properties.data.properties.meta.required = requiredMetaArray;
              packages/api-pls-utils/resource-definition/build-json-schema/index.js on lines 108..113

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

              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 (nextPage) {
                      const nextPageQuery = qs.stringify(_.merge({}, req.query, {page: {number: nextPage}}), {encode: false});
                      nextPageLink = `${basePath}?${nextPageQuery}`;
                    }
              Severity: Major
              Found in packages/api-pls-postgres-adapter/middleware/read.js and 1 other location - About 2 hrs to fix
              packages/api-pls-postgres-adapter/middleware/read.js on lines 208..211

              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 (prevPage) {
                      const prevPageQuery = qs.stringify(_.merge({}, req.query, {page: {number: prevPage}}), {encode: false});
                      prevPageLink = `${basePath}?${prevPageQuery}`;
                    }
              Severity: Major
              Found in packages/api-pls-postgres-adapter/middleware/read.js and 1 other location - About 2 hrs to fix
              packages/api-pls-postgres-adapter/middleware/read.js on lines 214..217

              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 (hasJsonApiType && hasParameters) {
                  log.info({contentTypeObj}, 'Content Type has JSON API content type headers with params.');
                  res.status(serverErrors.contentTypeHasParams.code);
                  return sendJson(res, {
                    errors: [serverErrors.contentTypeHasParams.body()]
              Severity: Major
              Found in packages/api-pls-express-router/util/json-api-headers.js and 1 other location - About 2 hrs to fix
              packages/api-pls-express-router/util/json-api-headers.js on lines 51..57

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

              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 (!acceptsJsonApi) {
                  log.info({req}, 'Request specifies content type, but does not accept the JSON API media type.');
                  res.status(serverErrors.acceptsHasParams.code);
                  return sendJson(res, {
                    errors: [serverErrors.acceptsHasParams.body()]
              Severity: Major
              Found in packages/api-pls-express-router/util/json-api-headers.js and 1 other location - About 2 hrs to fix
              packages/api-pls-express-router/util/json-api-headers.js on lines 41..47

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

              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 (extname === '.yaml' || extname === '.yml') {
                  let result;
                  try {
                    result = yaml.safeLoad(fileContents);
                  } catch (e) {
              Severity: Major
              Found in packages/api-pls-utils/resource-model/load-from-disk.js and 1 other location - About 1 hr to fix
              packages/api-pls-utils/resource-model/load-from-disk.js on lines 38..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 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 2 locations. Consider refactoring.
              Open

                } else {
                  let result;
                  try {
                    result = JSON.parse(fileContents);
                  } catch (e) {
              Severity: Major
              Found in packages/api-pls-utils/resource-model/load-from-disk.js and 1 other location - About 1 hr to fix
              packages/api-pls-utils/resource-model/load-from-disk.js on lines 21..36

              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

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

                const result = await pls.adapter.db.tx(t => {
                  const primaryTableQuery = t.one(query);
                  return t.batch([primaryTableQuery]);
                }).catch(r => r);
              Severity: Major
              Found in packages/api-pls-postgres-adapter/middleware/create.js and 2 other locations - About 1 hr to fix
              packages/api-pls-postgres-adapter/middleware/delete.js on lines 18..21
              packages/api-pls-postgres-adapter/middleware/update.js on lines 57..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 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

              Severity
              Category
              Status
              Source
              Language