FP javascript:S2999 on new this() in static methods

I’m not entirely sure if it’s a FP or if I’m just doing it wrong, but the following code triggers S2999 (“new” operators should be used with functions):

class Example {
  static createInstance() {
    return new this();


Is this on SonarQube (if so, what version of SonarQube and SonarJS)? SonarCloud? SonarLint? Help us help you. :slight_smile:


Hi Colin,

Sorry for not mentioning the environment. The issue is valid for both SonarLint and SonarQube. WebStorm 2019.3 + SonarLint, SonarQube 8.0 CE.

The equivalent code that does not use the class syntax does not trigger the error:

function Example() {


Example.createInstance = function() {
  return new this();


Thanks for reporting! I created a ticket to fix it: https://github.com/SonarSource/SonarJS/issues/1763

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