Skip to content

Commit

Permalink
#8 .rule()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 19, 2024
1 parent 5f3b6d2 commit 9e4e78a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/main/java/org/eolang/lints/Defect.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
*/
public interface Defect {

/**
* Rule.
* @return Unique name of the rule
*/
String rule();

/**
* Severity.
* @return Severity
Expand All @@ -54,6 +60,11 @@ public interface Defect {
* @since 0.0.1
*/
final class Default implements Defect {
/**
* Rule.
*/
private final String rle;

/**
* Severity.
*/
Expand All @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/eolang/lints/LintByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +43,11 @@
*/
final class LintByXsl implements Lint {

/**
* The name of the rule.
*/
private final String rule;

/**
* The stylesheet.
*/
Expand All @@ -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());
}

/**
Expand All @@ -80,6 +89,7 @@ public Collection<Defect> 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)
Expand Down

0 comments on commit 9e4e78a

Please sign in to comment.