Skip to content

Commit 899976f

Browse files
committed
LtSuppressed
1 parent 4a842ef commit 899976f

File tree

11 files changed

+134
-35
lines changed

11 files changed

+134
-35
lines changed

src/main/java/org/eolang/lints/Lint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface Lint<T> {
5151
/**
5252
* Returns motive for a lint, explaining why this lint exists.
5353
* @return Motive text about lint
54-
* @throws Exception if something went wrong
54+
* @throws IOException if something went wrong
5555
*/
56-
String motive() throws Exception;
56+
String motive() throws IOException;
5757
}

src/main/java/org/eolang/lints/LtByXsl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public Collection<Defect> defects(final XML xmir) {
126126
}
127127

128128
@Override
129-
public String motive() throws Exception {
130-
return new TextOf(this.doc).asString();
129+
public String motive() throws IOException {
130+
return new IoCheckedText(new TextOf(this.doc)).asString();
131131
}
132132

133133
/**
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2024 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.eolang.lints;
25+
26+
import com.jcabi.xml.XML;
27+
import java.io.IOException;
28+
import java.util.ArrayList;
29+
import java.util.Collection;
30+
31+
/**
32+
* Lint that ignores linting if {@code +unlint} meta is present.
33+
*
34+
* @since 0.0.1
35+
*/
36+
final class LtSuppressed implements Lint<XML> {
37+
38+
/**
39+
* The original lint.
40+
*/
41+
private final Lint<XML> origin;
42+
43+
/**
44+
* Ctor.
45+
* @param lint The lint to decorate
46+
*/
47+
LtSuppressed(final Lint<XML> lint) {
48+
this.origin = lint;
49+
}
50+
51+
@Override
52+
public String name() {
53+
return this.origin.name();
54+
}
55+
56+
@Override
57+
public Collection<Defect> defects(final XML xmir) throws IOException {
58+
final boolean suppress = !xmir.nodes(
59+
String.format(
60+
"/program/metas/meta[head='unlint' and tail='%s']",
61+
this.origin.name()
62+
)
63+
).isEmpty();
64+
final Collection<Defect> defects = new ArrayList<>(0);
65+
if (!suppress) {
66+
defects.addAll(this.origin.defects(xmir));
67+
}
68+
return defects;
69+
}
70+
71+
@Override
72+
public String motive() throws IOException {
73+
return this.origin.motive();
74+
}
75+
76+
}

src/main/java/org/eolang/lints/PkByXsl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ private static Iterable<Lint<XML>> all() {
7070
try {
7171
return new Shuffled<Lint<XML>>(
7272
new Mapped<>(
73-
res -> new LtByXsl(
74-
new InputOf(res.getInputStream()),
75-
new InputOf(
76-
PkByXsl.XSL_PATTERN.matcher(
77-
PkByXsl.LINTS_PATH.matcher(
78-
res.getURL().toString()
79-
).replaceAll("eolang/motives")
80-
).replaceAll(".md")
73+
res -> new LtSuppressed(
74+
new LtByXsl(
75+
new InputOf(res.getInputStream()),
76+
new InputOf(
77+
PkByXsl.XSL_PATTERN.matcher(
78+
PkByXsl.LINTS_PATH.matcher(
79+
res.getURL().toString()
80+
).replaceAll("eolang/motives")
81+
).replaceAll(".md")
82+
)
8183
)
8284
),
8385
Arrays.asList(

src/main/java/org/eolang/lints/comments/LtAsciiOnly.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.LinkedList;
3030
import java.util.Optional;
3131
import org.cactoos.io.ResourceOf;
32+
import org.cactoos.text.IoCheckedText;
3233
import org.cactoos.text.TextOf;
3334
import org.eolang.lints.Defect;
3435
import org.eolang.lints.Lint;
@@ -86,9 +87,11 @@ public String name() {
8687
}
8788

8889
@Override
89-
public String motive() throws Exception {
90-
return new TextOf(
91-
new ResourceOf("org/eolang/motives/comments/ascii-only.md")
90+
public String motive() throws IOException {
91+
return new IoCheckedText(
92+
new TextOf(
93+
new ResourceOf("org/eolang/motives/comments/ascii-only.md")
94+
)
9295
).asString();
9396
}
9497
}

src/main/java/org/eolang/lints/critical/LtIncorrectAlias.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
package org.eolang.lints.critical;
2525

2626
import com.jcabi.xml.XML;
27+
import java.io.IOException;
2728
import java.util.Collection;
2829
import java.util.LinkedList;
2930
import java.util.Map;
3031
import org.cactoos.io.ResourceOf;
3132
import org.cactoos.text.TextOf;
33+
import org.cactoos.text.UncheckedText;
3234
import org.eolang.lints.Defect;
3335
import org.eolang.lints.Lint;
3436
import org.eolang.lints.Severity;
@@ -83,10 +85,12 @@ public Collection<Defect> defects(final Map<String, XML> pkg) {
8385
}
8486

8587
@Override
86-
public String motive() throws Exception {
87-
return new TextOf(
88-
new ResourceOf(
89-
"org/eolang/motives/critical/incorrect-alias.md"
88+
public String motive() throws IOException {
89+
return new UncheckedText(
90+
new TextOf(
91+
new ResourceOf(
92+
"org/eolang/motives/critical/incorrect-alias.md"
93+
)
9094
)
9195
).asString();
9296
}

src/main/java/org/eolang/lints/errors/LtObjectIsNotUnique.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package org.eolang.lints.errors;
2525

2626
import com.jcabi.xml.XML;
27+
import java.io.IOException;
2728
import java.util.Collection;
2829
import java.util.LinkedList;
2930
import java.util.List;
@@ -34,6 +35,7 @@
3435
import java.util.stream.IntStream;
3536
import org.cactoos.io.ResourceOf;
3637
import org.cactoos.text.TextOf;
38+
import org.cactoos.text.UncheckedText;
3739
import org.eolang.lints.Defect;
3840
import org.eolang.lints.Lint;
3941
import org.eolang.lints.Severity;
@@ -92,11 +94,13 @@ public Collection<Defect> defects(final Map<String, XML> pkg) {
9294
}
9395

9496
@Override
95-
public String motive() throws Exception {
96-
return new TextOf(
97-
new ResourceOf(
98-
String.format(
99-
"org/eolang/motives/errors/%s.md", this.name()
97+
public String motive() throws IOException {
98+
return new UncheckedText(
99+
new TextOf(
100+
new ResourceOf(
101+
String.format(
102+
"org/eolang/motives/errors/%s.md", this.name()
103+
)
100104
)
101105
)
102106
).asString();

src/main/java/org/eolang/lints/misc/LtTestNotVerb.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.stream.Stream;
3939
import org.cactoos.io.ResourceOf;
4040
import org.cactoos.text.TextOf;
41+
import org.cactoos.text.UncheckedText;
4142
import org.eolang.lints.Defect;
4243
import org.eolang.lints.Lint;
4344
import org.eolang.lints.Severity;
@@ -132,10 +133,12 @@ public Collection<Defect> defects(final XML xmir) throws IOException {
132133
}
133134

134135
@Override
135-
public String motive() throws Exception {
136-
return new TextOf(
137-
new ResourceOf(
138-
"org/eolang/motives/misc/test-object-is-not-verb-in-singular.md"
136+
public String motive() throws IOException {
137+
return new UncheckedText(
138+
new TextOf(
139+
new ResourceOf(
140+
"org/eolang/motives/misc/test-object-is-not-verb-in-singular.md"
141+
)
139142
)
140143
).asString();
141144
}

src/main/java/org/eolang/lints/units/LtUnitTestMissing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public String name() {
6868
}
6969

7070
@Override
71-
public String motive() throws Exception {
71+
public String motive() throws IOException {
7272
return "";
7373
}
7474
}

src/main/java/org/eolang/lints/units/LtUnitTestWithoutLiveFile.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
package org.eolang.lints.units;
2525

2626
import com.jcabi.xml.XML;
27+
import java.io.IOException;
2728
import java.util.Collection;
2829
import java.util.LinkedList;
2930
import java.util.Map;
3031
import org.cactoos.io.ResourceOf;
32+
import org.cactoos.text.IoCheckedText;
3133
import org.cactoos.text.TextOf;
3234
import org.eolang.lints.Defect;
3335
import org.eolang.lints.Lint;
@@ -72,11 +74,13 @@ public Collection<Defect> defects(final Map<String, XML> pkg) {
7274
}
7375

7476
@Override
75-
public String motive() throws Exception {
76-
return new TextOf(
77-
new ResourceOf(
78-
String.format(
79-
"org/eolang/motives/units/%s.md", this.name()
77+
public String motive() throws IOException {
78+
return new IoCheckedText(
79+
new TextOf(
80+
new ResourceOf(
81+
String.format(
82+
"org/eolang/motives/units/%s.md", this.name()
83+
)
8084
)
8185
)
8286
).asString();

0 commit comments

Comments
 (0)