Skip to content

Commit

Permalink
#7 Program instead of Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 19, 2024
1 parent e9899a7 commit 9c7bb3a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 238 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/eolang/lints/Lint.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
*/
package org.eolang.lints;

import com.jcabi.xml.XML;
import java.io.IOException;
import java.util.Collection;

/**
* A single checker for an {@code .xmir} file inside a package.
* A single checker for an {@code .xmir} file.
*
* @since 0.0.1
*/
public interface Lint {

/**
* Check and return warnings.
* @param objects Pack of XMIR objects
* @param rel Relative name of the object inside the pack
* @return Violations
* Find and return defects.
* @param xmir The XMIR document to analyze
* @return Defects
*/
Collection<Defect> violations(Objects objects, String rel) throws IOException;
Collection<Defect> defects(XML xmir) throws IOException;

}
7 changes: 2 additions & 5 deletions src/main/java/org/eolang/lints/LintByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ final class LintByXsl implements Lint {
}

@Override
public Collection<Defect> violations(final Objects objects,
final String rel) throws IOException {
final XML report = this.sheet.transform(
objects.take(rel)
);
public Collection<Defect> defects(final XML xmir) {
final XML report = this.sheet.transform(xmir);
final Collection<Defect> defects = new LinkedList<>();
for (final XML defect : report.nodes("/defects/defect")) {
defects.add(
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/org/eolang/lints/Objects.java

This file was deleted.

72 changes: 0 additions & 72 deletions src/main/java/org/eolang/lints/ObjectsInDir.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package org.eolang.lints;

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import io.github.secretx33.resourceresolver.PathMatchingResourcePatternResolver;
import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -33,41 +35,40 @@
import org.cactoos.iterable.Mapped;

/**
* Scope of analysis.
* A single XMIR program to analyze.
*
* @see <a href="https://news.eolang.org/2022-11-25-xmir-guide.html">XMIR</a>
* @since 0.0.1
*/
public final class Scope {
public final class Program {

/**
* Lints to use.
*/
private static final Iterable<Lint> LINTS = Scope.all();
private static final Iterable<Lint> LINTS = Program.all();

/**
* Directory with XMIR files.
* Absolute path of the XMIR file to analyze.
*/
private final Path dir;
private final Path path;

/**
* Ctor.
* @param path The directory with XMIR files
* @param file The absolute path of the XMIR file
*/
public Scope(final Path path) {
this.dir = path;
public Program(final Path file) {
this.path = file;
}

/**
* Find defects possible defects in XMIR files.
* Find defects possible defects in the XMIR file.
* @return All defects found
*/
public Collection<Defect> defects() throws IOException {
final Objects objects = new ObjectsInDir(this.dir);
final Collection<Defect> messages = new LinkedList<>();
for (final Lint lint : Scope.LINTS) {
for (final String rel : objects.rels()) {
messages.addAll(lint.violations(objects, rel));
}
final XML xmir = new XMLDocument(this.path);
for (final Lint lint : Program.LINTS) {
messages.addAll(lint.defects(xmir));
}
return messages;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/eolang/lints/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public enum Severity {
* Compilation can't continue, must stop.
*/
CRITICAL,

/**
* It's a bug, must be fixed.
*/
ERROR,

/**
* Can live with it, but better be fixed.
*/
Expand Down
21 changes: 5 additions & 16 deletions src/test/java/org/eolang/lints/LintByXslTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
*/
package org.eolang.lints;

import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.io.InputOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.parser.CheckPack;
Expand All @@ -37,29 +32,23 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;

/**
* Test for {@link LintByXsl}.
*
* @since 0.0.1
*/
@ExtendWith(MktmpResolver.class)
final class LintByXslTest {

@Test
void lintsOneFile(@Mktmp final Path dir) throws IOException {
Files.write(
dir.resolve("foo.xmir"),
new EoSyntax(
new InputOf("# first\n[] > foo\n# first\n[] > foo\n")
).parsed().toString().getBytes(StandardCharsets.UTF_8)
);
void lintsOneFile() throws IOException {
MatcherAssert.assertThat(
"the objects is found",
new LintByXsl("critical/duplicate-names").violations(
new ObjectsInDir(dir), "foo"
new LintByXsl("critical/duplicate-names").defects(
new EoSyntax(
new InputOf("# first\n[] > foo\n# first\n[] > foo\n")
).parsed()
),
Matchers.hasSize(Matchers.greaterThan(0))
);
Expand Down
71 changes: 0 additions & 71 deletions src/test/java/org/eolang/lints/ObjectsInDirTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,25 @@
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Test for {@link Scope}.
* Test for {@link Program}.
*
* @since 0.0.1
*/
@ExtendWith(MktmpResolver.class)
final class ScopeTest {
final class ProgramTest {

@Test
void simpleTest(@Mktmp final Path dir) throws IOException {
final Path path = dir.resolve("foo.xmir");
Files.write(
dir.resolve("foo.xmir"),
path,
new EoSyntax(
new InputOf("# first.\n[] > foo\n# second.\n[] > foo\n")
).parsed().toString().getBytes(StandardCharsets.UTF_8)
);
MatcherAssert.assertThat(
"the defect is found",
new Scope(dir).defects().size(),
new Program(path).defects().size(),
Matchers.greaterThan(0)
);
}
Expand Down

0 comments on commit 9c7bb3a

Please sign in to comment.