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