From c3192c42ba158901118dbabb573a535100c2a86f Mon Sep 17 00:00:00 2001 From: Marat-Tim Date: Fri, 25 Apr 2025 22:47:10 +0300 Subject: [PATCH] feat(#65): add docs to README + get motives at runtime --- .github/motives.groovy | 29 +++++++++++++++++++++ .github/motives.sh | 5 +++- README.md | 3 +++ pom.xml | 17 ++++++++++++ src/main/java/org/eolang/lints/LtByXsl.java | 20 +++++++------- src/main/java/org/eolang/lints/PkByXsl.java | 12 ++++----- 6 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 .github/motives.groovy diff --git a/.github/motives.groovy b/.github/motives.groovy new file mode 100644 index 000000000..548c9d087 --- /dev/null +++ b/.github/motives.groovy @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com + * SPDX-License-Identifier: MIT + */ +package org.eolang.lints + +/** + * This script is run using gplus in the script motives.sh. + * This script saves a file with the lint name and extension .md to the tmp folder. + * The motive of this lint is preserved as content. + * These files are saved for all active lints in the project. + * @todo #65:15min after fixing this problem with creation of groovy folder + * https://github.com/jcabi/jcabi-parent/issues/586, + * move this script to the src/main/groovy folder in package org.eolang.lints + * @todo #65:15min after moving motives.groovy into src/main/groovy we should add test, + * that verifies that this script correctly saves a list of all lint motifs to the tmp folder + */ + +static def saveLint(Lint lint) { + new File("tmp/${lint.name()}.md").text = lint.motive() +} + +new PkMono().forEach { + saveLint(it) +} + +new PkWpa().forEach { + saveLint(it) +} diff --git a/.github/motives.sh b/.github/motives.sh index 9c7c317bc..40d1ba202 100755 --- a/.github/motives.sh +++ b/.github/motives.sh @@ -41,12 +41,15 @@ tail() { printf '' } +mkdir tmp +mvn clean compile gplus:execute + while IFS= read -r f; do n=$(basename "${f}" .md) html=gh-pages/${tag}/${n}.html ( head && pandoc "${f}" && tail ) > "${html}" echo "${n} -> $(du -b "${html}" | cut -f1) bytes" -done < <(find src/main/resources/org/eolang/motives -name '*.md' | sort) +done < <(find tmp -name '*.md' | sort) ( head diff --git a/README.md b/README.md index 7ad3f86c5..11347947e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ This Java package is a collection of "lints" (aka "checkers") for formatting. This is about best practices and readiness of code for successful compilation and execution. +You can find the current full list of rules [here][lints-list]. + We use this package as a dependency in the [EO-to-Java compiler][EO]: @@ -171,3 +173,4 @@ If you want the code to be checked using [XMIR]: https://news.eolang.org/2022-11-25-xmir-guide.html [EO]: https://www.eolang.org [benchmark-gha]: https://github.com/objectionary/lints/actions/runs/14839302036 +[lints-list]: https://www.objectionary.com/lints/ diff --git a/pom.xml b/pom.xml index bc68c5b73..ab298d291 100644 --- a/pom.xml +++ b/pom.xml @@ -622,6 +622,23 @@ + + org.codehaus.gmavenplus + gmavenplus-plugin + 4.1.1 + + + + + + + + org.apache.groovy + groovy + 4.0.26 + + + diff --git a/src/main/java/org/eolang/lints/LtByXsl.java b/src/main/java/org/eolang/lints/LtByXsl.java index bd06eacf8..5d9dde0dc 100644 --- a/src/main/java/org/eolang/lints/LtByXsl.java +++ b/src/main/java/org/eolang/lints/LtByXsl.java @@ -11,7 +11,9 @@ import com.jcabi.xml.XMLDocument; import com.jcabi.xml.XSL; import com.jcabi.xml.XSLDocument; +import io.github.secretx33.resourceresolver.DefaultResourceLoader; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Optional; @@ -40,9 +42,9 @@ final class LtByXsl implements Lint { private final XSL sheet; /** - * Motive document. + * Path to motive document. */ - private final Input doc; + private final String doc; /** * Ctor. @@ -54,20 +56,18 @@ final class LtByXsl implements Lint { new ResourceOf( String.format("org/eolang/lints/%s.xsl", xsl) ), - new ResourceOf( - String.format("org/eolang/motives/%s.md", xsl) - ) + String.format("org/eolang/motives/%s.md", xsl) ); } /** * Ctor. - * @param xsl Relative path of XSL - * @param motive Relative path of a motive document + * @param xsl Absolute path of XSL + * @param motive Absolute path of a motive document * @throws IOException If fails */ @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") - LtByXsl(final Input xsl, final Input motive) throws IOException { + LtByXsl(final Input xsl, final String motive) throws IOException { final XML xml = new XMLDocument(new IoCheckedText(new TextOf(xsl)).asString()); this.rule = new Xnav(xml.toString()) .element("xsl:stylesheet") @@ -117,7 +117,9 @@ public Collection defects(final XML xmir) { @Override public String motive() throws IOException { - return new IoCheckedText(new TextOf(this.doc)).asString(); + return new DefaultResourceLoader() + .getResource(this.doc) + .getContentAsString(StandardCharsets.UTF_8); } /** diff --git a/src/main/java/org/eolang/lints/PkByXsl.java b/src/main/java/org/eolang/lints/PkByXsl.java index f47069abe..bb1035a23 100644 --- a/src/main/java/org/eolang/lints/PkByXsl.java +++ b/src/main/java/org/eolang/lints/PkByXsl.java @@ -54,13 +54,11 @@ private static Iterable> all() { res -> new LtByXsl( new InputOf(res.getInputStream()), - new InputOf( - PkByXsl.XSL_PATTERN.matcher( - PkByXsl.LINTS_PATH.matcher( - res.getURL().toString() - ).replaceAll("eolang/motives") - ).replaceAll(".md") - ) + PkByXsl.XSL_PATTERN.matcher( + PkByXsl.LINTS_PATH.matcher( + res.getURL().toString() + ).replaceAll("eolang/motives") + ).replaceAll(".md") ), Arrays.asList( new PathMatchingResourcePatternResolver().getResources(