Forbid word 'can' in local inspections with level > INFORMATION

Inspection texts were changed accordingly
This commit is contained in:
Mikhail Glukhikh
2017-12-26 17:28:20 +03:00
parent 56230420f8
commit 2f987f08fa
13 changed files with 35 additions and 25 deletions
@@ -66,7 +66,7 @@ class CascadeIfInspection : AbstractKotlinInspection() {
holder.registerProblem(
expression.ifKeyword,
"Cascade if can be replaced with when",
"Cascade if should be replaced with when",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
IntentionWrapper(IfToWhenIntention(), expression.containingKtFile)
)
@@ -56,7 +56,7 @@ class JavaCollectionsStaticMethodInspection : AbstractKotlinInspection() {
val methodName = fqName.split(".").last()
holder.registerProblem(expression,
"Java Collections static method call can be replaced with Kotlin stdlib",
"Java Collections static method call should be replaced with Kotlin stdlib",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
ReplaceWithStdLibFix(methodName, firstArg.text))
}
@@ -37,11 +37,13 @@ class LiftReturnOrAssignmentInspection : AbstractKotlinInspection() {
val foldableReturns = BranchedFoldingUtils.getFoldableReturns(expression)
if (foldableReturns?.isNotEmpty() == true) {
val hasOtherReturns = expression.anyDescendantOfType<KtReturnExpression> { it !in foldableReturns }
val isSerious = !hasOtherReturns && foldableReturns.size > 1
val verb = if (isSerious) "should" else "can"
holder.registerProblemWithoutOfflineInformation(
keyword,
"Return can be lifted out of '${keyword.text}'",
"Return $verb be lifted out of '${keyword.text}'",
isOnTheFly,
if (!hasOtherReturns && foldableReturns.size > 1) ProblemHighlightType.GENERIC_ERROR_OR_WARNING
if (isSerious) ProblemHighlightType.GENERIC_ERROR_OR_WARNING
else ProblemHighlightType.INFORMATION,
LiftReturnOutFix(keyword.text)
)
@@ -49,9 +51,10 @@ class LiftReturnOrAssignmentInspection : AbstractKotlinInspection() {
}
val assignmentNumber = BranchedFoldingUtils.getFoldableAssignmentNumber(expression)
if (assignmentNumber > 0) {
val verb = if (assignmentNumber > 1) "should" else "can"
holder.registerProblemWithoutOfflineInformation(
keyword,
"Assignment can be lifted out of '${keyword.text}'",
"Assignment $verb be lifted out of '${keyword.text}'",
isOnTheFly,
if (assignmentNumber > 1) ProblemHighlightType.GENERIC_ERROR_OR_WARNING
else ProblemHighlightType.INFORMATION,
@@ -59,7 +59,7 @@ class ReplaceArrayOfWithLiteralInspection : AbstractKotlinInspection() {
val calleeName = calleeExpression.getReferencedName()
holder.registerProblem(
calleeExpression,
"'$calleeName' call can be replaced with array literal [...]",
"'$calleeName' call should be replaced with array literal [...]",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
ReplaceWithArrayLiteralFix()
)
@@ -60,7 +60,7 @@ class ReplacePutWithAssignmentInspection : AbstractApplicabilityBasedInspection<
override fun inspectionTarget(element: KtDotQualifiedExpression) = element.callExpression?.calleeExpression ?: element
override fun inspectionText(element: KtDotQualifiedExpression): String = "map.put() can be converted to assignment"
override fun inspectionText(element: KtDotQualifiedExpression): String = "map.put() should be converted to assignment"
override val defaultFixText = "Convert put to assignment"
@@ -35,7 +35,7 @@ class ReplaceRangeToWithUntilInspection : AbstractPrimitiveRangeToInspection() {
holder.registerProblem(
expression,
"'rangeTo' or the '..' call can be replaced with 'until'",
"'rangeTo' or the '..' call should be replaced with 'until'",
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
ReplaceWithUntilQuickFix()
)
@@ -65,7 +65,7 @@ class SimplifyAssertNotNullInspection : AbstractApplicabilityBasedInspection<KtC
return true
}
override fun inspectionText(element: KtCallExpression) = "assert can be replaced with operator"
override fun inspectionText(element: KtCallExpression) = "assert should be replaced with operator"
override val defaultFixText: String = "Replace assert with operator"
@@ -49,7 +49,7 @@ class SimplifyNegatedBinaryExpressionInspection : AbstractApplicabilityBasedInsp
override fun inspectionTarget(element: KtPrefixExpression) = element.operationReference
override fun inspectionText(element: KtPrefixExpression) = "Negated expression can be simplified"
override fun inspectionText(element: KtPrefixExpression) = "Negated expression should be simplified"
override val defaultFixText = "Simplify negated expression"
@@ -42,9 +42,9 @@ class UnnecessaryVariableInspection : AbstractApplicabilityBasedInspection<KtPro
override fun inspectionText(element: KtProperty) = when (statusFor(element)) {
Status.RETURN_ONLY ->
"Variable used only in following return and can be inlined"
"Variable used only in following return and should be inlined"
Status.EXACT_COPY ->
"Variable is an exact copy of another variable and can be inlined"
"Variable is same as '${(element.initializer as? KtNameReferenceExpression)?.getReferencedName()}' and should be inlined"
else -> ""
}
@@ -37,7 +37,7 @@ class WhenWithOnlyElseInspection : AbstractKotlinInspection() {
val usedAsExpression = expression.isUsedAsExpression(expression.analyze())
holder.registerProblem(expression,
"'when' has only 'else' branch and can be simplified",
"'when' has only 'else' branch and should be simplified",
SimplifyFix(usedAsExpression)
)
}
@@ -5,7 +5,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'rangeTo' or the '..' call can be replaced with 'until'</problem_class>
<description>'rangeTo' or the '..' call can be replaced with 'until'</description>
<description>'rangeTo' or the '..' call should be replaced with 'until'</description>
</problem>
<problem>
<file>test.kt</file>
@@ -13,6 +13,6 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'rangeTo' or the '..' call can be replaced with 'until'</problem_class>
<description>'rangeTo' or the '..' call can be replaced with 'until'</description>
<description>'rangeTo' or the '..' call should be replaced with 'until'</description>
</problem>
</problems>
@@ -7,7 +7,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/notIs.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -17,7 +17,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/notIn.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -27,7 +27,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/notEquals.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -37,7 +37,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/lessThanOrEquals.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -47,7 +47,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/lessThan.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -57,7 +57,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/is.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -67,7 +67,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/in.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -77,7 +77,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/greaterThanOrEquals.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -87,7 +87,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/greaterThan.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
<problem>
@@ -97,7 +97,7 @@
<entry_point TYPE="file" FQNAME="temp:///src/equals.kt"/>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified
</problem_class>
<description>Negated expression can be simplified</description>
<description>Negated expression should be simplified</description>
</problem>
</problems>
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.inspections
import com.google.common.collect.Lists
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFile
@@ -137,6 +138,12 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
"Expected at least one problem at caret",
problemExpected == problemDescriptors.isNotEmpty())
if (!problemExpected) return false
problemDescriptors
.filter { it.highlightType != ProblemHighlightType.INFORMATION }
.forEach {
Assert.assertTrue("Problem description should not contain 'can': ${it.descriptionTemplate}",
" can " !in it.descriptionTemplate)
}
if (problemExpectedString != null) {
Assert.assertTrue("Expected the following problem at caret: $problemExpectedString\n" +
"Active problems: ${problemDescriptors.joinToString { it.descriptionTemplate }}",