master-inspectopedia-collector

Cleaner checks for br element

Merge branch 'master' into master-inspectopedia-collector

Collecting CWE ids


Merge-request: IJ-MR-126396
Merged-by: Egor Malyshev <egor.malyshev@jetbrains.com>

GitOrigin-RevId: 6bec313f9bf5a255bd81e922ed2e0b34fc6e4304
This commit is contained in:
Egor Malyshev
2024-02-19 14:34:45 +00:00
committed by intellij-monorepo-bot
parent 0b5363a00e
commit 63d7aa8192
3 changed files with 136 additions and 126 deletions

View File

@@ -8,8 +8,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.json.JsonMapper;
import com.intellij.codeInspection.InspectionEP; import com.intellij.codeInspection.InspectionEP;
import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.ex.ScopeToolState;
import com.intellij.codeInspection.options.*; import com.intellij.codeInspection.options.*;
import com.intellij.ide.plugins.PluginManager; import com.intellij.ide.plugins.PluginManager;
import com.intellij.inspectopedia.extractor.data.Inspection; import com.intellij.inspectopedia.extractor.data.Inspection;
@@ -18,6 +17,7 @@ import com.intellij.inspectopedia.extractor.data.Plugin;
import com.intellij.inspectopedia.extractor.data.Plugins; import com.intellij.inspectopedia.extractor.data.Plugins;
import com.intellij.inspectopedia.extractor.utils.HtmlUtils; import com.intellij.inspectopedia.extractor.utils.HtmlUtils;
import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationStarter; import com.intellij.openapi.application.ApplicationStarter;
import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
@@ -97,6 +97,11 @@ final class InspectopediaExtractor implements ApplicationStarter {
availablePlugins.put(IDE_NAME, new Plugin(IDE_NAME, IDE_NAME, IDE_VERSION)); availablePlugins.put(IDE_NAME, new Plugin(IDE_NAME, IDE_NAME, IDE_VERSION));
final InspectionMetaInformationService
service = ApplicationManager.getApplication().getService(InspectionMetaInformationService.class);
final MetaInformationState inspectionsExtraState = service == null ? null : (MetaInformationState)service.getState(null);
for (final ScopeToolState scopeToolState : scopeToolStates) { for (final ScopeToolState scopeToolState : scopeToolStates) {
final InspectionToolWrapper<?, ?> wrapper = scopeToolState.getTool(); final InspectionToolWrapper<?, ?> wrapper = scopeToolState.getTool();
@@ -118,13 +123,16 @@ final class InspectopediaExtractor implements ApplicationStarter {
catch (Throwable t) { catch (Throwable t) {
LOG.info("Cannot create options panel " + wrapper.getShortName(), t); LOG.info("Cannot create options panel " + wrapper.getShortName(), t);
} }
final MetaInformation metaInformation = inspectionsExtraState == null ? null : inspectionsExtraState.getInspections().get(wrapper.getID());
final List<Integer> cweIds = metaInformation == null ? null : metaInformation.getCweIds();
final String language = wrapper.getLanguage(); final String language = wrapper.getLanguage();
final String briefDescription = HtmlUtils.cleanupHtml(description[0], language); final String briefDescription = HtmlUtils.cleanupHtml(description[0], language);
final String extendedDescription = description.length > 1 ? HtmlUtils.cleanupHtml(description[1], language) : null; final String extendedDescription = description.length > 1 ? HtmlUtils.cleanupHtml(description[1], language) : null;
final Inspection inspection = new Inspection(wrapper.getShortName(), wrapper.getDisplayName(), wrapper.getDefaultLevel().getName(), final Inspection inspection = new Inspection(wrapper.getShortName(), wrapper.getDisplayName(), wrapper.getDefaultLevel().getName(),
language, briefDescription, language, briefDescription,
extendedDescription, Arrays.asList(wrapper.getGroupPath()), wrapper.applyToDialects(), extendedDescription, Arrays.asList(wrapper.getGroupPath()), wrapper.applyToDialects(),
wrapper.isCleanupTool(), wrapper.isEnabledByDefault(), panelInfo); wrapper.isCleanupTool(), wrapper.isEnabledByDefault(), panelInfo, cweIds);
availablePlugins.get(pluginId).addInspection(inspection); availablePlugins.get(pluginId).addInspection(inspection);
} }

View File

@@ -27,6 +27,7 @@ public class Inspection implements Comparable<Inspection> {
public String extendedDescription = ""; public String extendedDescription = "";
public boolean hasOptionsPanel = false; public boolean hasOptionsPanel = false;
public List<OptionsPanelInfo> options = null; public List<OptionsPanelInfo> options = null;
public List<Integer> cweIds = null;
public Inspection(String id, public Inspection(String id,
String name, String name,
@@ -38,7 +39,8 @@ public class Inspection implements Comparable<Inspection> {
boolean appliesToDialects, boolean appliesToDialects,
boolean partOfCodeCleanup, boolean partOfCodeCleanup,
boolean enabledByDefault, boolean enabledByDefault,
List<OptionsPanelInfo> options) { List<OptionsPanelInfo> options,
List<Integer> cweIds) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.severity = severity; this.severity = severity;
@@ -51,6 +53,7 @@ public class Inspection implements Comparable<Inspection> {
this.isEnabledDefault = enabledByDefault; this.isEnabledDefault = enabledByDefault;
this.hasOptionsPanel = options != null; this.hasOptionsPanel = options != null;
this.options = options; this.options = options;
this.cweIds = cweIds;
} }
public Inspection() { public Inspection() {

View File

@@ -114,7 +114,8 @@ public final class HtmlUtils {
do { do {
paragraphsWithParagraphs = document.select("p:has(p)"); paragraphsWithParagraphs = document.select("p:has(p)");
paragraphsWithParagraphs.unwrap(); paragraphsWithParagraphs.unwrap();
} while (!paragraphsWithParagraphs.isEmpty()); }
while (!paragraphsWithParagraphs.isEmpty());
//And then there were multi nested paragraphs which deep down contained nothing but whitespace? Now they're ready for removal as well :) //And then there were multi nested paragraphs which deep down contained nothing but whitespace? Now they're ready for removal as well :)
final Elements emptyParagraphs = document.select("p:matches(^\\s*$)"); final Elements emptyParagraphs = document.select("p:matches(^\\s*$)");
emptyParagraphs.remove(); emptyParagraphs.remove();
@@ -129,18 +130,16 @@ public final class HtmlUtils {
} }
private static boolean isBlockElement(@NotNull Node node) { private static boolean isBlockElement(@NotNull Node node) {
if (!(node instanceof Element element)) if (!(node instanceof Element element)) {
return false; return false;
}
return element.tagName().equals("list") || return "list".equals(element.tagName()) ||
(element.tagName().equals("code") && element.attr("style").equals("block")) || ("code".equals(element.tagName()) && "block".equals(element.attr("style"))) ||
isBr(node); isBr(node);
} }
private static boolean isBr(@NotNull Node node) { private static boolean isBr(@NotNull Node node) {
if (!(node instanceof Element)) return node instanceof Element element && "br".equals(element.tagName());
return false;
return "br".equals(((Element) node).tagName());
} }
} }