Do not report code style warnings on overridden declarations (KT-25416)

#KT-25416 Fixed
This commit is contained in:
Nikolay Krasko
2018-07-16 12:13:03 +03:00
parent b6db8971e4
commit 5b34498162
5 changed files with 34 additions and 9 deletions
@@ -134,6 +134,9 @@ class FunctionNameInspection : NamingConventionInspection(
) {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return namedFunctionVisitor { function ->
if (function.hasModifier(KtTokens.OVERRIDE_KEYWORD)) {
return@namedFunctionVisitor
}
if (!TestUtils.isInTestSourceContent(function)) {
verifyName(function, holder)
}
@@ -170,6 +173,10 @@ abstract class PropertyNameInspectionBase protected constructor(
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return propertyVisitor { property ->
if (property.hasModifier(KtTokens.OVERRIDE_KEYWORD)) {
return@propertyVisitor
}
if (property.getKind() == kind) {
verifyName(property, holder)
}
@@ -2,23 +2,22 @@
<problem>
<file>test.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<description>Function name &lt;code&gt;Foo&lt;/code&gt; should start with a lowercase letter #loc</description>
</problem>
<problem>
<file>test.kt</file>
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<description>Function name &lt;code&gt;FOO_BAR&lt;/code&gt; should not contain underscores #loc</description>
</problem>
<problem>
<file>test.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Class naming convention</problem_class>
<description>Function name &lt;code&gt;`a b`&lt;/code&gt; may contain only letters and digits #loc</description>
</problem>
<problem>
<file>test.kt</file>
<line>10</line>
<description>Function name &lt;code&gt;a_b&lt;/code&gt; should not contain underscores #loc</description>
</problem>
</problems>
+9 -1
View File
@@ -4,4 +4,12 @@ fun FOO_BAR() {}
fun xyzzy() {}
fun `a b`() {}
fun `a b`() {}
interface I {
fun a_b()
}
class C : I {
override fun a_b() {} // Shouldn't be reported
}
@@ -2,8 +2,11 @@
<problem>
<file>test.kt</file>
<line>27</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<description>Property name &lt;code&gt;_Foo&lt;/code&gt; should not start with an underscore #loc</description>
</problem>
<problem>
<file>test.kt</file>
<line>37</line>
<description>Property name &lt;code&gt;Foo&lt;/code&gt; should start with a lowercase letter #loc</description>
</problem>
</problems>
+8
View File
@@ -31,4 +31,12 @@ class D {
var FOO_BAR: Int = 0
}
}
interface I {
val Foo: Int
}
class C : I {
override override val Foo = 1
}