Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Rulesets and add first party Detekt extensions #5548

Merged
merged 20 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Visit [the project website](https://detekt.dev/) for installation guides, rule d
- [Changelog and migration guides](https://detekt.dev/changelog.html)
- [Available CLI options](https://detekt.dev/cli.html)
- [Rule set and rule descriptions](https://detekt.dev/complexity.html)
- [Writing custom rules and extending detekt](https://detekt.dev/extensions.html)
- [Writing custom rules and extending detekt](https://detekt.dev/docs/introduction/extensions/)
- [Suppressing issues in code](https://detekt.dev/suppressing-rules.html)
- [Suppressing issues via baseline file](https://detekt.dev/baseline.html)
- [Configuring detekt](https://detekt.dev/configurations.html)
Expand Down Expand Up @@ -125,17 +125,24 @@ dependencies {
}
```

Likewise custom [extensions](https://detekt.dev/extensions.html) can be added to detekt.
Similarly, there are extra rule sets available for Detekt from Detekt:
```kotlin
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-libraries:[version]")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-ruleauthors:[version]")
}
```
For more info visit the [Detekt Marketplace](https://detekt.dev/marketplace).

Likewise custom [extensions](https://detekt.dev/docs/introduction/extensions/) can be added to detekt.

### Contributing

See [CONTRIBUTING](.github/CONTRIBUTING.md)

Thanks to all the people who contributed to detekt!

<a href="https://github.com/detekt/detekt/graphs/contributors">
<img src="https://contrib.rocks/image?repo=detekt/detekt" />
</a>
[![Profile images of all the contributors](https://contrib.rocks/image?repo=detekt/detekt)](https://github.com/detekt/detekt/graphs/contributors)

### Mentions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import io.gitlab.arturbosch.detekt.api.internal.ruleSetConfig
/**
* This rule set provides wrappers for rules implemented by ktlint - https://ktlint.github.io/.
*
* Note: Issues reported by this rule set can only be suppressed on file level (`@file:Suppress("detekt.rule")`).
* Note: The formatting rule set is not included in the detekt-cli or gradle plugin.
* **Note: The `formatting` rule set is not included in the detekt-cli or Gradle plugin.**
*
* To enable this rule set, add `detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$version"`
* to your gradle dependencies or reference the `detekt-formatting`-jar with the `--plugins` option
* to your gradle `dependencies` or reference the `detekt-formatting`-jar with the `--plugins` option
* in the command line interface.
*
* Note: Issues reported by this rule set can only be suppressed on file level (`@file:Suppress("detekt.rule")`).
*/
@ActiveByDefault(since = "1.0.0")
class FormattingProvider : RuleSetProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import io.gitlab.arturbosch.detekt.api.internal.ActiveByDefault

/**
* Rules in this rule set report issues related to libraries API exposure.
*
* **Note: The `libraries` rule set is not included in the detekt-cli or Gradle plugin.**
*
* To enable this rule set, add `detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-libraries:$version"`
* to your Gradle `dependencies` or reference the `detekt-rules-libraries`-jar with the `--plugins` option
* in the command line interface.
*/
@ActiveByDefault("1.16.0")
class RuleLibrariesProvider : RuleSetProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.api.internal.ActiveByDefault

/**
* The rule authors ruleset provides rules that ensures good practices when writing detekt rules
* The rule authors ruleset provides rules that ensures good practices when writing detekt rules.
*
* **Note: The `ruleauthors` rule set is not included in the detekt-cli or Gradle plugin.**
*
* To enable this rule set, add `detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-ruleauthors:$version"`
* to your Gradle `dependencies` or reference the `detekt-rules-ruleauthors`-jar with the `--plugins` option
* in the command line interface.
*/
@ActiveByDefault("1.22.0")
class RuleAuthorsProvider : RuleSetProvider {
Expand Down
168 changes: 150 additions & 18 deletions website/src/data/marketplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,39 @@ export const tagTypes = {
ruleset: {
color: "#39ca30",
description: "A collection of custom rules for Detekt",
communityUrls: [
"https://github.com/topics/detekt-rules",
"https://github.com/search?q=%22io.gitlab.arturbosch.detekt.api.RuleSetProvider%22+-org%3Adetekt&type=code",
cortinico marked this conversation as resolved.
Show resolved Hide resolved
],
},
processor: {
color: "#e9669e",
description: "A custom processor for Detekt",
communityUrls: [
"https://github.com/search?q=%22io.gitlab.arturbosch.detekt.api.FileProcessListener%22+-org%3Adetekt&type=code",
],
},
reporter: {
color: "#fe6829",
description: "A custom reporter for Detekt",
communityUrls: [
"https://github.com/search?q=%22io.gitlab.arturbosch.detekt.api.OutputReport%22+-org%3Adetekt&type=code",
"https://github.com/search?q=%22io.gitlab.arturbosch.detekt.api.ConsoleReport%22+-org%3Adetekt&type=code",
],
},
configvalidator: {
color: "#53dbb7",
description: "A custom config validator for Detekt",
communityUrls: [
"https://github.com/search?q=%22io.gitlab.arturbosch.detekt.api.ConfigValidator%22+-org%3Adetekt&type=code",
],
},
plugin: {
color: "#a44fb7",
description: "A plugin or a tool built on top of Detekt",
communityUrls: [
"https://github.com/topics/detekt-plugin"
],
},
};

Expand All @@ -61,12 +82,15 @@ export const extensions = [
ruleset: "compose",
rules: [
"ComposableEventParameterNaming",
"ComposableParametersOrdering",
"ComposeFunctionName",
"MissingModifierDefaultValue",
"ModifierDefaultValue",
"ModifierHeightWithText",
"ModifierParameterPosition",
"PublicComposablePreview",
"ReusedModifierInstance",
"TopLevelComposableFunctions",
"UnnecessaryEventHandlerParameter",
],
usesTypeResolution: false,
Expand All @@ -77,25 +101,44 @@ export const extensions = [
description:
"Static checks to aid with a healthy adoption of Jetpack Compose.",
repo: "https://github.com/twitter/compose-rules/",
docs: "https://twitter.github.io/compose-rules/",
ruleset: "TwitterCompose",
rules: [
"ComposableNaming",
"ComposableParamOrder",
"CompositionLocalAllowlist",
"CompositionLocalNaming",
"ContentEmitterReturningValues",
"ModifierComposable",
"ModifierMissing",
"ModifierReused",
"ModifierWithoutDefault",
"MultipleEmitters",
"MutableParams",
"PreviewNaming",
"PreviewPublic",
"RememberMissing",
"UnstableCollections",
"ViewModelForwarding",
"ViewModelInjection",
],
usesTypeResolution: false,
tags: ["ruleset"],
},
{
title: "Detekt Rule Authors",
description:
"The rule authors ruleset provides rules that ensures good practices when writing detekt rules.",
repo: "https://github.com/detekt/detekt",
docs: "https://detekt.dev/docs/next/rules/ruleauthors",
tags: ["ruleset"],
ruleset: "ruleauthors",
rules: [
"UseEntityAtName",
"ViolatesTypeResolutionRequirements",
],
usesTypeResolution: true,
},
{
title: "Doist detekt-rules",
description:
Expand All @@ -113,6 +156,102 @@ export const extensions = [
usesTypeResolution: false,
tags: ["ruleset"],
},
{
title: "GitLab Report",
description:
"A reporter to export Detekt findings to GitLab Code Quality (and other code climate compatible tools).\nThis is designed for use with GitLab, but should also work fine with everything else that accepts the code climate format.",
repo: "https://gitlab.com/cromefire/detekt-gitlab-report",
tags: ["reporter"],
},
{
title: "Hint",
description:
"A ruleset to implement detection of violation of programming principles. detekt-hint offers also instructions on how to integrate with Danger and Github Actions",
repo: "https://github.com/mkohm/detekt-hint",
docs: "https://mkohm.github.io/detekt-hint/",
tags: ["plugin", "ruleset"],
ruleset: "detekt-hint",
rules: [
"InterfaceSegregationPrinciple",
"LackOfCohesionMethods",
"OpenClosedPrinciple",
"UseCompositionInsteadOfInheritance",
],
usesTypeResolution: true,
},
{
title: "ktlint",
description:
"This rule set provides wrappers for rules implemented by ktlint.",
repo: "https://github.com/detekt/detekt",
docs: "https://detekt.dev/docs/next/rules/formatting",
tags: ["ruleset"],
ruleset: "formatting",
rules: [
"AnnotationOnSeparateLine",
"AnnotationSpacing",
"ArgumentListWrapping",
"BlockCommentInitialStarAlignment",
"ChainWrapping",
"CommentSpacing",
"CommentWrapping",
"DiscouragedCommentLocation",
"EnumEntryNameCase",
"Filename",
"FinalNewline",
"FunKeywordSpacing",
"FunctionReturnTypeSpacing",
"FunctionSignature",
"FunctionStartOfBodySpacing",
"FunctionTypeReferenceSpacing",
"ImportOrdering",
"Indentation",
"KdocWrapping",
"MaximumLineLength",
"ModifierListSpacing",
"ModifierOrdering",
"MultiLineIfElse",
"NoBlankLineBeforeRbrace",
"NoBlankLinesInChainedMethodCalls",
"NoConsecutiveBlankLines",
"NoEmptyClassBody",
"NoEmptyFirstLineInMethodBlock",
"NoLineBreakAfterElse",
"NoLineBreakBeforeAssignment",
"NoMultipleSpaces",
"NoSemicolons",
"NoTrailingSpaces",
"NoUnitReturn",
"NoUnusedImports",
"NoWildcardImports",
"NullableTypeSpacing",
"PackageName",
"ParameterListSpacing",
"ParameterListWrapping",
"SpacingAroundAngleBrackets",
"SpacingAroundColon",
"SpacingAroundComma",
"SpacingAroundCurly",
"SpacingAroundDot",
"SpacingAroundDoubleColon",
"SpacingAroundKeyword",
"SpacingAroundOperators",
"SpacingAroundParens",
"SpacingAroundRangeOperator",
"SpacingAroundUnaryOperator",
"SpacingBetweenDeclarationsWithAnnotations",
"SpacingBetweenDeclarationsWithComments",
"SpacingBetweenFunctionNameAndOpeningParenthesis",
"StringTemplate",
"TrailingCommaOnCallSite",
"TrailingCommaOnDeclarationSite",
"TypeArgumentListSpacing",
"TypeParameterListSpacing",
"UnnecessaryParenthesesBeforeTrailingLambda",
"Wrapping",
],
usesTypeResolution: false,
},
{
title: "Kure",
description:
Expand All @@ -135,27 +274,20 @@ export const extensions = [
usesTypeResolution: true,
},
{
title: "Hint",
title: "Library Authors",
description:
"A ruleset to implement detection of violation of programming principles. detekt-hint offers also instructions on how to integrate with Danger and Github Actions",
repo: "https://github.com/mkohm/detekt-hint",
tags: ["plugin", "ruleset"],
ruleset: "detekt-hint",
"Rules in this rule set report issues related to libraries API exposure.",
repo: "https://github.com/detekt/detekt",
docs: "https://detekt.dev/docs/next/rules/libraries",
tags: ["ruleset"],
ruleset: "libraries",
rules: [
"InterfaceSegregationPrinciple",
"LackOfCohesionMethods",
"OpenClosedPrinciple",
"UseCompositionInsteadOfInheritance",
"ForbiddenPublicDataClass",
"LibraryCodeMustSpecifyReturnType",
"LibraryEntitiesShouldNotBePublic",
],
usesTypeResolution: true,
},
{
title: "Gitlab Report",
description:
"A reporter to export Detekt findings to GitLab Code Quality (and other code climate compatible tools).\nThis is designed for use with GitLab, but should also work fine with everything else that accepts the code climate format.",
repo: "https://gitlab.com/cromefire/detekt-gitlab-report",
tags: ["reporter"],
},
{
title: "Operator",
description:
Expand Down Expand Up @@ -186,7 +318,7 @@ export const extensions = [
tags: ["ruleset"],
},
/*
Pro Tip: add your ruleset in alphabetical order.
Appending your ruleset here (at the end) is more likely to produce Git conflicts.
* Pro Tip: add your ruleset in alphabetical order.
* Appending your ruleset here (at the end) is more likely to produce Git conflicts.
*/
];
4 changes: 2 additions & 2 deletions website/src/pages/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ keywords: [changelog, release-notes, migration]
- We deprecated the MultiRule class as it was overly complicated. The suggested approach is to just provide separated rules. - [#5161](https://github.com/detekt/detekt/pull/5161)
- The `--fail-fast` CLI flag (and `failFast` Gradle property) has been removed. It was deprecated since 1.16.x - [#5290](https://github.com/detekt/detekt/pull/5290)
- We **deprecated** the following rules `DuplicateCaseInWhenExpression`, `MissingWhenCase`, `RedundantElseInWhen` as the Kotlin Compiler is already reporting errors for those scenarios - [#5309](https://github.com/detekt/detekt/pull/5309)
- We removed the `--print-ast` CLI flag as PsiViewer provides the same features - [#5418](https://github.com/detekt/detekt/pull/5418)
- We removed the `--print-ast` CLI flag as [PsiViewer](https://www.jetbrains.com/help/idea/psi-viewer.html) provides the same features - [#5418](https://github.com/detekt/detekt/pull/5418)
- Notable changes to existing rules
- `ArrayPrimitive` is now working only with Type Resolution - [#5175](https://github.com/detekt/detekt/pull/5175)
- `WildcardImport` is now running also on tests by default - [#5121](https://github.com/detekt/detekt/pull/5121)
Expand Down Expand Up @@ -105,7 +105,7 @@ If you wish to use the `libraries` ruleset we introduced you should add the foll
and add the following to you `build.gradle` file:

```kotlin
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-authors:$version")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-libraries:$version")
```

If you're using our KtLint wrapper (i.e. `detekt-formatting`) you should also update your config file as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function MarketplaceCard(input) {
</Link>
</div>
<div className={styles.marketplaceCardBody}>
<Link href={extension.repo}>{extension.repo}</Link>
<Link href={extension.docs ?? extension.repo}>{extension.docs ?? extension.repo}</Link>
<p>{extension.description}</p>
{extension.rules && (
<p>
Expand All @@ -38,7 +38,7 @@ function MarketplaceCard(input) {
Uses type resolution:{" "}
<strong>{extension.usesTypeResolution.toString()}</strong>
</p>
<p>
<p className={styles.marketplaceCardRules}>
<ul>
{extension.rules.map((rule) => (
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
line-height: 1.66;
}

.marketplaceCardRules {
max-height: 300px;
overflow-y: auto;
}

.tagContainer {
display: flex;
flex-wrap: wrap;
list-style: none;
}
}