gjd6640 / sonar-text-plugin

A free and open-source plugin for SonarSource's Sonarqube product that lets you create rules to flag issues in text files.
Apache License 2.0
23 stars 4 forks source link

sonar-text-plugin

A free and open-source Community plugin for SonarSource's Sonarqube product that lets you create custom rules to flag issues in text files. Currently it supports raising issues by:

Screenshots

Other screenshots are available by browsing the "/screenshots" directory in this project.

Why use this plugin

The uses that I had in mind when building this were:

To install the plugin:

  1. Ctrl-F for "release" on this Github page and click that link
  2. Download the plugin Jar file
  3. Copy that Jar into your Sonar installation's "extensions/plugins" directory
  4. Reboot Sonar

To configure your first rule:

  1. Log in to Sonar, go to Quality Profiles, find the new "Text" section, and create a new profile under that
  2. Make the new Quality Profile the default Test profile
  3. Add an initial rule to the new Quality Profile's ruleset. Do this by first finding the inactive "Simple Regex Match" rule. Click on that rule.
  4. Click the "create" button that appears next to the words "CUSTOM RULES" at the bottom of the rule definition
  5. Define your rule and save it
  6. Activate the new rule in a quality profile
  7. Double-check to ensure that the list of extensions for the 'text' language includes the extension of the file that your rule is looking for.
  8. Double-check to ensure that your "sonar.sources" path will include the file to be scanned. If this path is set to "src/main/java" then Sonar won't scan files at the root of your project or in "src/main/resources".

After you've done the above you'll be ready to run a scan and see the first rule work.

A use-case that I don't plan to solve via this plugin

Truly understanding library dependencies & specifying rules about those dependencies in a build tool agnostic manner is out of scope. That fits better in a "sonar-dependencies-plugin" that'd understand library dependency reports such as the Maven dependency plugin generates (teach it to understand dependency reports from several popular build tools). That plugin would have a rule template to flag problematic dependencies. It might also expose a custom API that other Sonar plugins can reference when running their rules; for example, the Java plugin might let you apply both a PMD XPath expression and a library version check and only raise an issue when both 'match' (use of a known buggy method / maybe multithreaded use of a call known to be non-threadsafe / enabling a feature via a property that doesn't work properly if a certain library version is being used).