How to monitor the use of some custom rules in javascript?

Hi,

with java and php custom rules, I can monitor if these rules are added or not to a project custom quality profile, and then I can have stats on the validation/violation of these rules.

How can I do this with javascript when rules can only be written for ES Lint ?

Hi,

I’m not sure you can; this isn’t a need we anticipated. Would you mind sharing your use case?

 
Ann

Sure in my big national “energy-providing” company (50 million lines licence almost reached), we’ve been asked to work on “Green IT” and eco-design around Sonarqube rules. So we’ve created a few additionnal “eco-design” rules for our main languages (java, php and javascript), and now we need to see for each project, how many “eco-design” rule they use, and how they respect them.

Hi,

Thanks for sharing. I’m going to move this to the ‘Suggest new features’ category, since what you’re after doesn’t currently exist.

 
Ann

Well, it actually does exist. It’s just marked as deprecated since Sonarqube 6

I’m talking about SonarJs custom rules which allow all this.

The question, regarding this need, is still why was it considered “deprecated”, and can this “deprecation” (which never transformed into a removing of the feature) be canceled ?

hello @Tristan107 ,

custom rules are deprecated because they were using now removed Java based parser (the feature is really gone). We now use parser based on ESLint. I think we will eventually introduce JS based custom rules, but it’s not on the roadmap right now. You can find some infrastructure for this if you dig in the code, but there are some important pieces still missing.

1 Like

Oh, ok I didn’t know it was already removed.

In https://rules.sonarsource.com/javascript, we can still see many rules, they are done throught ESLint too ? can we do that too, create a rule in ESLint and make it visible in UI like it seems you do ?

The question is indeed why remove the java based parser if it removes rules from UI and make them not visible through quality profiles and APIs :
ESLint may be as good or maybe better in quality/security checking, but it puts javascript behind other languages in term of monitoring rules through Sonarqube UI and APIs.

hello @Tristan107 ,

it seems that my explanation just caused more confusion, sorry for that :slight_smile:

We use ESLint as internal library, not directly. All the rules are now implemented using ESLint internally, some of the rules are just plain ESLint rules, some of them we developed ourselves using ESLint framework (usually the more sofisticated rules with data flow analysis are like this).

Java rules had to be removed because maintaining the parser was too much work and did not add any value. Writing rules for JS in JS will allow us to innovate more.

can we do that too, create a rule in ESLint and make it visible in UI like it seems you do ?

eventually perhaps yes, but for the time being this is not possible