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

Add wrapper for KtLint rules #6037

Merged
merged 3 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions detekt-core/src/main/resources/default-detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ naming:
active: false
allowedPattern: '^(is|has|are)'
ClassNaming:
active: true
classPattern: '[A-Z][a-zA-Z0-9]*'
active: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this changed?

Copy link
Contributor Author

@atulgpt atulgpt Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my question. Ideally, it should not be changed but it got changed automatically after running generateDocumentation. This could be a bug in generateDocumentation as I have also added the ClassNaming rule from KtLint and there was one preexisting ClassNaming rule as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico here my only concern which is not related to this PR is how we handle the same name rules, should generateDocumentation fail in cases like that? Or should we support the same name rules(if yes then when? Like should we allow the same name rules only when those are in different rule sections?) If we allow same name rules then the above change should also be addressed as generateDocumentation wrongly updates the wrong rules config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, in detekt what is a unique identifier for a rule? Is this just rule name or combination of rule provider id and name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how we handle the same name rules, should generateDocumentation fail in cases like that?

I think that's a bug and we should investigate here. Rules with same ID coudl occur, especially if coming from external packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, I have reverted the unintentional change. I will create a separate issue for the bug

ConstructorParameterNaming:
active: true
parameterPattern: '[a-z][A-Za-z0-9]*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.gitlab.arturbosch.detekt.formatting.wrappers.AnnotationSpacing
import io.gitlab.arturbosch.detekt.formatting.wrappers.ArgumentListWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.BlockCommentInitialStarAlignment
import io.gitlab.arturbosch.detekt.formatting.wrappers.ChainWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.ClassNaming
import io.gitlab.arturbosch.detekt.formatting.wrappers.CommentSpacing
import io.gitlab.arturbosch.detekt.formatting.wrappers.CommentWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.ContextReceiverMapping
Expand All @@ -16,6 +17,7 @@ import io.gitlab.arturbosch.detekt.formatting.wrappers.EnumWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.Filename
import io.gitlab.arturbosch.detekt.formatting.wrappers.FinalNewline
import io.gitlab.arturbosch.detekt.formatting.wrappers.FunKeywordSpacing
import io.gitlab.arturbosch.detekt.formatting.wrappers.FunctionName
import io.gitlab.arturbosch.detekt.formatting.wrappers.FunctionReturnTypeSpacing
import io.gitlab.arturbosch.detekt.formatting.wrappers.FunctionSignature
import io.gitlab.arturbosch.detekt.formatting.wrappers.FunctionStartOfBodySpacing
Expand Down Expand Up @@ -51,6 +53,7 @@ import io.gitlab.arturbosch.detekt.formatting.wrappers.PackageName
import io.gitlab.arturbosch.detekt.formatting.wrappers.ParameterListSpacing
import io.gitlab.arturbosch.detekt.formatting.wrappers.ParameterListWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.ParameterWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.PropertyName
import io.gitlab.arturbosch.detekt.formatting.wrappers.PropertyWrapping
import io.gitlab.arturbosch.detekt.formatting.wrappers.SpacingAroundAngleBrackets
import io.gitlab.arturbosch.detekt.formatting.wrappers.SpacingAroundColon
Expand Down Expand Up @@ -92,11 +95,13 @@ class KtLintMultiRule(config: Config = Config.empty) :
ArgumentListWrapping(config),
BlockCommentInitialStarAlignment(config),
ChainWrapping(config),
ClassNaming(config),
CommentSpacing(config),
CommentWrapping(config),
EnumEntryNameCase(config),
Filename(config),
FinalNewline(config),
FunctionName(config),
FunKeywordSpacing(config),
FunctionReturnTypeSpacing(config),
FunctionStartOfBodySpacing(config),
Expand Down Expand Up @@ -125,6 +130,7 @@ class KtLintMultiRule(config: Config = Config.empty) :
PackageName(config),
ParameterListWrapping(config),
ParameterWrapping(config),
PropertyName(config),
PropertyWrapping(config),
SpacingAroundAngleBrackets(config),
SpacingAroundColon(config),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.gitlab.arturbosch.detekt.formatting.wrappers

import com.pinterest.ktlint.ruleset.standard.rules.ClassNamingRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/standard/#classobject-naming) for
* documentation.
*/
class ClassNaming(config: Config) : FormattingRule(config) {
override val wrapping = ClassNamingRule()
override val issue =
issueFor("Class or object name should start with an uppercase letter and use camel case.")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.gitlab.arturbosch.detekt.formatting.wrappers

import com.pinterest.ktlint.ruleset.standard.rules.FunctionNamingRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/experimental/#function-naming) for
* documentation.
*/
class FunctionName(config: Config) : FormattingRule(config) {
override val wrapping = FunctionNamingRule()
override val issue =
issueFor("Function name should start with a lowercase letter (except factory methods) and use camel case.")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.gitlab.arturbosch.detekt.formatting.wrappers

import com.pinterest.ktlint.ruleset.standard.rules.PropertyNamingRule
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.FormattingRule

/**
* See [ktlint docs](https://pinterest.github.io/ktlint/rules/experimental/#property-naming) for
* documentation.
*/
class PropertyName(config: Config) : FormattingRule(config) {
override val wrapping = PropertyNamingRule()
override val issue =
issueFor("Reports incorrect property name.")
}
6 changes: 6 additions & 0 deletions detekt-formatting/src/main/resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ formatting:
active: true
autoCorrect: true
indentSize: 4
ClassNaming:
cortinico marked this conversation as resolved.
Show resolved Hide resolved
active: false
CommentSpacing:
active: true
autoCorrect: true
Expand Down Expand Up @@ -52,6 +54,8 @@ formatting:
FunKeywordSpacing:
active: true
autoCorrect: true
FunctionName:
active: false
FunctionReturnTypeSpacing:
active: true
autoCorrect: true
Expand Down Expand Up @@ -174,6 +178,8 @@ formatting:
autoCorrect: true
indentSize: 4
maxLineLength: 120
PropertyName:
active: false
PropertyWrapping:
active: true
autoCorrect: true
Expand Down