Skip to content

Commit cf9fce3

Browse files
committed
feat(#65): add docs to README + get motives at runtime
1 parent b308afd commit cf9fce3

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

.github/motives.groovy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.lints
6+
7+
/**
8+
* This script is run using gplus in the script motives.sh.
9+
* This script saves a file with the lint name and extension .md to the tmp folder.
10+
* The motive of this lint is preserved as content.
11+
* These files are saved for all active lints in the project.
12+
* @todo #65:15min after fixing this problem with creation of groovy folder
13+
* https://github.com/jcabi/jcabi-parent/issues/586,
14+
* move this script to the src/main/groovy folder in package org.eolang.lints
15+
* @todo #65:15min after moving motives.groovy into src/main/groovy we should add test,
16+
* that verifies that this script correctly saves a list of all lint motifs to the tmp folder
17+
*/
18+
19+
static def saveLint(Lint<?> lint) {
20+
new File("tmp/${lint.name()}.md").text = lint.motive()
21+
}
22+
23+
new PkMono().forEach {
24+
saveLint(it)
25+
}
26+
27+
new PkWpa().forEach {
28+
saveLint(it)
29+
}

.github/motives.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ tail() {
4141
printf '</article></section></body></html>'
4242
}
4343

44+
mkdir tmp
45+
mvn clean compile gplus:execute
46+
4447
while IFS= read -r f; do
4548
n=$(basename "${f}" .md)
4649
html=gh-pages/${tag}/${n}.html
4750
( head && pandoc "${f}" && tail ) > "${html}"
4851
echo "${n} -> $(du -b "${html}" | cut -f1) bytes"
49-
done < <(find src/main/resources/org/eolang/motives -name '*.md' | sort)
52+
done < <(find tmp -name '*.md' | sort)
5053

5154
(
5255
head

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This Java package is a collection of "lints" (aka "checkers") for
1717
formatting. This is about best practices and readiness of code
1818
for successful compilation and execution.
1919

20+
You can find the current full list of rules [here][lints-list].
21+
2022
We use this package as a dependency in the
2123
[EO-to-Java compiler][EO]:
2224

@@ -171,3 +173,4 @@ If you want the code to be checked using
171173
[XMIR]: https://news.eolang.org/2022-11-25-xmir-guide.html
172174
[EO]: https://www.eolang.org
173175
[benchmark-gha]: https://github.com/objectionary/lints/actions/runs/14713088694
176+
[lints-list]: https://www.objectionary.com/lints/

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,23 @@
576576
</execution>
577577
</executions>
578578
</plugin>
579+
<plugin>
580+
<groupId>org.codehaus.gmavenplus</groupId>
581+
<artifactId>gmavenplus-plugin</artifactId>
582+
<version>4.1.1</version>
583+
<configuration>
584+
<scripts>
585+
<script>./.github/motives.groovy</script>
586+
</scripts>
587+
</configuration>
588+
<dependencies>
589+
<dependency>
590+
<groupId>org.apache.groovy</groupId>
591+
<artifactId>groovy</artifactId>
592+
<version>4.0.26</version>
593+
</dependency>
594+
</dependencies>
595+
</plugin>
579596
</plugins>
580597
</build>
581598
</project>

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import com.jcabi.xml.XMLDocument;
1212
import com.jcabi.xml.XSL;
1313
import com.jcabi.xml.XSLDocument;
14+
import io.github.secretx33.resourceresolver.DefaultResourceLoader;
1415
import java.io.IOException;
16+
import java.nio.charset.StandardCharsets;
1517
import java.util.ArrayList;
1618
import java.util.Collection;
1719
import java.util.Optional;
@@ -40,9 +42,9 @@ final class LtByXsl implements Lint<XML> {
4042
private final XSL sheet;
4143

4244
/**
43-
* Motive document.
45+
* Path to motive document.
4446
*/
45-
private final Input doc;
47+
private final String doc;
4648

4749
/**
4850
* Ctor.
@@ -54,20 +56,18 @@ final class LtByXsl implements Lint<XML> {
5456
new ResourceOf(
5557
String.format("org/eolang/lints/%s.xsl", xsl)
5658
),
57-
new ResourceOf(
58-
String.format("org/eolang/motives/%s.md", xsl)
59-
)
59+
String.format("org/eolang/motives/%s.md", xsl)
6060
);
6161
}
6262

6363
/**
6464
* Ctor.
65-
* @param xsl Relative path of XSL
66-
* @param motive Relative path of a motive document
65+
* @param xsl Absolute path of XSL
66+
* @param motive Absolute path of a motive document
6767
* @throws IOException If fails
6868
*/
6969
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
70-
LtByXsl(final Input xsl, final Input motive) throws IOException {
70+
LtByXsl(final Input xsl, final String motive) throws IOException {
7171
final XML xml = new XMLDocument(new IoCheckedText(new TextOf(xsl)).asString());
7272
this.rule = new Xnav(xml.toString())
7373
.element("xsl:stylesheet")
@@ -117,7 +117,9 @@ public Collection<Defect> defects(final XML xmir) {
117117

118118
@Override
119119
public String motive() throws IOException {
120-
return new IoCheckedText(new TextOf(this.doc)).asString();
120+
return new DefaultResourceLoader()
121+
.getResource(this.doc)
122+
.getContentAsString(StandardCharsets.UTF_8);
121123
}
122124

123125
/**

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ private static Iterable<Lint<XML>> all() {
5454
res ->
5555
new LtByXsl(
5656
new InputOf(res.getInputStream()),
57-
new InputOf(
58-
PkByXsl.XSL_PATTERN.matcher(
59-
PkByXsl.LINTS_PATH.matcher(
60-
res.getURL().toString()
61-
).replaceAll("eolang/motives")
62-
).replaceAll(".md")
63-
)
57+
PkByXsl.XSL_PATTERN.matcher(
58+
PkByXsl.LINTS_PATH.matcher(
59+
res.getURL().toString()
60+
).replaceAll("eolang/motives")
61+
).replaceAll(".md")
6462
),
6563
Arrays.asList(
6664
new PathMatchingResourcePatternResolver().getResources(

0 commit comments

Comments
 (0)