简体   繁体   English

SonarQube - 帮助创建新的语言插件

[英]SonarQube - help in creating a new language plugin

I am creating a new plugin for SonarQube which allows developers to perform static code analysis on ESQL code. 我正在为SonarQube创建一个新插件,允许开发人员对ESQL代码执行静态代码分析。

Using Maven I can build a shell of a plugin, which produces the JAR file which I can place in the correct folder in order for it to be added to SonarQube. 使用Maven我可以构建一个插件的shell,它生成JAR文件,我可以放在正确的文件夹中,以便将它添加到SonarQube。

The next stage is to write the Java classes for the rules, however I am unsure on what and where these look like. 下一步是为规则编写Java类,但我不确定它们的外观和位置。 I am using the example from the following GIT repository: https://github.com/SonarSource/sonar-examples/tree/master/plugins/sonar-reference-plugin 我正在使用以下GIT存储库中的示例: https//github.com/SonarSource/sonar-examples/tree/master/plugins/sonar-reference-plugin

Do I simply create a new package with some classes? 我只是创建一个包含一些类的新包吗? And how do I actually rules? 我怎么实际规则?

If you want to write a rule engine for the ESQL language, this means that you must first write a parser for this language. 如果要为ESQL语言编写规则引擎,这意味着您必须首先为此语言编写解析器。 And only after you completed this stage, you will create a rule engine based on that parser (with visitor classes that navigate through the AST and that create issues under specific circumstances). 只有在完成此阶段后,您才会创建一个基于该解析器的规则引擎(具有导航AST并在特定情况下创建问题的访问者类)。

You can take a look at how we implemented the Javascript plugin ( see the code of version 1.3 ): 您可以看看我们如何实现Javascript插件( 请参阅版本1.3的代码 ):

  • the "javascript-squid" module is where the parser is written “javascript-squid”模块是编写解析器的地方
  • the "javascript-checks" module is where the rule engine (based on the parser) is written “javascript-checks”模块是编写规则引擎(基于解析器)的地方
  • the "sonar-javascript-plugin" module is the actual plugin, which embeds the parser and the rule engine and which provides all the required glue around them. “sonar-javascript-plugin”模块是实际的插件,它嵌入了解析器和规则引擎,并提供了所有必需的粘合剂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM