0
点赞
收藏
分享

微信扫一扫

Sonar学习笔记-Rule template canot be activated on a Quality profile checkstyle:RegexpSinglelineCheck

RJ_Hwang 2022-05-27 阅读 55

 

Rule template can't be activated on a Quality profile: checkstyle:com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck

​​https://stackoverflow.com/questions/40263382/sonarqube-server-new-quality-profile-checkstyle-rules/43327339​​

​​https://stackoverflow.com/questions/46961374/sonarqube-rule-based-on-defined-regular-expression​​

Does SonarQube have a rule which will scan a files content for a reqular expression and if found during a scan will mark as an issue?

Example: I want a rule which that will scan each file for the word "AcmeProducts" and mark it as "Critical" if found.

Thanks Jason

 

2,01799 silver badges1616 bronze badges

  • 1
    You could write your own coding rule. See​​here​​ – ​​Jeroen Heier​​ Oct 27 '17 at 4:05

 


1

 

I was able to accomplish this by creating a custom rule based on the Comment pattern matcher rule in sonarqube.

​​share​​​  ​​improve this answer​​  follow 

 

2,01799 silver badges1616 bronze badges

  • Thanks for taking the time to come back and answer your own question :) But can you please share how you were able to extract the default rule? I cant figure it out. –​​hiburn8​​ Sep 23 '19 at 13:59

​​add a comment​​


 

I'm not sure if such rule exists. You could implement a custom plugin to provide such rule.

Something that's very close to what you need is the ​​​HasTagSensor​​​​ of the Xoo Plugin, which is not a real plugin, but a sample to demonstrate and test features of the plugin API. The ​​HasTag​​ rule implementation that I linked raises an issue for each occurrence of some configured string (not a regex). Based on this, you could implement a rule that uses a regex parameter instead of a string.


 

I think that what you are looking for is implemented in the sonar checkstyle plugin.

To configure such a rule :

  1. Install the sonar checkstyle plugin. The instructions to follow is given here, on the sonar checkstyle plugin GitHub page :​​https://github.com/checkstyle/sonar-checkstyle​​.
  2. Reboot your sonar instance to make the new plugin available
  3. Configure a new rule, using the following menu sequence :
  • "Quality profile"
  • select the quality profile to modify
  • in the rule list, select "Activate more"
  • in the "repository" section, select "checkstyle" to filter checkstyle's plugin rules
  • select the rule template "Regexp Singleline" and create a new rule base on a regex detecting your prohibited key word.


举报

相关推荐

0 条评论