Javascript rule extension

64 views
Skip to first unread message

Skynet

unread,
Jan 31, 2018, 8:17:00 AM1/31/18
to SonarQube

I am trying to extend Sonarqube with custom Javascript rules. I find that the documentation is fairly limited on this subject. The extension tutorials on sonarqube website show only the most basic stuff.


The only javadoc I could find is this one: http://javadocs.sonarsource.org/latest/apidocs/ and it doesn't cover anything about extending Javascript.


What I ultimately want to do is add a JS rule that will check for hardcoded secrets (such as passwords, api keys, etc). I already created one for Java, and that was a lot easier as I could take an already pre-made plugin and complete it with my custom regex.


The problematic spot that made me post here was actually this one:

cannot find symbol
symbol:   class VariableTree
location: package org.sonar.plugins.javascript.api.tree.expression


I was following the same scheme as with Java and used import org.sonar.plugins.javascript.api.tree.expression.VariableTree; which is obviously wrong. I was not able to find the source code for this either... if anybody can point me to some secret doc stash or at least where I can find a javadoc for org.sonar.plugins.javascript.api


Thank you

Elena Vilchik

unread,
Jan 31, 2018, 11:30:25 AM1/31/18
to SonarQube
Hi,

Here is a doc about writing custom rules for SonarJS https://github.com/SonarSource/SonarJS/blob/master/docs/CUSTOM_RULES.md
Don't hesitate to have a look at plugin core rules to understand how to do one or another https://github.com/SonarSource/SonarJS/tree/master/javascript-checks/src/main/java/org/sonar/javascript/checks

Skynet

unread,
Jan 31, 2018, 11:56:06 AM1/31/18
to SonarQube
Thanks for your reply Elena, that's what I've been doing so far - reading the source code.. so I was just wondering if there is a doc for it.

Could you please advise if it's possible to create XPath rules (instead of a plugin) for JS in SQ?

Cheers

Elena Vilchik

unread,
Feb 1, 2018, 4:19:49 AM2/1/18
to Skynet, SonarQube
No, it's not possible to write an XPath rule for JS

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/Lgv92qYszKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/44feaedf-d160-4371-b143-b3cb982b5611%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Elena Vilchik | 
SonarSource
Language Team
Reply all
Reply to author
Forward
0 new messages