Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/org/eolang/lints/DefectMissing.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public Boolean apply(final String unlint) {
final String name = split[0];
final List<Integer> lines = this.defects.get(name);
if (unlint.matches(String.format("%s:\\d+-\\d+", name))) {
missing = !lines.stream().allMatch(new UnlintInRange(unlint));
if (lines == null) {
missing = !this.excluded.contains(name);
} else {
missing = !lines.stream().allMatch(new UnlintInRange(unlint));
}
} else {
final Set<String> names;
if (this.defects != null) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/eolang/lints/DefectMissingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,23 @@ void returnsTrueIfSomeLineIsOutOfRange() {
Matchers.equalTo(true)
);
}

@Test
void returnsTrueWhenRangeReferencesAbsentLint() {
MatcherAssert.assertThat(
"Defect should be missing when referenced lint is absent from map",
new DefectMissing(new MapOf<>("other-lint", new ListOf<>(1, 2)), new ListOf<>())
.apply("ascii-only:1-5"),
Matchers.equalTo(true)
);
}

@Test
void returnsTrueWhenRangeReferencesLintInEmptyMap() {
MatcherAssert.assertThat(
"Defect should be missing when defects map is empty",
new DefectMissing(new MapOf<>(), new ListOf<>()).apply("ascii-only:1-5"),
Matchers.equalTo(true)
);
}
}
22 changes: 22 additions & 0 deletions src/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,26 @@ void catchesUnlintWithOutOfRangeLines() throws IOException {
Matchers.iterableWithSize(1)
);
}

@Test
void catchesRangeUnlintOfAbsentLint() throws IOException {
MatcherAssert.assertThat(
"Range unlint referencing an absent lint should be reported, not throw NPE",
new LtUnlintNonExistingDefect(
new ListOf<>(new LtAsciiOnly()),
new ListOf<>()
).defects(
new EoSyntax(
String.join(
"\n",
"+unlint ascii-only:1-5",
"",
"# Hello.",
"[] > main"
)
).parsed()
),
Matchers.hasSize(Matchers.greaterThan(0))
);
}
}
Loading