EQuimper/nodejs-api-boilerplate

View on GitHub

Showing 69 of 69 total issues

Function logErrorService has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function logErrorService(err, req, res, next) {
  if (!err) {
    return new APIError(
      'Error with the server!',
      HTTPStatus.INTERNAL_SERVER_ERROR,
Severity: Minor
Found in src/services/log.js - About 1 hr to fix

    Function logErrorService has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function logErrorService(err, req, res, next) {
      if (!err) {
        return new APIError(
          'Error with the server!',
          HTTPStatus.INTERNAL_SERVER_ERROR,
    Severity: Minor
    Found in src/services/log.js - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

        if (post.author.toString() !== req.user._id.toString()) {
          return res.sendStatus(HTTPStatus.UNAUTHORIZED);
        }
    Severity: Minor
    Found in src/controllers/post.controller.js and 1 other location - About 50 mins to fix
    src/controllers/post.controller.js on lines 267..269

    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

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

        if (post.author.toString() !== req.user._id.toString()) {
          return res.sendStatus(HTTPStatus.UNAUTHORIZED);
        }
    Severity: Minor
    Found in src/controllers/post.controller.js and 1 other location - About 50 mins to fix
    src/controllers/post.controller.js on lines 328..330

    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

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

      before(async () => {
        await User.remove();
        testUser = await User.create(UserFactory.generate());
      });
    Severity: Minor
    Found in __tests__/routes/users/user.create.test.js and 1 other location - About 40 mins to fix
    __tests__/routes/auth/auth.login.test.js on lines 15..18

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

    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

      before(async () => {
        await User.remove();
        testUser = await User.create(UserFactory.generate());
      });
    Severity: Minor
    Found in __tests__/routes/auth/auth.login.test.js and 1 other location - About 40 mins to fix
    __tests__/routes/users/user.create.test.js on lines 12..15

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

    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

          server
            .post(`${ENDPOINT}/${testPost._id}/favorite`)
            .set('Authorization', `JWT 123`)
            .end((err, res) => {
              const { status } = res;
    Severity: Minor
    Found in __tests__/routes/posts/post.favorites.test.js and 1 other location - About 35 mins to fix
    __tests__/routes/posts/post.delete.test.js on lines 32..39

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

    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

          server
            .delete(`${ENDPOINT}/${testPost._id}`)
            .set('Authorization', `JWT ${testUser.createToken()}`)
            .end((err, res) => {
              const { status } = res;
    Severity: Minor
    Found in __tests__/routes/posts/post.delete.test.js and 1 other location - About 35 mins to fix
    __tests__/routes/posts/post.favorites.test.js on lines 41..48

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

    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

    try {
      Post = mongoose.model('Post');
    } catch (e) {
      Post = mongoose.model('Post', PostSchema);
    }
    Severity: Minor
    Found in src/models/post.model.js and 1 other location - About 30 mins to fix
    src/models/user.model.js on lines 179..183

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

    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

    try {
      User = mongoose.model('User');
    } catch (e) {
      User = mongoose.model('User', UserSchema);
    }
    Severity: Minor
    Found in src/models/user.model.js and 1 other location - About 30 mins to fix
    src/models/post.model.js on lines 118..122

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

    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

    Parsing error: The keyword 'import' is reserved
    Open

    import { Router } from 'express';
    Severity: Minor
    Found in src/routes/user.routes.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import passport from 'passport';
    Severity: Minor
    Found in src/services/auth.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'const' is reserved
    Open

    const nodeExternals = require('webpack-node-externals');
    Severity: Minor
    Found in webpack.config.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import { expect } from 'chai';

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import Joi from 'joi';
    Severity: Minor
    Found in src/controllers/user.controller.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import supertest from 'supertest';
    Severity: Minor
    Found in __mocks__/utils/server.mock.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import faker from 'faker';
    Severity: Minor
    Found in __mocks__/factories/post.factory.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import { expect } from 'chai';
    Severity: Minor
    Found in __tests__/utils/filteredBody.test.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import mongoose from 'mongoose';
    Severity: Minor
    Found in src/config/database.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Parsing error: The keyword 'import' is reserved
    Open

    import httpStatus from 'http-status';
    Severity: Minor
    Found in src/services/error.js by eslint

    For more information visit Source: http://eslint.org/docs/rules/

    Severity
    Category
    Status
    Source
    Language