This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for bracket notation & duplicate goog.require/provide sta…
…tements (v. 1.1.0). Closes #5
- Loading branch information
Showing
10 changed files
with
174 additions
and
131 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
<idea-plugin> | ||
<id>de.veihelmann.closureplugin</id> | ||
<name>Inspections for Google™ Closure</name> | ||
<version>1.0.2</version> | ||
<version>1.1.0</version> | ||
<vendor email="[email protected]">Daniel Veihelmann</vendor> | ||
|
||
<description><![CDATA[ | ||
This plugin enhances IntelliJ's support for Google Closure. It can determine missing or obsolete 'goog.require' | ||
statements and offers corresponding quick-fixes. | ||
This plugin enhances IntelliJ's support for Google Closure. It can determine missing/obsolete/duplicate 'goog.require' | ||
statements and offers corresponding quick-fixes. In addition, there is an inspection and quick-fix for usages of bracket notation (instead of dot notation) for accessing properties. | ||
More info & source code: https://github.com/Dan1ve/ClosureInspectionsPlugin | ||
]]></description> | ||
|
||
<change-notes><![CDATA[ | ||
Small bugfixes | ||
- New inspection to avoid bracket notation (e.g. myVar['myField']), which cannot be type-checked by the Closure compiler. | ||
- Duplicate goog.require/goog.provide statements are now reported, too. | ||
]]> | ||
</change-notes> | ||
|
||
|
@@ -26,6 +27,7 @@ | |
<inspectionToolProvider id="closureinspectionsprovider" | ||
implementation="de.veihelmann.closureplugin.ClosureInspectionsProvider" | ||
order="LAST"/> | ||
|
||
</extensions> | ||
|
||
<actions> | ||
|
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
111 changes: 0 additions & 111 deletions
111
src/de/veihelmann/closureplugin/ConvertToES6ClassInspection.java
This file was deleted.
Oops, something went wrong.
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
62 changes: 62 additions & 0 deletions
62
src/de/veihelmann/closureplugin/UseOfBracketNotationInspection.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,62 @@ | ||
package de.veihelmann.closureplugin; | ||
|
||
import com.intellij.codeInsight.daemon.GroupNames; | ||
import com.intellij.codeInspection.LocalInspectionTool; | ||
import com.intellij.codeInspection.ProblemsHolder; | ||
import com.intellij.lang.javascript.psi.JSIndexedPropertyAccessExpression; | ||
import com.intellij.lang.javascript.psi.JSLiteralExpression; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiElementVisitor; | ||
import de.veihelmann.closureplugin.fixes.BracketNotationFix; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Checks for usages of bracket notation (e.g. myVar['fieldName']), which cannot be type-checked by the Closure compiler. | ||
* Quick fix is to use dot notation (myVar.fieldName) instead. | ||
*/ | ||
public class UseOfBracketNotationInspection extends LocalInspectionTool { | ||
|
||
@NotNull | ||
@Override | ||
public String getShortName() { | ||
return "UseOfBracketNotationInspection"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { | ||
return new PsiElementVisitor() { | ||
@Override | ||
public void visitElement(PsiElement element) { | ||
super.visitElement(element); | ||
|
||
if (element instanceof JSIndexedPropertyAccessExpression) { | ||
checkBracketNotation((JSIndexedPropertyAccessExpression) element, holder); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@NotNull | ||
public String getDisplayName() { | ||
return "Checks for uses of bracket notation"; | ||
} | ||
|
||
@NotNull | ||
public String getGroupDisplayName() { | ||
return GroupNames.PROPERTIES_GROUP_NAME; | ||
} | ||
|
||
public boolean isEnabledByDefault() { | ||
return true; | ||
} | ||
|
||
private void checkBracketNotation(JSIndexedPropertyAccessExpression accessElement, ProblemsHolder problemsHolder) { | ||
JSLiteralExpression literal = (JSLiteralExpression) Arrays.stream(accessElement.getChildren()).filter(element -> element instanceof JSLiteralExpression).findFirst().orElse(null); | ||
if (literal != null && literal.getText().matches("[\"']\\w+['\"]")) { | ||
problemsHolder.registerProblem(accessElement, "Access of property " + literal.getText() + " cannot be type-checked (bracket notation)", new BracketNotationFix(literal)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.