How to verify a sample SonarJS rule ? (sonar-custom-rules-examples) with sonarqube ?

389 views
Skip to first unread message

Lory Molesky

unread,
May 18, 2017, 6:22:34 PM5/18/17
to sona...@googlegroups.com, lory.m...@oracle.com
Hi,

I'm trying to use your js custom rule example from
https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/javascript-custom-rules
But after I build the plugin + deploy to the server, the sonarqube
reporting url does not seem
to be pickin up the custom rule. (I tested this by running the
sonar-scanner on the src/ dir
in the javascript-custom-rules/ sample).

Here are the details of what I did (on linux):

First, I did this getting started setup:

https://docs.sonarqube.org/display/SONAR/Get+Started+in+Two+Minutes

(this worked perfectly!)

Next, I try to use your javascript-custom-rules example.

Followed this procedure

https://docs.sonarqube.org/display/PLUG/Custom+Rules+for+SonarJS

Copied the javascript-custom-rules

https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/javascript-custom-rules

built it successfully with % mvn clean package,
then copied the javascript-custom-rules-1.0-SNAPSHORT.jar into
sonarqube's extensions/plugins directory.
Looking at the server's web.log seems to deploy properly:

web.log:2017.05.18 15:03:44 INFO
web[][o.s.s.p.ServerPluginRepository] Deploy plugin JavaScript Custom
Rules / 1.0-SNAPSHOT

So it seems like the server is now using this new js custom rule.

So next I want to test this custom rule by running sonar-scanner on some
.js code.
So I create a sonar-project.properties in
sonar-custom-rules-examples-master/javascript-custom-rules/

sonar-project.properties is very simple:

sonar.projectKey=custom-rules:sample
sonar.projectName=Custom Rules
sonar.projectVersion=1.0
sonar.sources=src
sonar.sourceEncoding=UTF-8

Then I run sonar-scanner, then view the results on localhost:9000

However, I don't see any difference in the results whenI use the custom
JS plugin or when I don't use it.
(I'll get 3 errors on forbiddenFunctionUseCheck.js, these seem to be all
from built-in rules)


src/test/resources/checks/forbiddenFunctionUseCheck.js

"foo" does not exist. Change its name or declare it so that its
usage doesn't result in a "ReferenceError".

"bar" does not exist. Change its name or declare it so that its
usage doesn't result in a "ReferenceError".

Replace Obj with a constructor function.

Am I missing a step ?

thanks,

-Lory
Lory Molesky
Oracle


yves.dubo...@sonarsource.com

unread,
May 22, 2017, 4:09:07 AM5/22/17
to SonarQube, lory.m...@oracle.com
Hello Lory,

It looks like you carried out all operations correctly. You just need to activate your custom rule: in the SonarQube GUI, go to tab "Rules", search for your rule, then activate it (you need to be logged in).

Yves Dubois-Pèlerin
SonarSource team
Message has been deleted

agarwal....@gmail.com

unread,
Jan 31, 2018, 11:35:48 AM1/31/18
to SonarQube

I am also having the same issue. I tried going inside the Rules tab and opened the Forbidden Function rule but there is no option to activate. I am attaching screen shot also for the reference. Can you give me a small js file to test on and pics on how to activate. Please help me.

 

G. Ann Campbell

unread,
Jan 31, 2018, 3:06:50 PM1/31/18
to SonarQube
Hi,

From 6.5, built-in quality profiles are no longer editable. You'll need to create a new profile before you can activate your rule.


Ann

P.S. The standard courtesies (Hi, Thanks, ...) are appreciated in this group.
Reply all
Reply to author
Forward
0 new messages