racodond / sonar-gherkin-custom-rules-plugin

Sample plugin that defines SonarQube custom rules for Cucumber Gherkin feature files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sample plugin that defines SonarQube custom rules for Cucumber Gherkin feature files

Build Status AppVeyor Build Status Quality Gate Twitter

Description

The SonarQube Gherkin plugin can be enhanced by writing custom rules through a plugin using SonarQube Gherkin API. This sample plugin is designed to help you get started writing your own plugin and custom rules.

Usage

  1. Download and install SonarQube 5.6 or greater
  2. Install the Gherkin plugin (1.0 or greater) either by a direct download or through the Update Center.
  3. Install this sample plugin by a direct download
  4. Start SonarQube
  5. Activate some of the custom rules implemented in this sample plugin ("Forbidden tag" for example).
  6. Install your favorite analyzer (SonarQube Scanner, Maven, Ant, etc.) and analyze your code. Note that Java 8 is required to run an analysis.
  7. Browse the issues through the web interface

Writing Custom Rules

Creating a SonarQube Plugin

<basePlugin>gherkin</basePlugin>

Implementing a Rule

There are two different ways to browse the AST:

Using DoubleDispatchVisitorCheck

To explore part of the AST, override a method from DoubleDispactchVisitor. For instance, if you want to explore tag nodes, override DoubleDispactchVisitor#visitTag. This method is called each time a tag node is encountered in the AST. Note: When overriding a visit method, you must call the super method in order to allow the visitor to visit the children of the node. See ForbiddenTagCheck for example.

Using SubscriptionVisitorCheck

To explore part of the AST, override SubscriptionVisitor#nodesToVisit by returning the list of Tree#Kind nodes you want to visit. For instance, if you want to explore tag nodes the method should return a list containing Tree#Kind#TAG. See ForbiddenNameContentCheck for example.

Creating Issues

Precise issue or file issue or line issue can be created by calling the related method in Issues.

Testing

Testing is made easy by the GherkinCheckVerifier. There are two ways to assert that an issue should be raised:

  • Through comments directly in the .feature test file
  • Or using assertions in the check class test

Examples of coding rule implementation and testing can be found in the Gherkin plugin gherkin-checks module.

About

Sample plugin that defines SonarQube custom rules for Cucumber Gherkin feature files

License:GNU Lesser General Public License v3.0


Languages

Language:Java 94.3%Language:Gherkin 3.3%Language:Shell 1.4%Language:HTML 0.9%