guillaumemaka/realworld-starter-kit-hapijs

View on GitHub

Showing 12 of 48 total issues

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

module.exports = (server) => {
  const inputValidations = require('./validations/input')
  const outputValidations = require('./validations/output')
  const fetchArticle = require('./routes_prerequisites').fetchArticle(server)
  const fetchComment = require('./routes_prerequisites').fetchComment(server)
Severity: Major
Found in lib/modules/api/articles/routes.js - About 6 hrs to fix

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

    module.exports = (server) => {
      return {
        /**
         * GET /api/articles
         */
    Severity: Major
    Found in lib/modules/api/articles/handlers.js - About 4 hrs to fix

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

      module.exports = (server) => {
        const replyHelper = require('../helpers')
      
        function constructProfileResponse (user, authenticatedUser = null) {
          let profile = { user: user.toProfileJSONFor(authenticatedUser) }
      Severity: Major
      Found in lib/modules/api/profiles/handlers.js - About 2 hrs to fix

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

        module.exports = (server) => {
          const handlers = require('./handlers')(server)
          return [
            // Get current user
            {
        Severity: Minor
        Found in lib/modules/api/users/routes.js - About 1 hr to fix

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

          module.exports = (server) => {
            function constructUserResponse (user) {
              let authUser = { user: user.toAuthJSON() }
              authUser.user.bio = user.bio || null
              authUser.user.image = user.image || null
          Severity: Minor
          Found in lib/modules/api/users/handlers.js - About 1 hr to fix

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

            module.exports = (server) => {
              const handlers = require('./handlers')(server)
              return [
                // Get /profiles/{username}
                {
            Severity: Minor
            Found in lib/modules/api/profiles/routes.js - About 1 hr to fix

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

              function getArticles (user, query, callback) {
                let mQuery = {}
              
                if (query.tag) {
                  mQuery.tagList = { $in: [ query.tag ] }
              Severity: Minor
              Found in lib/modules/services/articles.js - About 1 hr to fix

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

                const register = (server, options, next) => {
                  const preResponse = (request, reply) => {
                    let response = request.response
                    if (response.isBoom) {
                      const reformated = { errors: {} }
                Severity: Minor
                Found in lib/modules/api/index.js - About 1 hr to fix

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

                  const fetchArticle = server => {
                    return {
                      method: (request, reply) => {
                        if (!request.params.slug) {
                          return reply.continue()
                  Severity: Minor
                  Found in lib/modules/api/articles/routes_prerequisites.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

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

                  const fetchComment = server => {
                    return {
                      method: (request, reply) => {
                        if (!request.params.commentId) {
                          return reply.continue()
                  Severity: Minor
                  Found in lib/modules/api/articles/routes_prerequisites.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

                  Function mongooseResponseValidationErrorHandler has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function mongooseResponseValidationErrorHandler (err) {
                    if (err.name && err.name === 'ValidationError') {
                      let response = {
                        errors: {}
                      }
                  Severity: Minor
                  Found in lib/modules/api/helpers.js - About 35 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

                  Function constructErrorResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  const constructErrorResponse = (err) => {
                    var response
                    for (var handler in errorHandlers) {
                      let handlerFn = errorHandlers[handler]
                      if (typeof (handlerFn) === 'function') {
                  Severity: Minor
                  Found in lib/modules/api/helpers.js - About 25 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

                  Severity
                  Category
                  Status
                  Source
                  Language