Skip to content

Commit

Permalink
added variables naming convention inspection (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
saturn4er authored Mar 24, 2023
1 parent db9d6b4 commit 43c6f74
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.vlang.ide.inspections.namingConventions

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElementVisitor
import org.vlang.lang.psi.VlangVarDefinition
import org.vlang.lang.psi.VlangVisitor

class VlangVarNamingConventionInspection : VlangNamingConventionInspectionBase() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return object : VlangVisitor() {
override fun visitVarDefinition(o: VlangVarDefinition) {
super.visitVarDefinition(o)
holder.checkSnakeCase(o, "Variable")
}
}
}
}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
enabledByDefault="true" level="ERROR"
implementationClass="org.vlang.ide.inspections.namingConventions.VlangClassLikeNamingConventionInspection"/>

<localInspection language="vlang" groupPath="V"
groupName="Naming conventions" shortName="VlangVarNamingConventionInspection"
displayName="Variable naming convention"
enabledByDefault="true" level="ERROR"
implementationClass="org.vlang.ide.inspections.namingConventions.VlangVarNamingConventionInspection"/>

<localInspection language="vlang" groupPath="V"
groupName="Naming conventions" shortName="VlangTypeAliasNamingConventionInspection"
displayName="Type alias naming convention"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Reports variables whose names do not follow the naming convention.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class VlangNamingConventionsInspectionsTest : InspectionTestBase("namingConventi
fun `test generic receivers names`() = doTest("generic_receivers_names.v", VlangReceiverNamesInspection())
fun `test different receivers names`() = doTest("different_receivers_names.v", VlangReceiverNamesInspection())

fun `test var names`() = doTest("variables.v", VlangVarNamingConventionInspection())

companion object {
val FUNCTION = VlangFunctionNamingConventionInspection()
val CLASS_LIKE = VlangClassLikeNamingConventionInspection()
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/inspections/namingConventions/variables.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module main
fn main() {
<error descr="Variable name cannot contain uppercase letters, use snake_case instead">InvalidVarName</error> := 1
}

0 comments on commit 43c6f74

Please sign in to comment.