* Emit helpful errors in Gradle plugin Whenever the plugin is applied to a project that doesn't have jcenter() configured, the user would get a cryptic error message from Gradle (see issue #2549). This simple change makes sure the plugin will provide users with clear instructions on how to fix their build so they don't get stumped when things don't work. * Update contributions in README * Fix ktlint name in docs: it's all lowercase Also update repo URL to /pinterest/ktlint through out docs * Update Gradle getting started in index.md * Fix ktlint name in code too * Address detekt warnings after plugin changes * Only check for jCenter in afterEvaluate { } This is necessary because we need to make sure it's there _somehow_, and it may be added by other plugins, or blocks evaluated after this plugin is applied. * Apply suggestions from code review Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com> Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
5.2 KiB
Contributing to detekt
- Read this article before writing commit messages
- Use
gradle build -x dokkato build the source but exclude documentation jar generating to save time. gradle detektshould not report any errors- This repository follows the Kotlin Coding Conventions which are enforced by ktlint when running
gradle detekt. - Make sure your IDE uses ktlint formatting rules as well as the settings in .editorconfig
- We use Spek for testing. Please use the
Spec.kt-Suffix. For easier testing you might want to use the Spek IntelliJ Plugin. - Feel free to add your name to the contributors list at the end of the readme file when opening a pull request.
- The code in
detekt-apiand any rule indetekt-rulesmust be documented. We generate documentation for our website based on these modules. - If some Kotlin code in
resourcesfolder (likedetekt-formatting) shows a compilation error, right click on it and useMark as plain text.
When implementing new rules ...
-
... do not forget to add the new rule to a
RuleSetProvider(e.g. StyleGuideProvider) -
... do not forget to write a description for the issue of the new rule.
-
Add the correct KDoc to the Rule class. This KDoc is used to generate wiki pages and the
default-detekt-config.ymlautomatically. The format of the KDoc should be as follows:/** * This is a nice description for the rule, explaining what it checks, why it exists and how violations can be * solved. * * <noncompliant> * // add the non-compliant code example here * </noncompliant> * * <compliant> * // add the compliant code example here * </compliant> * * @configuration name - Description for the configuration option (default: `whatever should be the default`) */ class SomeRule : Rule { }The description should be as detailed as possible as it will act as the documentation of the rule. Add links to references that explain the rationale for the rule if possible. The
<noncompliant>and<compliant>code examples should be added right after the description of the rule. The@configurationtag should follow the correct pattern. The name of the configuration option has to match the actual name used in the code, otherwise an invaliddefault-detekt-config.ymlwill be generated and the rule won't function correctly by default. The default value will be taken as is for the configuration option and pasted into thedefault-detekt-config.yml.A
@configurationtag as described above will translate to a rule entry in thedefault-detekt-config.yml:SomeRule: active: false name: whatever should be the default -
... do not forget to test the new rule and/or add tests for any changes made to a rule. Run detekt on itself and other kotlin projects with the
--run-rule RuleSet:RuleIdoption to test your rule in isolation. Make use of thescripts/get_analysis_projects.groovyscript to automatically establish a set of analysis projects. -
... do not forget to run
./gradlew build. This will execute tests locally and update thedefault-detekt.config.ymlas well as add the new/changed rules to the documentation. -
To print the AST of sources you can pass the
--print-astflag to the CLI which will print each Kotlin files AST. This can be helpful when implementing and debugging rules. -
To view the AST (PSI) of your source code you can use the PSI Viewer plugin for IntelliJ.
-
be aware that your PR will stay open for at least two days so that other users can give feedback.
After some time and testing there is a chance this rule will become active on default.
Rules that contain an @active tag in their KDoc will be marked as active in the default-detekt-config.yml.
When updating the website ...
Make sure to test your changes locally.
- install ruby and jekyll
- gem install bundler
- bundler install
- jekyll build
- jekyll serve
Following warning is expected until Jekyll adopts to Ruby 2.7.0.
warning: Using the last argument as keyword parameters is deprecated (Ruby 2.7.0)
When working on the Gradle plugin ...
- Make changes to the core modules (e.g. adding a new CLI flag)
- Run
gradle publishToMavenLocal - Make changes to the Gradle plugin and add tests
- Verify with
gradle detekt
Release process
groovy scripts/github-milestone-report.groovy- creates changelog- Increment
detektVersioningradle.properties gradle build publishToMavenLocal -x detekt -x testgradle test detektgradle bintrayUpload- uploads artifacts to Bintraygradle publishPlugins- uploads the Gradle Plugin to the Plugin Repositoriesgradle githubRelease- creates a tag for the current version with changelog and cli jar- Increment
detektAnalysisVersioningradle.propertiesto use newest plugin version on CI