Skip to content

How can I add exceptions for code patterns ? #338

Closed
@Igor-Lopes

Description

@Igor-Lopes

Hi,

I have a Node/Express app setup and Code Climate is giving me some duplication issues on files that aren't real duplication issues, since the code is already refactored and I'm only accessing these files.

On the following example I have to access the user model and a response helper lib in order to process the request in my controller. I've loaded these files into my app variable, passed as argument. I don't see how this is a code duplication, since I'm only loading these files and assigning them to variables. Is this a correct behavior ? Is there a way to add code pattern exceptions to ignore such issues ? I'm confused about these issues, I don't see how I can avoid having similar code or another way to access these files.

Here's the code section given as similar to others:

module.exports = (app) => {
  const User = app.models.user
  const responses = app.libs.responses.users
  const controller = {}

And here's the complete code for this file:

const { validationResult } = require('express-validator/check')

module.exports = (app) => {
  const User = app.models.user
  const responses = app.libs.responses.users
  const controller = {}

  controller.getProfile = async (req, res, next) => {
    try {
      validationResult(req).throw()

      let user = await User.findById(req.params.id).lean()

      res.send(responses.getProfile(user))
    } catch (ex) {
      next(ex)
    }
  }

  return controller
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions