"Replace User with a constructor function."


I am having an issue with SonarQube, and I was hoping someone might be able to help me troubleshoot it.

Here is a brief description of the problem:

I am trying to create a new document in Mongoose, but SonarQube is giving me the error “Replace User with a constructor function.” I have already defined the User object as a constructor function using the mongoose.model() function, but the error persists.

Here is the relevant code snippet:

const testData = {
profileImage: { picture }
const testSonarQube = new User(testData);

Here is some additional information that might be helpful in troubleshooting the issue:

  • Sonar Cloud Scan Version: sonarcloud-scan:1.4.0
  • sonarcloud-quality-gate:0.1.6
  • Programming language: js
  • Error message: “Replace User with a constructor function.”

I would really appreciate any help or advice that anyone might be able to offer. Thank you in advance for your assistance!

Best regards,
Ayadi Tahar

Thanks for reporting this false-positive!

Since all the necessary information has been included, we’ve flagged this for attention by an expert. This means that somebody will look at your report, maybe ask some follow-up questions, and try and determine if it’s really a false-positive that should be fixed.

This review could be done hours, days, or even weeks from now. If it takes a while – it doesn’t mean your report isn’t important to us, it just means that our teams are already hard-at-work developing new language analysis features, and your report is in the queue.

If you’re using SonarQube or SonarCloud – an issue administrator can always mark an issue as a false-positive in the UI (this also suppresses it in SonarLint when using Connected Mode). The rule can also be disabled in your Quality Profile if it’s particularly noisy.

1 Like

Hello @Tahar_AYADI,

thanks for reporting this. Indeed mongoose.model is not a case the JS engine considers for that rule. I have created a ticket to implement it.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.