diff --git a/plugins/env-files-support/src/main/java/ru/adelf/idea/dotenv/inspections/IncorrectDelimiterInspection.java b/plugins/env-files-support/src/main/java/ru/adelf/idea/dotenv/inspections/IncorrectDelimiterInspection.java
new file mode 100644
index 000000000000..11d5f17c832e
--- /dev/null
+++ b/plugins/env-files-support/src/main/java/ru/adelf/idea/dotenv/inspections/IncorrectDelimiterInspection.java
@@ -0,0 +1,80 @@
+package ru.adelf.idea.dotenv.inspections;
+
+import com.intellij.codeInspection.*;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import ru.adelf.idea.dotenv.DotEnvFactory;
+import ru.adelf.idea.dotenv.psi.DotEnvFile;
+import ru.adelf.idea.dotenv.psi.DotEnvTypes;
+import ru.adelf.idea.dotenv.psi.impl.DotEnvKeyImpl;
+
+public class IncorrectDelimiterInspection extends LocalInspectionTool {
+ // Change the display name within the plugin.xml
+ // This needs to be here as otherwise the tests will throw errors.
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return "Incorrect delimiter";
+ }
+
+ @Override
+ public boolean runForWholeFile() {
+ return true;
+ }
+
+ @Nullable
+ @Override
+ public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
+ if (!(file instanceof DotEnvFile)) {
+ return null;
+ }
+
+ return analyzeFile(file, manager, isOnTheFly).getResultsArray();
+ }
+
+ @NotNull
+ private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
+ ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
+
+ PsiTreeUtil.findChildrenOfType(file, DotEnvKeyImpl.class).forEach(key -> {
+ if (key.getText().contains("-")) {
+ problemsHolder.registerProblem(key, "Expected: '_' Found: '-'", new ReplaceDelimiterQuickFix());
+ }
+ });
+
+ return problemsHolder;
+ }
+
+ private static class ReplaceDelimiterQuickFix implements LocalQuickFix {
+
+ @NotNull
+ @Override
+ public String getName() {
+ return "Replace delimiter";
+ }
+
+ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
+ try {
+ PsiElement psiElement = descriptor.getPsiElement();
+
+ PsiElement newPsiElement = DotEnvFactory.createFromText(project, DotEnvTypes.KEY,
+ psiElement.getText().replace("-","_")+"=dummy");
+
+ psiElement.replace(newPsiElement);
+ } catch (IncorrectOperationException e) {
+ Logger.getInstance(IncorrectDelimiterInspection.class).error(e);
+ }
+ }
+
+ @NotNull
+ public String getFamilyName() {
+ return getName();
+ }
+ }
+}
diff --git a/plugins/env-files-support/src/main/resources/META-INF/plugin.xml b/plugins/env-files-support/src/main/resources/META-INF/plugin.xml
index a58afc4c5eb9..2b1bde9afe89 100644
--- a/plugins/env-files-support/src/main/resources/META-INF/plugin.xml
+++ b/plugins/env-files-support/src/main/resources/META-INF/plugin.xml
@@ -110,6 +110,14 @@
level="WARNING"
implementationClass="ru.adelf.idea.dotenv.inspections.ExtraBlankLineInspection"/>
+
+
diff --git a/plugins/env-files-support/src/main/resources/inspectionDescriptions/DotEnvIncorrectDelimiterInspection.html b/plugins/env-files-support/src/main/resources/inspectionDescriptions/DotEnvIncorrectDelimiterInspection.html
new file mode 100644
index 000000000000..656e6688896f
--- /dev/null
+++ b/plugins/env-files-support/src/main/resources/inspectionDescriptions/DotEnvIncorrectDelimiterInspection.html
@@ -0,0 +1,5 @@
+
+
+Reports incorrect delimiter in .env files ('-' instead of'_').
+
+
\ No newline at end of file
diff --git a/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/InspectionsTest.java b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/InspectionsTest.java
index 7ccfa7eb93f7..8d55be221140 100644
--- a/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/InspectionsTest.java
+++ b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/InspectionsTest.java
@@ -1,9 +1,11 @@
package ru.adelf.idea.dotenv.tests.dotenv;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
+import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.InspectionProfileEntry;
import ru.adelf.idea.dotenv.inspections.DuplicateKeyInspection;
import ru.adelf.idea.dotenv.inspections.ExtraBlankLineInspection;
+import ru.adelf.idea.dotenv.inspections.IncorrectDelimiterInspection;
import ru.adelf.idea.dotenv.inspections.SpaceInsideNonQuotedInspection;
import ru.adelf.idea.dotenv.tests.DotEnvLightCodeInsightFixtureTestCase;
@@ -24,6 +26,8 @@ public class InspectionsTest extends DotEnvLightCodeInsightFixtureTestCase {
return basePath + "dotenv/fixtures";
}
+ // Test for each Inspection
+
public void testDuplicateKey() {
doInspectionTest(new DuplicateKeyInspection(), Arrays.asList("DUPLICATE_KEY=test", "DUPLICATE_KEY=test2"));
}
@@ -36,6 +40,22 @@ public class InspectionsTest extends DotEnvLightCodeInsightFixtureTestCase {
doInspectionTest(new ExtraBlankLineInspection(), Collections.singletonList("\n\n\n"));
}
+ public void testIncorrectDelimiterInspection() {
+ doInspectionTest(new IncorrectDelimiterInspection(), Collections.singletonList("INCORRECT-DELIMITER"));
+ }
+
+ // Every available quickfix from every inspection is getting applied
+ public void testQuickFixes() {
+ myFixture.enableInspections(new SpaceInsideNonQuotedInspection());
+ myFixture.enableInspections(new ExtraBlankLineInspection());
+ myFixture.enableInspections(new IncorrectDelimiterInspection());
+
+ myFixture.doHighlighting();
+ List intentionActions = myFixture.getAllQuickFixes();
+ intentionActions.forEach(intentionAction -> myFixture.launchAction(intentionAction));
+ myFixture.checkResultByFile("quickFix.env");
+ }
+
private void doInspectionTest(InspectionProfileEntry entry, List expectedHighlightedText) {
myFixture.enableInspections(entry);
diff --git a/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/inspections.env b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/inspections.env
index e6ca7d14ef30..46a4f60baff3 100644
--- a/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/inspections.env
+++ b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/inspections.env
@@ -6,4 +6,6 @@ SPACE_INSIDE_NON_QUOTED=spaces without quotes
# extra blank lines test START
-# extra blank lines test END
\ No newline at end of file
+# extra blank lines test END
+
+INCORRECT-DELIMITER=test-test
\ No newline at end of file
diff --git a/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/quickFix.env b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/quickFix.env
new file mode 100644
index 000000000000..0b354b2ca67e
--- /dev/null
+++ b/plugins/env-files-support/src/test/java/ru/adelf/idea/dotenv/tests/dotenv/fixtures/quickFix.env
@@ -0,0 +1,11 @@
+DUPLICATE_KEY=test
+DUPLICATE_KEY=test2
+
+SPACE_INSIDE_NON_QUOTED="spaces without quotes"
+
+# extra blank lines test START
+
+
+# extra blank lines test END
+
+INCORRECT_DELIMITER=test-test
\ No newline at end of file