From 9e4e78ac49284297dbdf6c7c079317e78b9636fb Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 19 Nov 2024 07:28:07 +0300 Subject: [PATCH] #8 .rule() --- src/main/java/org/eolang/lints/Defect.java | 22 ++++++++++++++++++- src/main/java/org/eolang/lints/LintByXsl.java | 14 ++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/eolang/lints/Defect.java b/src/main/java/org/eolang/lints/Defect.java index 6815dcae..c3d6e642 100644 --- a/src/main/java/org/eolang/lints/Defect.java +++ b/src/main/java/org/eolang/lints/Defect.java @@ -30,6 +30,12 @@ */ public interface Defect { + /** + * Rule. + * @return Unique name of the rule + */ + String rule(); + /** * Severity. * @return Severity @@ -54,6 +60,11 @@ public interface Defect { * @since 0.0.1 */ final class Default implements Defect { + /** + * Rule. + */ + private final String rle; + /** * Severity. */ @@ -71,16 +82,25 @@ final class Default implements Defect { /** * Ctor. + * @param rule Rule * @param severity Severity * @param line Line number * @param text Description of the defect + * @checkstyle ParameterNumberCheck (5 lines) */ - Default(final Severity severity, final int line, final String text) { + Default(final String rule, final Severity severity, + final int line, final String text) { + this.rle = rule; this.sev = severity; this.lineno = line; this.txt = text; } + @Override + public String rule() { + return this.rle; + } + @Override public Severity severity() { return this.sev; diff --git a/src/main/java/org/eolang/lints/LintByXsl.java b/src/main/java/org/eolang/lints/LintByXsl.java index 4e2e1d24..59238884 100644 --- a/src/main/java/org/eolang/lints/LintByXsl.java +++ b/src/main/java/org/eolang/lints/LintByXsl.java @@ -25,6 +25,7 @@ import com.jcabi.xml.ClasspathSources; import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; import com.jcabi.xml.XSL; import com.jcabi.xml.XSLDocument; import java.io.IOException; @@ -42,6 +43,11 @@ */ final class LintByXsl implements Lint { + /** + * The name of the rule. + */ + private final String rule; + /** * The stylesheet. */ @@ -52,12 +58,15 @@ final class LintByXsl implements Lint { * @param xsl Relative path of XSL * @throws IOException If fails */ + @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") LintByXsl(final Input xsl) throws IOException { - this.sheet = new XSLDocument( + final XML xml = new XMLDocument( new IoCheckedText( new TextOf(xsl) ).asString() - ).with(new ClasspathSources()); + ); + this.rule = xml.xpath("/xsl:stylesheet/@id").get(0); + this.sheet = new XSLDocument(xml).with(new ClasspathSources()); } /** @@ -80,6 +89,7 @@ public Collection defects(final XML xmir) { for (final XML defect : report.nodes("/defects/defect")) { defects.add( new Defect.Default( + this.rule, Severity.parsed(defect.xpath("@severity").get(0)), Integer.parseInt(defect.xpath("@line").get(0)), defect.xpath("text()").get(0)