Skip to content

Commit

Permalink
#3626: lint always
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 9, 2024
1 parent 3330ad9 commit 07977d0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 44 deletions.
25 changes: 6 additions & 19 deletions eo-maven-plugin/src/main/java/org/eolang/maven/LintMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.iterable.Filtered;
import org.cactoos.list.ListOf;
import org.eolang.lints.Defect;
import org.eolang.lints.Program;
Expand Down Expand Up @@ -92,23 +91,11 @@ void exec() throws IOException {
counts.putIfAbsent(Severity.CRITICAL, 0);
counts.putIfAbsent(Severity.ERROR, 0);
counts.putIfAbsent(Severity.WARNING, 0);
final Collection<ForeignTojo> must = new ListOf<>(
new Filtered<>(
ForeignTojo::notLinted,
tojos
)
);
final int passed = new Threaded<>(
must,
tojos,
tojo -> this.lintOne(tojo, counts)
).total();
if (must.isEmpty()) {
Logger.info(
this,
"No XMIR programs out of %d linted individually",
tojos.size()
);
} else if (tojos.isEmpty()) {
if (tojos.isEmpty()) {
Logger.info(this, "There are no XMIR programs, nothing to lint individually");
}
Logger.info(
Expand All @@ -122,16 +109,16 @@ void exec() throws IOException {
Logger.info(
this,
"Linted %d out of %d XMIR program(s) that needed this (out of %d total programs): %s",
passed, must.size(), tojos.size(), sum
passed, tojos.size(), tojos.size(), sum
);
throw new IllegalStateException(
String.format("In %d XMIR files, we found %s", must.size(), sum)
String.format("In %d XMIR files, we found %s", tojos.size(), sum)
);
} else {
Logger.info(
this,
"Linted %d out of %d XMIR program(s) that needed this (out of %d total programs), no problems found",
passed, must.size(), tojos.size()
"Linted %d out of %d XMIR program(s) that needed this, no problems found",
passed, tojos.size()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,6 @@ public boolean notShaken() {
return res;
}

/**
* Checks if tojo was not already verified.
*
* @return True if optimization is required, false otherwise.
*/
public boolean notLinted() {
final Path src = this.xmir();
boolean res = true;
if (this.delegate.exists(ForeignTojos.Attribute.LINTED.getKey())) {
final Path tgt = this.optimized();
if (tgt.toFile().lastModified() >= src.toFile().lastModified()) {
Logger.debug(this, "Already verified %[file]s to %[file]s", src, tgt);
res = false;
}
}
return res;
}

/**
* Check if the given tojo has not been parsed.
*
Expand Down
31 changes: 31 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/LintMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jcabi.xml.XMLDocument;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.farea.Farea;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -49,8 +50,38 @@
*/
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
@ExtendWith(MktmpResolver.class)
@ExtendWith(RandomProgramResolver.class)
final class LintMojoTest {

@Test
void lintsAgainAfterModification(@Mktmp final Path temp, @RandomProgram final String program)
throws Exception {
new Farea(temp).together(
f -> {
f.clean();
f.files().file("src/main/eo/foo.eo").write(program.getBytes());
f.build()
.plugins()
.appendItself()
.execution()
.goals("register", "parse", "optimize", "shake", "lint");
f.exec("process-classes");
final long before = f.files().file(
"target/eo/6-lint/foo.xmir"
).path().toFile().lastModified();
f.files().file("src/main/eo/foo.eo").write(program.getBytes());
f.exec("process-classes");
MatcherAssert.assertThat(
"the .xmir file is re-generated",
f.files().file(
"target/eo/6-lint/foo.xmir"
).path().toFile().lastModified(),
Matchers.not(Matchers.equalTo(before))
);
}
);
}

@Test
void doesNotFailWithNoErrorsAndWarnings(@Mktmp final Path temp) {
Assertions.assertDoesNotThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
@ExtendWith(MktmpResolver.class)
@ExtendWith(RandomProgramResolver.class)
final class PhiMojoTest {
/**
* Comment.
*/
private static final String COMMENT =
"# No comments.";

@Test
void convertsSimpleObjectToPhi(@Mktmp final Path temp, @RandomProgram final String program)
Expand Down Expand Up @@ -172,7 +167,7 @@ void createsFiles(@Mktmp final Path temp) throws Exception {
),
new FakeMaven(temp)
.withProgram(
PhiMojoTest.COMMENT,
"No comments.",
"[] > cart",
" memory 0 > total",
" [i] > add",
Expand Down Expand Up @@ -218,7 +213,7 @@ void doesNotFailOnError(@Mktmp final Path temp) {
Assertions.assertDoesNotThrow(
() -> new FakeMaven(temp)
.withProgram(
PhiMojoTest.COMMENT,
"No comments.",
"[] > without-name",
" true"
)
Expand Down

0 comments on commit 07977d0

Please sign in to comment.