Skip to content

Commit

Permalink
#4: works
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 18, 2024
1 parent c156a2e commit 3570aa2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ SOFTWARE.
<artifactId>jcabi-xml</artifactId>
<version>0.30.1</version>
</dependency>
<dependency>
<groupId>io.github.secretx33</groupId>
<artifactId>path-matching-resource-pattern-resolver</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/org/eolang/lints/LintByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
*/
package org.eolang.lints;

import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.XML;
import com.jcabi.xml.XSL;
import com.jcabi.xml.XSLDocument;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import org.cactoos.Input;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.IoCheckedText;
import org.cactoos.text.TextOf;
Expand All @@ -50,15 +52,24 @@ final class LintByXsl implements Lint {
* @param xsl Relative path of XSL
* @throws IOException If fails
*/
LintByXsl(final String xsl) throws IOException {
LintByXsl(final Input xsl) throws IOException {
this.sheet = new XSLDocument(
new IoCheckedText(
new TextOf(
new ResourceOf(
String.format("org/eolang/lints/%s.xsl", xsl)
)
)
new TextOf(xsl)
).asString()
).with(new ClasspathSources());
}

/**
* Ctor.
* @param xsl Relative path of XSL
* @throws IOException If fails
*/
LintByXsl(final String xsl) throws IOException {
this(
new ResourceOf(
String.format("org/eolang/lints/%s.xsl", xsl)
)
);
}

Expand Down
31 changes: 24 additions & 7 deletions src/main/java/org/eolang/lints/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
*/
package org.eolang.lints;

import io.github.secretx33.resourceresolver.PathMatchingResourcePatternResolver;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import org.cactoos.io.InputOf;
import org.cactoos.iterable.Mapped;

/**
Expand All @@ -40,13 +42,7 @@ public final class Scope {
/**
* Lints to use.
*/
private static final Iterable<Lint> LINTS = new Mapped<>(
LintByXsl::new,
Arrays.asList(
"critical/duplicate-names",
"critical/not-empty-atoms"
)
);
private static final Iterable<Lint> LINTS = Scope.all();

/**
* Directory with XMIR files.
Expand Down Expand Up @@ -76,4 +72,25 @@ public Collection<Defect> defects() throws IOException {
return messages;
}

/**
* All lints.
* @return List of all lints
*/
private static Iterable<Lint> all() {
try {
return new Mapped<>(
res -> new LintByXsl(
new InputOf(res.getInputStream())
),
Arrays.asList(
new PathMatchingResourcePatternResolver().getResources(
"classpath*:org/eolang/lints/**/*.xsl"
)
)
);
} catch (final IOException ex) {
throw new IllegalArgumentException(ex);
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Severity parsed(final String text) {
final Severity severity;
if ("critical".equals(text)) {
severity = Severity.CRITICAL;
} else if ("defect".equals(text)) {
} else if ("error".equals(text)) {
severity = Severity.ERROR;
} else if ("warning".equals(text)) {
severity = Severity.WARNING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOFTWARE.
<xsl:text>missing-home</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOFTWARE.
<xsl:text>missing-package</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOFTWARE.
<xsl:text>missing-version-meta</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
Expand Down

0 comments on commit 3570aa2

Please sign in to comment.