WEB-25928 webpack config inspection incorrectly flags "empty" as invalid value for node.fs

This commit is contained in:
irengrig
2017-03-16 09:56:22 +01:00
parent 57486388c0
commit e07e38be3e
3 changed files with 20 additions and 2 deletions
@@ -356,14 +356,26 @@ public class JsonBySchemaObjectAnnotator implements Annotator {
private void checkForEnum(PsiElement value, JsonSchemaObject schema) {
//enum values + pattern -> don't check enum values
if (schema.getEnum() == null || schema.getPattern() != null) return;
final String text = value.getText();
final String text = StringUtil.notNullize(value.getText());
final List<Object> objects = schema.getEnum();
for (Object object : objects) {
if (object.toString().equalsIgnoreCase(text)) return;
if (myWalker.onlyDoubleQuotesForStringLiterals()) {
if (object.toString().equalsIgnoreCase(text)) return;
} else {
if (equalsIgnoreQuotesAndCase(object.toString(), text)) return;
}
}
error("Value should be one of: [" + StringUtil.join(objects, o -> o.toString(), ", ") + "]", value);
}
private static boolean equalsIgnoreQuotesAndCase(@NotNull final String s1, @NotNull final String s2) {
final boolean quoted1 = StringUtil.isQuotedString(s1);
final boolean quoted2 = StringUtil.isQuotedString(s2);
if (quoted1 != quoted2) return false;
if (!quoted1) return s1.equalsIgnoreCase(s2);
return StringUtil.unquoteString(s1).equalsIgnoreCase(StringUtil.unquoteString(s2));
}
private void checkArray(JsonValueAdapter value, JsonSchemaObject schema) {
final JsonArrayValueAdapter asArray = value.getAsArray();
if (asArray == null) return;
@@ -32,6 +32,7 @@ public interface JsonLikePsiWalker {
PsiElement goUpToCheckable(@NotNull final PsiElement element);
List<JsonSchemaWalker.Step> findPosition(@NotNull final PsiElement element, boolean isName, boolean forceLastTransition);
boolean isNameQuoted();
boolean onlyDoubleQuotesForStringLiterals();
boolean hasPropertiesBehindAndNoComma(@NotNull PsiElement element);
Set<String> getPropertyNamesOfParentObject(@NotNull PsiElement element);
@Nullable JsonPropertyAdapter getParentPropertyAdapter(@NotNull PsiElement element);
@@ -121,6 +121,11 @@ public class JsonOriginalPsiWalker implements JsonLikePsiWalker {
return true;
}
@Override
public boolean onlyDoubleQuotesForStringLiterals() {
return true;
}
@Override
public boolean hasPropertiesBehindAndNoComma(@NotNull PsiElement element) {
PsiElement current = element instanceof JsonProperty ? element : PsiTreeUtil.getParentOfType(element, JsonProperty.class);