Skip to content
Merged
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
2 changes: 0 additions & 2 deletions src/main/groovy/org/eolang/lints/HomeNames.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ final class HomeNames {
&& file.contains(
Path.of(this.location)
.resolve("objects")
.resolve("org")
.resolve("eolang")
.toString().replace("\\", "/")
)
}
Expand Down
10 changes: 8 additions & 2 deletions 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 All @@ -53,7 +57,9 @@ public Boolean apply(final String unlint) {
names = new SetOf<>();
}
if (split.length > 1) {
missing = (!names.contains(name) || !lines.contains(Integer.parseInt(split[1])))
missing = (!names.contains(name)
|| lines == null
|| !lines.contains(Integer.parseInt(split[1])))
&& !this.excluded.contains(name);
} else {
missing = !names.contains(name) && !this.excluded.contains(name);
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/org/eolang/lints/HomeNamesTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class HomeNamesTest {
Matchers.everyItem(
Matchers.hasToString(
Matchers.matchesRegex(
"org\\.eolang(?:\\.[a-zA-Z_][a-zA-Z0-9_-]*)+\\.eo"
"(?:[a-zA-Z_][a-zA-Z0-9_-]*\\.)*[a-zA-Z_][a-zA-Z0-9_-]*\\.eo"
)
)
)
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 range pattern references an absent lint",
new DefectMissing(new MapOf<>(), new ListOf<>()).apply("ascii-only:1-5"),
Matchers.equalTo(true)
);
}

@Test
void returnsFalseWhenRangeReferencesExcludedAbsentLint() {
MatcherAssert.assertThat(
"Defect should not be missing when the absent lint is excluded",
new DefectMissing(new MapOf<>(), new ListOf<>("ascii-only"))
.apply("ascii-only:1-5"),
Matchers.equalTo(false)
);
}
}
20 changes: 10 additions & 10 deletions src/test/java/org/eolang/lints/LtReservedNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class LtReservedNameTest {
void catchesReservedName() throws IOException {
MatcherAssert.assertThat(
"It is expected to catch only one defect here",
new LtReservedName(new MapOf<>("true", "org.eolang.true.eo"))
new LtReservedName(new MapOf<>("true", "true.eo"))
.defects(
new EoSyntax(
String.join(
Expand All @@ -45,7 +45,7 @@ void catchesReservedName() throws IOException {
void allowsNonReservedName() throws IOException {
MatcherAssert.assertThat(
"Defects are not empty, but they should",
new LtReservedName(new MapOf<>("true", "org.eolang.true.eo"))
new LtReservedName(new MapOf<>("true", "true.eo"))
.defects(
new EoSyntax(
String.join(
Expand All @@ -63,7 +63,7 @@ void allowsNonReservedName() throws IOException {
void allowsUniqueNameInTopSourceObject() throws IOException {
MatcherAssert.assertThat(
"Defects are not empty, but they should",
new LtReservedName(new MapOf<>("f", "org.eolang.f.eo"))
new LtReservedName(new MapOf<>("f", "f.eo"))
.defects(
new EoSyntax(
String.join(
Expand All @@ -80,7 +80,7 @@ void allowsUniqueNameInTopSourceObject() throws IOException {
@Test
void catchesReservedNameWithPackage() throws IOException {
final Collection<Defect> found = new LtReservedName(
new MapOf<>("stdout", "org.eolang.stdout.eo")
new MapOf<>("stdout", "stdout.eo")
).defects(
new EoSyntax(
String.join(
Expand Down Expand Up @@ -109,8 +109,8 @@ void reportsMultipleNames() throws IOException {
"Defects size does not match with expected",
new LtReservedName(
new MapOf<String, String>(
new MapEntry<>("ja", "org.eolang.ja.eo"),
new MapEntry<>("spb", "org.eolang.spb.eo")
new MapEntry<>("ja", "ja.eo"),
new MapEntry<>("spb", "spb.eo")
)
).defects(
new EoSyntax(
Expand All @@ -131,7 +131,7 @@ void reportsReservedNameInTopObject() throws IOException {
MatcherAssert.assertThat(
"Defects size does not match with expected",
new LtReservedName(
new MapOf<>("foo", "org.eolang.foo.eo")
new MapOf<>("foo", "foo.eo")
).defects(
new EoSyntax(
String.join(
Expand All @@ -152,7 +152,7 @@ void reportsCorrectMessageForReservedNameInTopObject() throws IOException {
"The name of high-level object 'foo' should be reported",
new ListOf<>(
new LtReservedName(
new MapOf<>("foo", "org.eolang.foo.eo")
new MapOf<>("foo", "foo.eo")
).defects(
new EoSyntax(
String.join(
Expand All @@ -165,7 +165,7 @@ void reportsCorrectMessageForReservedNameInTopObject() throws IOException {
)
).get(0).text(),
Matchers.equalTo(
"Object name \"foo\" is already reserved by object in the \"org.eolang.foo.eo\""
"Object name \"foo\" is already reserved by object in the \"foo.eo\""
)
);
}
Expand Down Expand Up @@ -207,7 +207,7 @@ void scansReservedFromHomeWithCorrectMessage() throws Exception {
)
).get(0).text(),
Matchers.equalTo(
"Object name \"stdout\" is already reserved by object in the \"org.eolang.io.stdout.eo\""
"Object name \"stdout\" is already reserved by object in the \"io.stdout.eo\""
)
);
}
Expand Down
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 catchesUnlintWithRangeForAbsentLint() throws IOException {
MatcherAssert.assertThat(
"Non-existing unlint with range should be reported, not crash with NPE",
new LtUnlintNonExistingDefect(
new ListOf<>(new LtAsciiOnly()),
new ListOf<>()
).defects(
new EoSyntax(
String.join(
"\n",
"+unlint ascii-only:1-5",
"[] > main",
" QQ.io.stdout > @",
" \"Hello\""
)
).parsed()
),
Matchers.iterableWithSize(1)
);
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/eolang/lints/ReservedNamesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void readsReservedInCorrectFormat() {
Matchers.everyItem(
Matchers.hasToString(
Matchers.matchesRegex(
"org\\.eolang(?:\\.[a-zA-Z_][a-zA-Z0-9_-]*)+\\.eo"
"(?:[a-zA-Z_][a-zA-Z0-9_-]*\\.)*[a-zA-Z_][a-zA-Z0-9_-]*\\.eo"
)
)
)
Expand Down
Loading