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

Formulate rule/style descriptions consistently #4414

Merged
merged 2 commits into from Dec 28, 2021
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
Expand Up @@ -32,8 +32,8 @@ class DataClassContainsFunctions(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"DataClassContainsFunctions",
Severity.Style,
"Data classes should mainly be used to store data and should not have any extra functions. " +
"(Compiler will automatically generate equals, toString and hashCode functions)",
"Data classes should mainly be used to store data and should not have any extra functions " +
"(Compiler will automatically generate equals, toString and hashCode functions).",
Debt.TWENTY_MINS
)

Expand Down
Expand Up @@ -34,8 +34,8 @@ class DataClassShouldBeImmutable(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"DataClassShouldBeImmutable",
Severity.Style,
"Data classes should mainly be immutable and should not have any side effects. " +
"(To copy an object altering some of its properties use the copy function)",
"Data classes should mainly be immutable and should not have any side effects " +
"(To copy an object altering some of its properties use the copy function).",
Debt.TWENTY_MINS
)

Expand Down
Expand Up @@ -49,6 +49,6 @@ class EqualsOnSignatureLine(config: Config = Config.empty) : Rule(config) {
}

private companion object {
const val MESSAGE = "Equals signs for expression style functions should be on the same line as the signature"
const val MESSAGE = "Equals signs for expression style functions should be on the same line as the signature."
}
}
Expand Up @@ -43,7 +43,7 @@ class ExplicitCollectionElementAccessMethod(config: Config = Config.empty) : Rul
Issue(
"ExplicitCollectionElementAccessMethod",
Severity.Style,
"Prefer usage of indexed access operator [] for map element access or insert methods",
"Prefer usage of the indexed access operator [] for map element access or insert methods.",
Debt.FIVE_MINS
)

Expand All @@ -52,7 +52,7 @@ class ExplicitCollectionElementAccessMethod(config: Config = Config.empty) : Rul
if (bindingContext == BindingContext.EMPTY) return
val call = expression.selectorExpression as? KtCallExpression ?: return
if (isIndexableGetter(call) || (isIndexableSetter(call) && unusedReturnValue(call))) {
report(CodeSmell(issue, Entity.from(expression), "Prefer usage of indexed access operator []."))
report(CodeSmell(issue, Entity.from(expression), issue.description))
}
}

Expand Down
Expand Up @@ -43,8 +43,7 @@ class ExpressionBodySyntax(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Functions with exact one statement, the return statement," +
" can be rewritten with ExpressionBodySyntax.",
"Functions with exact one statement, the return statement, can be rewritten with ExpressionBodySyntax.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -28,7 +28,7 @@ class ForbiddenImport(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Mark forbidden imports. A forbidden import could be an import for an unstable / experimental api" +
"Mark forbidden imports. A forbidden import could be an import for an unstable / experimental api " +
"and hence you might want to mark it as forbidden in order to get warned about the usage.",
Debt.TEN_MINS
)
Expand Down
Expand Up @@ -41,8 +41,7 @@ class FunctionOnlyReturningConstant(config: Config = Config.empty) : Rule(config
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"A function that only returns a constant is misleading. " +
"Consider declaring a constant instead",
"A function that only returns a constant is misleading. Consider declaring a constant instead.",
Debt.TEN_MINS
)

Expand Down
Expand Up @@ -49,7 +49,7 @@ class LibraryCodeMustSpecifyReturnType(config: Config = Config.empty) : Rule(con
this.javaClass.simpleName,
Severity.Style,
"Library functions/properties should have an explicit return type. " +
"Inferred return type can easily be changed by mistake which may lead to breaking changes.",
"Inferred return types can easily be changed by mistake which may lead to breaking changes.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -32,7 +32,7 @@ class LibraryEntitiesShouldNotBePublic(ruleSetConfig: Config = Config.empty) : R
override val issue: Issue = Issue(
javaClass.simpleName,
Severity.Style,
"Library class should not be public",
"Library classes should not be public.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -24,7 +24,7 @@ class MaxLineLength(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Line detected that is longer than the defined maximum line length in the code style.",
"Line detected, which is longer than the defined maximum line length in the code style.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -41,7 +41,7 @@ class MayBeConst(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Reports vals that can be const val instead.",
"Usage of `vals` that can be `const val` detected.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -57,7 +57,7 @@ class ModifierOrder(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Modifiers are not in the correct order.",
"Modifiers are not in the correct order. Consider to reorder these modifiers.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -69,7 +69,7 @@ class MultilineLambdaItParameter(val config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Multiline lambdas should not use `it` as a parameter name",
"Multiline lambdas should not use `it` as a parameter name.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -39,7 +39,8 @@ class OptionalAbstractKeyword(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
javaClass.simpleName,
Severity.Style,
"Unnecessary abstract modifier in interface",
"Unnecessary abstract modifier in interface detected. " +
"This abstract modifier is unnecessary and thus can be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -36,7 +36,7 @@ class OptionalWhenBraces(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
javaClass.simpleName,
Severity.Style,
"Optional braces in when expression",
"Optional braces in when expression detected.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -77,7 +77,7 @@ class RedundantHigherOrderMapUsage(config: Config = Config.empty) : Rule(config)
override val issue: Issue = Issue(
javaClass.simpleName,
Severity.Style,
"Checks for Redundant 'map' calls.",
"Checks for redundant 'map' calls, which can be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -51,7 +51,7 @@ class RedundantVisibilityModifierRule(config: Config = Config.empty) : Rule(conf
override val issue: Issue = Issue(
"RedundantVisibilityModifierRule",
Severity.Style,
"Checks for redundant visibility modifiers.",
"Redundant visibility modifiers detected, which can be safely removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -38,7 +38,7 @@ class SafeCast(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Safe cast instead of if-else-null",
"Prefer to use a safe cast instead of if-else-null.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -40,7 +40,7 @@ class SpacingBetweenPackageAndImports(config: Config = Config.empty) : Rule(conf
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Violation of the package declaration style.",
"Violation of the package declaration style detected.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -17,7 +17,7 @@ class TrailingWhitespace(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Checks which lines end with a whitespace.",
"Whitespaces at the end of a line are unnecessary and can be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -47,7 +47,7 @@ class UnnecessaryApply(config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"The `apply` usage is unnecessary",
"The `apply` usage is unnecessary and can be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -48,7 +48,7 @@ class UnnecessaryFilter(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UnnecessaryFilter",
Severity.Style,
"filter() with other collection operations may be simplified.",
"`filter()` with other collection operations may be simplified.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -53,7 +53,7 @@ class UnnecessaryLet(config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"The `let` usage is unnecessary",
"The `let` usage is unnecessary.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -33,7 +33,7 @@ class UntilInsteadOfRangeTo(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"'..' call can be replaced with 'until'",
"A `..` call can be replaced with `until`.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -46,7 +46,7 @@ class UnusedPrivateClass(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UnusedPrivateClass",
Severity.Maintainability,
"Private class is unused.",
"Private class is unused and should be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -63,7 +63,7 @@ class UnusedPrivateMember(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UnusedPrivateMember",
Severity.Maintainability,
"Private member is unused.",
"Private member is unused and should be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -36,7 +36,7 @@ class UseAnyOrNoneInsteadOfFind(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UseAnyOrNoneInsteadOfFind",
Severity.Style,
"Use 'any' or 'none' instead of 'find' and null check",
"Use `any` or `none` instead of `find` and `null` checks.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -26,7 +26,7 @@ class UseArrayLiteralsInAnnotations(config: Config = Config.empty) : Rule(config
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"Array literals '[...]' should be preferred as they are more readable than 'arrayOf(...)' expressions.",
"Array literals [...] should be preferred as they are more readable than `arrayOf(...)` expressions.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -39,7 +39,7 @@ class UseEmptyCounterpart(config: Config) : Rule(config) {
override val issue = Issue(
javaClass.simpleName,
Severity.Style,
"""Instantiation of an object's "empty" state should use the object's "empty" initializer""",
"""Instantiation of an object's "empty" state should use the object's "empty" initializer.""",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -53,7 +53,7 @@ class UseIfEmptyOrIfBlank(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UseIfEmptyOrIfBlank",
Severity.Style,
"Use 'ifEmpty' or 'ifBlank' instead of 'isEmpty' or 'isBlank' to assign default value.",
"Use `ifEmpty` or `ifBlank` instead of `isEmpty` or `isBlank` to assign a default value.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -30,7 +30,7 @@ class UseIfInsteadOfWhen(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UseIfInsteadOfWhen",
Severity.Style,
"Binary expressions are better expressed using an 'if' expression than a 'when' expression.",
"Binary expressions are better expressed using an `if` expression than a `when` expression.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -50,7 +50,7 @@ class UseIsNullOrEmpty(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UseIsNullOrEmpty",
Severity.Style,
"Use 'isNullOrEmpty()' call instead of 'x == null || x.isEmpty()'",
"Use `isNullOrEmpty()` call instead of `x == null || x.isEmpty()`.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -45,7 +45,7 @@ class UseOrEmpty(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UseOrEmpty",
Severity.Style,
"Use 'orEmpty()' call instead of '?: emptyList()'",
"Use `orEmpty()` call instead of `?: emptyList()`",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -50,9 +50,10 @@ class UselessCallOnNotNull(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue(
"UselessCallOnNotNull",
Severity.Performance,
"This call on non-null reference may be reduced or removed. Some calls are intended to be called on nullable " +
"collection or text types (e.g. String?). When this call is used on a reference to a non-null type " +
"(e.g. String) it is redundant and will have no effect, so it can be removed.",
"This call on a non-null reference may be reduced or removed. " +
"Some calls are intended to be called on nullable collection or text types (e.g. `String?`)." +
"When this call is used on a reference to a non-null type " +
"(e.g. `String`) it is redundant and will have no effect, so it can be removed.",
Debt.FIVE_MINS
)

Expand Down
Expand Up @@ -14,9 +14,6 @@ import org.jetbrains.kotlin.psi.KtIfExpression
import org.jetbrains.kotlin.psi.KtWhenExpression
import org.jetbrains.kotlin.psi.psiUtil.siblings

private const val DESCRIPTION = "Multi-line if statement was found that does not have braces. " +
"These should be added to improve readability."

/**
* This rule detects multi-line `if` statements which do not have braces.
* Adding braces would improve readability and avoid possible errors.
Expand All @@ -33,19 +30,25 @@ private const val DESCRIPTION = "Multi-line if statement was found that does not
*/
class MandatoryBracesIfStatements(config: Config = Config.empty) : Rule(config) {

override val issue = Issue("MandatoryBracesIfStatements", Severity.Style, DESCRIPTION, Debt.FIVE_MINS)
override val issue = Issue(
"MandatoryBracesIfStatements",
Severity.Style,
"Multi-line if statement was found that does not have braces. " +
"These braces should be added to improve readability.",
Debt.FIVE_MINS
)

override fun visitIfExpression(expression: KtIfExpression) {
super.visitIfExpression(expression)

val thenExpression = expression.then ?: return
if (thenExpression !is KtBlockExpression && hasNewLineAfter(expression.rightParenthesis)) {
report(CodeSmell(issue, Entity.from(thenExpression), DESCRIPTION))
report(CodeSmell(issue, Entity.from(thenExpression), issue.description))
}

val elseExpression = expression.`else` ?: return
if (mustBeOnSameLine(elseExpression) && hasNewLineAfter(expression.elseKeyword)) {
report(CodeSmell(issue, Entity.from(elseExpression), DESCRIPTION))
report(CodeSmell(issue, Entity.from(elseExpression), issue.description))
}
}

Expand Down