lorenzopicoli/node-api-starter

View on GitHub

Showing 5 of 5 total issues

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

export async function authFacebook(ctx, next) {
  const authFunction = passport.authenticate('facebook-token', async (err, info) => {
    if (!info || !info.profile) {
      if (err && err.message === 'You should provide access_token') ctx.throw(400, err.message)

Severity: Minor
Found in src/modules/auth/controller.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 authFacebook has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function authFacebook(ctx, next) {
  const authFunction = passport.authenticate('facebook-token', async (err, info) => {
    if (!info || !info.profile) {
      if (err && err.message === 'You should provide access_token') ctx.throw(400, err.message)

Severity: Minor
Found in src/modules/auth/controller.js - About 1 hr to fix

    Function seed has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.seed = (knex, Promise) => {
      const bcrypt = Promise.promisifyAll(require('bcrypt'))
    
      return bcrypt.genSaltAsync(10)
        .then(salt => bcrypt.hashAsync('123', salt))
    Severity: Minor
    Found in seeds/development/users.js - About 1 hr to fix

      Function get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export async function get(ctx, next) {
        try {
          const user = await User.where('id', ctx.params.id).fetch({
            require: true
            // withRelated: ['blablabla']
      Severity: Minor
      Found in src/modules/users/controller.js - About 45 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

      Redundant use of await on a return value.
      Open

                return await lastHandler(ctx)
      Severity: Minor
      Found in src/modules/index.js by eslint

      Disallows unnecessary return await (no-return-await)

      Inside an async function, return await is useless. Since the return value of an async function is always wrapped in Promise.resolve, return await doesn't actually do anything except add extra time before the overarching Promise resolves or rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of async functions.

      Rule Details

      This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function.

      The following patterns are considered warnings:

      async function foo() {
        return await bar();
      }

      The following patterns are not warnings:

      async function foo() {
        return bar();
      }
      
      async function foo() {
        await bar();
        return;
      }
      
      async function foo() {
        const x = await bar();
        return x;
      }

      When Not To Use It

      If you want to use await to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding return await, you can turn off this rule.

      Further Reading

      async function on MDN Source: http://eslint.org/docs/rules/

      Severity
      Category
      Status
      Source
      Language