diff --git a/.github/workflows/createlintlist.yml b/.github/workflows/createlintlist.yml new file mode 100644 index 00000000..96f39622 --- /dev/null +++ b/.github/workflows/createlintlist.yml @@ -0,0 +1,62 @@ +# The MIT License (MIT) +# +# Copyright (c) 2016-2025 Objectionary.com +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +--- +'on': + push: + branches: + - master + +jobs: + create_lint_list: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 21 + - run: | + GH_PAGES_BRANCH=gh-pages + + mvn clean + mvn package -DskipTests + + JAR_PREFIX="jar:file:$(readlink -f target/printAll.jar)\!/org/eolang/motives/" + + MOTIVES=$(java -jar target/printAll.jar | cut -c ${#JAR_PREFIX}-) + + jar xvf target/printAll.jar /org/eolang/motives/ + + cd org/eolang/motives/ + + git init + git config user.name 'Marat-Tim' + git config user.email 'rurikcat@gmail.com' + git checkout -b $GH_PAGES_BRANCH + echo "$MOTIVES" | xargs -n 1 git add || true + echo "${MOTIVES//\(.*\)/[\1](\1)\n}" > README.md + git add README.md + + git commit -m "test" + REPO=https://Marat-Tim:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + git remote add origin $REPO + git push --force origin $GH_PAGES_BRANCH diff --git a/pom.xml b/pom.xml index bc77853e..ad833eeb 100644 --- a/pom.xml +++ b/pom.xml @@ -234,6 +234,11 @@ SOFTWARE. 1.37 test + + org.slf4j + slf4j-simple + 2.0.16 + @@ -386,6 +391,32 @@ SOFTWARE. 11 + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + printAll + + + + org.eolang.lints.PrintAllLints + + + + + jar-with-dependencies + + false + + + + pw.krejci jmh-maven-plugin diff --git a/src/main/java/org/eolang/lints/JavaLint.java b/src/main/java/org/eolang/lints/JavaLint.java new file mode 100644 index 00000000..66594abc --- /dev/null +++ b/src/main/java/org/eolang/lints/JavaLint.java @@ -0,0 +1,81 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.lints; + +import com.jcabi.xml.XML; +import io.github.secretx33.resourceresolver.ClassPathResource; +import java.io.IOException; +import java.util.Collection; +import java.util.Locale; +import org.cactoos.text.FormattedText; +import org.cactoos.text.IoCheckedText; + +/** + * Override {@link Lint#motive()} method. Overridden method will return path to the file on the + * classpath with the same name as the class of the decorated object but in camel-case. + * + * @since 0.0.0 + */ +public final class JavaLint implements Lint { + /** + * Decorated object. + */ + private final Lint lint; + + public JavaLint(final Lint lint) { + this.lint = lint; + } + + @Override + public String name() { + return this.lint.name(); + } + + @Override + public Collection defects(final XML entity) throws IOException { + return this.lint.defects(entity); + } + + @Override + public String motive() throws IOException { + final String classname = this.lint.getClass() + .getSimpleName() + .replaceAll("([a-z0-9])([A-Z])", "$1-$2") + .toLowerCase(Locale.ROOT); + String packagename = this.lint.getClass().getPackage().getName(); + packagename = packagename.substring(packagename.lastIndexOf('.') + 1); + return new ClassPathResource( + new IoCheckedText( + new FormattedText( + "org/eolang/motives/%s/%s.md", + packagename, + classname + ) + ).asString() + ) + .getURL() + .toString(); + } + +} diff --git a/src/main/java/org/eolang/lints/PkMono.java b/src/main/java/org/eolang/lints/PkMono.java index b1e2cb06..595e2a4b 100644 --- a/src/main/java/org/eolang/lints/PkMono.java +++ b/src/main/java/org/eolang/lints/PkMono.java @@ -24,10 +24,11 @@ package org.eolang.lints; import com.jcabi.xml.XML; -import java.util.Arrays; import javax.annotation.concurrent.ThreadSafe; import org.cactoos.iterable.IterableEnvelope; +import org.cactoos.iterable.IterableOf; import org.cactoos.iterable.Joined; +import org.cactoos.iterable.Mapped; import org.cactoos.iterable.Shuffled; import org.eolang.lints.comments.LtAsciiOnly; import org.eolang.lints.misc.LtTestNotVerb; @@ -51,9 +52,12 @@ final class PkMono extends IterableEnvelope> { new Shuffled<>( new Joined>( new PkByXsl(), - Arrays.asList( - new LtAsciiOnly(), - new LtTestNotVerb() + new Mapped>( + JavaLint::new, + new IterableOf<>( + new LtAsciiOnly(), + new LtTestNotVerb() + ) ) ) ) diff --git a/src/main/java/org/eolang/lints/PrintAllLints.java b/src/main/java/org/eolang/lints/PrintAllLints.java new file mode 100644 index 00000000..840eb08c --- /dev/null +++ b/src/main/java/org/eolang/lints/PrintAllLints.java @@ -0,0 +1,57 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2025 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.lints; + +import com.jcabi.xml.XML; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Print all lints. + * + * @since 0.0.0 + */ +public final class PrintAllLints { + private PrintAllLints() { + } + + @SuppressWarnings({"PMD.ProhibitPublicStaticMethods", "PMD.AvoidThrowingRawExceptionTypes"}) + public static void main(final String[] args) { + final List> alllints = new ArrayList<>(50); + new PkMono().forEach(alllints::add); + alllints.stream() + .map( + lint -> { + try { + return lint.motive(); + } catch (final IOException exception) { + throw new RuntimeException(exception); + } + } + ) + .forEach(System.out::println); + } + +} diff --git a/src/main/java/org/eolang/lints/comments/LtAsciiOnly.java b/src/main/java/org/eolang/lints/comments/LtAsciiOnly.java index 0a4cf519..d867b6c0 100644 --- a/src/main/java/org/eolang/lints/comments/LtAsciiOnly.java +++ b/src/main/java/org/eolang/lints/comments/LtAsciiOnly.java @@ -43,9 +43,6 @@ * For now we just reusing object line number (via @line), which is not correct * for specifying on which line of the program comment is located. This issue * can be solved after this one. - * @todo #19:45min Create Lint envelope called `JavaLint` that will fetch motive from - * Markdown file based on the lint's name (Java class name) and lint's dimension - * (Java package name, e.g. `comments`). * @checkstyle StringLiteralsConcatenationCheck (30 lines) */ public final class LtAsciiOnly implements Lint { @@ -90,7 +87,7 @@ public String name() { public String motive() throws IOException { return new IoCheckedText( new TextOf( - new ResourceOf("org/eolang/motives/comments/ascii-only.md") + new ResourceOf("org/eolang/motives/comments/lt-ascii-only.md") ) ).asString(); } diff --git a/src/main/java/org/eolang/lints/misc/LtTestNotVerb.java b/src/main/java/org/eolang/lints/misc/LtTestNotVerb.java index 51ba4f73..61268779 100644 --- a/src/main/java/org/eolang/lints/misc/LtTestNotVerb.java +++ b/src/main/java/org/eolang/lints/misc/LtTestNotVerb.java @@ -129,7 +129,7 @@ public String motive() throws IOException { return new UncheckedText( new TextOf( new ResourceOf( - "org/eolang/motives/misc/test-object-is-not-verb-in-singular.md" + "org/eolang/motives/misc/lt-test-not-verb.md" ) ) ).asString(); diff --git a/src/main/resources/org/eolang/motives/comments/ascii-only.md b/src/main/resources/org/eolang/motives/comments/lt-ascii-only.md similarity index 100% rename from src/main/resources/org/eolang/motives/comments/ascii-only.md rename to src/main/resources/org/eolang/motives/comments/lt-ascii-only.md diff --git a/src/main/resources/org/eolang/motives/misc/test-object-is-not-verb-in-singular.md b/src/main/resources/org/eolang/motives/misc/lt-test-not-verb.md similarity index 100% rename from src/main/resources/org/eolang/motives/misc/test-object-is-not-verb-in-singular.md rename to src/main/resources/org/eolang/motives/misc/lt-test-not-verb.md