eslint: 1) config parsing: determine plugins/extends also inside package.json 2) optimize configs search, order configs properly (by the file tree position related to file)

This commit is contained in:
irengrig
2017-04-06 11:39:26 +02:00
parent 31410cb0b3
commit 3b4739c7dc

View File

@@ -1,8 +1,15 @@
package com.intellij.json;
import com.intellij.json.psi.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Mikhail Golubev
*/
@@ -34,4 +41,28 @@ public class JsonUtil {
}
return null;
}
@Nullable
public static <T extends JsonElement> T getPropertyValueOfType(@NotNull final JsonObject object, @NotNull final String name,
@NotNull final Class<T> clazz) {
final JsonProperty property = object.findProperty(name);
if (property == null) return null;
return ObjectUtils.tryCast(property.getValue(), clazz);
}
@Nullable
public static List<String> getChildAsStringList(@NotNull final JsonObject object, @NotNull final String name) {
final JsonArray array = getPropertyValueOfType(object, name, JsonArray.class);
if (array != null) return array.getValueList().stream().filter(value -> value instanceof JsonStringLiteral)
.map(value -> StringUtil.unquoteString(value.getText())).collect(Collectors.toList());
return null;
}
@Nullable
public static List<String> getChildAsSingleStringOrList(@NotNull final JsonObject object, @NotNull final String name) {
final List<String> list = getChildAsStringList(object, name);
if (list != null) return list;
final JsonStringLiteral literal = getPropertyValueOfType(object, name, JsonStringLiteral.class);
return literal == null ? null : Collections.singletonList(StringUtil.unquoteString(literal.getText()));
}
}