-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handlebars inspection for 'if'/'each' built-in helpers tests е
Conflicts: handlebars/src/com/dmarcotte/handlebars/inspections/HbBlockMismatchAnnotator.java handlebars/src/com/dmarcotte/handlebars/inspections/HbBlockMismatchInspection.java src/com/dmarcotte/handlebars/inspections/HbBlockMismatchInspection.java
- Loading branch information
1 parent
e292cf6
commit daa6c8e
Showing
8 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
Handlebars block helpers "if", "each" and some others usually require a parameter | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/com/dmarcotte/handlebars/inspections/HbEmptyBlockInspection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.dmarcotte.handlebars.inspections; | ||
|
||
|
||
import com.dmarcotte.handlebars.HbBundle; | ||
import com.dmarcotte.handlebars.psi.HbOpenBlockMustache; | ||
import com.dmarcotte.handlebars.psi.HbParam; | ||
import com.intellij.codeInspection.LocalInspectionTool; | ||
import com.intellij.codeInspection.ProblemsHolder; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiElementVisitor; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.util.containers.ContainerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
|
||
public class HbEmptyBlockInspection extends LocalInspectionTool { | ||
private static final Set<String> HELPERS_WITH_ARGUMENTS = ContainerUtil.immutableSet("if", "each", "with"); | ||
|
||
@NotNull | ||
@Override | ||
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
return new PsiElementVisitor() { | ||
|
||
@Override | ||
public void visitElement(PsiElement element) { | ||
if (!(element instanceof HbOpenBlockMustache)) { | ||
return; | ||
} | ||
|
||
String name = ((HbOpenBlockMustache)element).getName(); | ||
if (HELPERS_WITH_ARGUMENTS.contains(name) && | ||
null == PsiTreeUtil.getChildrenOfType(element, HbParam.class)) { | ||
holder.registerProblem(element, HbBundle.message("hb.block.mismatch.inspection.empty.block", name)); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<problems> | ||
<problem> | ||
<file>test.hbs</file> | ||
<line>3</line> | ||
<description>Block helper each usually requires a parameter</description> | ||
</problem> | ||
<problem> | ||
<file>test.hbs</file> | ||
<line>5</line> | ||
<description>Block helper if usually requires a parameter</description> | ||
</problem> | ||
</problems> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{#if aaa}} | ||
{{aaa}} | ||
{{#each}} | ||
{{aaa}} | ||
{{#if}} | ||
{{aaa}} | ||
{{#each bbb}} | ||
{{aaa}}{{aaa}} | ||
{{/each}} | ||
{{/if}} | ||
{{/each}} | ||
{{/if}} |
35 changes: 35 additions & 0 deletions
35
test/src/com/dmarcotte/handlebars/inspections/HbInspectionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.dmarcotte.handlebars.inspections; | ||
|
||
|
||
import com.dmarcotte.handlebars.util.HbTestUtils; | ||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; | ||
import com.intellij.testFramework.PlatformTestCase; | ||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class HbInspectionsTest extends LightPlatformCodeInsightFixtureTestCase { | ||
|
||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") | ||
public HbInspectionsTest() { | ||
PlatformTestCase.initPlatformLangPrefix(); | ||
} | ||
|
||
@Override | ||
protected boolean isWriteActionRequired() { | ||
return false; | ||
} | ||
|
||
public void testEmptyBlock() { | ||
doTest(); | ||
} | ||
|
||
private void doTest() { | ||
myFixture.testInspection(getTestName(false), new LocalInspectionToolWrapper(new HbEmptyBlockInspection())); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected String getTestDataPath() { | ||
return HbTestUtils.BASE_TEST_DATA_PATH + "/inspections"; | ||
} | ||
} |