Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remal-gradle-plugins/sonarlint
A plugin that executes SonarLint checks without SonarQube server
https://github.com/remal-gradle-plugins/sonarlint
gradle gradle-plugin plugin sonar sonarlint sonarqube
Last synced: about 2 months ago
JSON representation
A plugin that executes SonarLint checks without SonarQube server
- Host: GitHub
- URL: https://github.com/remal-gradle-plugins/sonarlint
- Owner: remal-gradle-plugins
- License: mit
- Created: 2022-09-21T02:27:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T10:56:33.000Z (3 months ago)
- Last Synced: 2024-10-29T12:47:41.971Z (3 months ago)
- Topics: gradle, gradle-plugin, plugin, sonar, sonarlint, sonarqube
- Language: Java
- Homepage:
- Size: 1.01 MB
- Stars: 18
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
**Tested on Java LTS versions from 8 to 21.**
**Tested on Gradle versions from 7.1 to 8.12-rc-1.**
# `name.remal.sonarlint` plugin
[![configuration cache: supported from v3.2](https://img.shields.io/static/v1?label=configuration%20cache&message=supported+from+v3.2&color=success)](https://docs.gradle.org/current/userguide/configuration_cache.html)
This plugin executes [SonarLint](https://www.sonarlint.org/) inspections without connecting to a SonarQube server.
The plugin uses these Sonar plugins:
* [AzureResourceManager](https://rules.sonarsource.com/azureresourcemanager/)
* [CloudFormation](https://rules.sonarsource.com/cloudformation/)
* [CSS](https://rules.sonarsource.com/css/)
* [Docker](https://rules.sonarsource.com/docker/)
* [Java](https://rules.sonarsource.com/java/)
* [JavaScript](https://rules.sonarsource.com/javascript/)
* JSON
* JSP
* [Kotlin](https://rules.sonarsource.com/kotlin/)
* [Kubernetes](https://rules.sonarsource.com/kubernetes/)
* [Scala](https://rules.sonarsource.com/scala/)
* [Secrets](https://rules.sonarsource.com/secrets/)
* [Terraform](https://rules.sonarsource.com/terraform/)
* [Text](https://rules.sonarsource.com/text/)
* [TypeScript](https://rules.sonarsource.com/typescript/)
* [HTML](https://rules.sonarsource.com/web/)
* [XML](https://rules.sonarsource.com/xml/)
* YAMLFor every [`SourceSet`](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSet.html) a SonarLint task is created by default.
## Configuration
```groovy
sonarLint {
isGeneratedCodeIgnored = false // `true` by default, set to `false` to validate generated code (code inside `./build/`)// see detailed documentation about `nodeJs` later in the document
nodeJs {
nodeJsExecutable = project.layout.projectDirectory.file('/usr/bin/node') // set path to Node.js executable
detectNodeJs = true // `false` by default, set to `true` to enable automatic Node.js detection
logNodeJsNotFound = false // Hide warning message about not found Node.js
}rules {
enable(
'java:S100', // Enable `java:S100` rule (that is disabled by default)
'java:S101', // Enable `java:S101` rule (that is disabled by default)
)
enabled = ['java:S100'] // `enabled` - a mutable collection of enabled rulesdisable(
'java:S1000', // Disable `java:S1000` rule
'java:S1001', // Disable `java:S1001` rule
)
disabled = ['java:S1000'] // `disabled` - a mutable collection of disabled rulesrule('java:S100') {
property('format', '^[a-z][a-zA-Z0-9]*$') // Configure `format` property for `java:S100` rule
properties = ['format': '^[a-z][a-zA-Z0-9]*$'] // `properties` - a mutable map of rule properties
}
}languages {
include('java', 'kotlin') // Enable Java and Kotlin languages only, all other languages become disabled
exclude('java', 'kotlin') // Disable Java and Kotlin languages, all other languages remain enabled
}sonarProperty('sonar.html.file.suffixes', '.custom-html') // Configure `sonar.html.file.suffixes` Sonar property
sonarProperties = ['sonar.html.file.suffixes': '.custom-html'] // `sonarProperties` - a mutable map of Sonar propertiesignoredPaths.add('**/dto/**') // Ignore all files which relative path matches `**/dto/**` glob for all rules
rules {
rule('java:S100') {
ignoredPaths.add('**/dto/**') // Ignore all files which relative path matches `**/dto/**` glob for rule `java:S100`
}
}testSourceSets = sourceSets.matching { true } // Which source-sets contain test sources. Source-sets created by plugins like `name.remal.test-source-sets` are automatically integrated. Most probably, you don't have to configure anything yourself.
logging {
withDescription = false // Hide rule descriptions from console output
hideWarnings = true // To hide warnings produced by this plugin
}// `sonarLint` extension extends `CodeQualityExtension` (see https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/quality/CodeQualityExtension.html).
// You can use all fields of `CodeQualityExtension` the same way as for `checkstyle`, for example.
}
```For every property value (for both Sonar properties and rule properties) you can use `project.provider { ... }` to set a lazy value that will be calculated when a SonarLint task is executed. For example:
```groovy
sonarLint {
sonarProperty('sonar.html.file.suffixes', project.provider { '.custom-html' })
}
```## Help tasks
Two additional help tasks are created:
1. `sonarLintProperties` - displays Sonar properties that can be configured via `sonarLint.sonarProperties`.
2. `sonarLintRules` - displays all Sonar rules available, their description and their properties.## Node.js detection
SonarLint requires Node.js of the version 18.17.0 or greater
to process CSS, HTML, JavaScript, TypeScript, YAML languages.If Node.js detection is enabled, the plugin tries to find a Node.js executable automatically. The detection algorithm is:
1. Try to find a Node.js executable on $PATH
2. Then try to download a Node.js executable from [the official website](https://nodejs.org/en/download)If Node.js is successfully detected, is will be used.
If Node.js cannot be detected, CSS, HTML, JavaScript, TypeScript, YAML languages will be excluded.
If OS or CPU architecture does not support official Node.js, the detection won't detect any executable.
If there are no files requiring Node.js in the sources, Node.js detection will be skipped.
# Migration guide
## Version 3.* to 4.*
Gradle 6 support was removed.
## Version 2.* to 3.*
Package name was changed from `name.remal.gradleplugins.sonarlint` to `name.remal.gradle_plugins.sonarlint`.