diff --git a/src/main/kotlin/org/vlang/ide/inspections/namingConventions/VlangVarNamingConventionInspection.kt b/src/main/kotlin/org/vlang/ide/inspections/namingConventions/VlangVarNamingConventionInspection.kt new file mode 100644 index 00000000..20a0e7d5 --- /dev/null +++ b/src/main/kotlin/org/vlang/ide/inspections/namingConventions/VlangVarNamingConventionInspection.kt @@ -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") + } + } + } +} diff --git a/src/main/resources/META-INF/inspections.xml b/src/main/resources/META-INF/inspections.xml index f2d35e20..4d703a77 100644 --- a/src/main/resources/META-INF/inspections.xml +++ b/src/main/resources/META-INF/inspections.xml @@ -146,6 +146,12 @@ enabledByDefault="true" level="ERROR" implementationClass="org.vlang.ide.inspections.namingConventions.VlangClassLikeNamingConventionInspection"/> + + + +Reports variables whose names do not follow the naming convention. + + \ No newline at end of file diff --git a/src/test/kotlin/org/vlang/ide/inspections/VlangNamingConventionsInspectionsTest.kt b/src/test/kotlin/org/vlang/ide/inspections/VlangNamingConventionsInspectionsTest.kt index 78c9d23f..fc40747a 100644 --- a/src/test/kotlin/org/vlang/ide/inspections/VlangNamingConventionsInspectionsTest.kt +++ b/src/test/kotlin/org/vlang/ide/inspections/VlangNamingConventionsInspectionsTest.kt @@ -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() diff --git a/src/test/resources/inspections/namingConventions/variables.v b/src/test/resources/inspections/namingConventions/variables.v new file mode 100644 index 00000000..ba9a681f --- /dev/null +++ b/src/test/resources/inspections/namingConventions/variables.v @@ -0,0 +1,4 @@ +module main +fn main() { + InvalidVarName := 1 +} \ No newline at end of file