Skip to content

Commit

Permalink
Merge branch 'master' into 266
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jan 31, 2025
2 parents c22c037 + 82759bc commit 73df164
Show file tree
Hide file tree
Showing 53 changed files with 391 additions and 528 deletions.
50 changes: 34 additions & 16 deletions ...s/unknown-name/catches-unknown-names.yaml → .github/motives.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# The MIT License (MIT)
#
# Copyright (c) 2016-2025 Objectionary.com
Expand All @@ -19,20 +21,36 @@
# 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.
---
sheets:
- /org/eolang/lints/errors/unknown-name.xsl
asserts:
- /defects[count(defect[@severity='error'])=1]
- /defects/defect[@line='5']
input: |
+alias foo

# No comments.
[] > fff
test > @
$ > t
@.org.eolang.random
@.t > zz
foo > y1
^.ff > pp
set -e

tag=$1
if [ -z "${tag}" ]; then
echo "Provide tag name as the first argument, for example '0.0.1'"
exit 1
fi

rm -rf "gh-pages/${tag}"
mkdir -p "gh-pages/${tag}"

while IFS= read -r f; do
n=$(basename "${f}" .md)
html=gh-pages/${tag}/${n}.html
pandoc "${f}" -o "${html}"
echo "${n} -> $(du -b "${html}" | cut -f1) bytes"
done < <(find src/main/resources/org/eolang/motives -name '*.md')

(
printf '<html><body style="font-family: monospace;">\n'
printf '<p>Latest version: %s</p>\n' "${tag}"
printf '<p>List of lints in this version<p>'
printf "<ul>\n"
while IFS= read -r f; do
n=$(basename "${f}" ".html")
printf '<li><a href="%s">%s</a></li>\n' \
"/lints/${tag}/${n}.html" "${n}"
done < <(find "gh-pages/${tag}" -name '*.html' | sort)
printf '</ul>\n'
printf '<p>Published on %s.</p>\n' "$(date)"
printf '</body></html>'
) > "gh-pages/index.html"
21 changes: 2 additions & 19 deletions .github/workflows/motives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,8 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: |
tag=${{github.ref_name}}
mkdir -p "gh-pages/${tag}"
find src/main/resources/org/eolang/motives -name '*.md' -exec cp {} "gh-pages/${tag}" \;
(
printf '<html><body style="font-family: monospace;">\n'
printf '<p>Latest version: %s</p>\n' "${tag}"
printf '<p>List of lints in this version<p>'
printf "<ul>\n"
while IFS= read -r f; do
n=$(basename "${f}" .md)
printf '<li><a href="%s">%s</a></li>\n' \
"/${tag}/${n}.html" "${n}"
done < <(find "gh-pages/${tag}" -name '*.md')
printf '</ul>\n'
printf '<p>Published on %s.</p>\n' "$(date)"
printf '</body></html>'
) > "gh-pages/index.html"
- run: sudo apt-get update --yes --fix-missing && sudo apt-get install --yes pandoc
- run: .github/motives.sh "${github.ref_name}"
- uses: JamesIves/[email protected]
with:
branch: gh-pages
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ target/
temp/
*.tgz
*.DS_Store
gh-pages/
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.33.3</version>
<version>0.33.5</version>
</dependency>
<dependency>
<groupId>io.github.secretx33</groupId>
Expand Down Expand Up @@ -117,7 +117,7 @@ SOFTWARE.
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>xsline</artifactId>
<version>0.22.1</version>
<version>0.23.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -138,13 +138,13 @@ SOFTWARE.
<dependency>
<groupId>org.eolang</groupId>
<artifactId>eo-parser</artifactId>
<version>0.50.0</version>
<version>0.51.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>xnav</artifactId>
<version>0.1.4</version>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.opennlp</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/it/lints-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SOFTWARE.
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.33.3</version>
<version>0.33.5</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/eolang/lints/LtByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ final class LtByXsl implements Lint<XML> {
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
LtByXsl(final Input xsl, final Input motive) throws IOException {
final XML xml = new XMLDocument(new IoCheckedText(new TextOf(xsl)).asString());
this.rule = xml.xpath("/xsl:stylesheet/@id").get(0);
this.rule = new Xnav(xml.toString())
.element("xsl:stylesheet")
.attribute("id")
.text()
.orElseThrow();
this.sheet = new MeasuredXsl(
this.rule,
new XSLDocument(xml, this.rule).with(new ClasspathSources())
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/org/eolang/lints/critical/LtIncorrectAlias.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
*/
package org.eolang.lints.critical;

import com.github.lombrozo.xnav.Filter;
import com.github.lombrozo.xnav.Xnav;
import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
Expand All @@ -38,6 +42,7 @@

/**
* Checks that `+alias` is pointing to existing `.xmir` files.
*
* @since 0.0.30
*/
public final class LtIncorrectAlias implements Lint<Map<String, XML>> {
Expand All @@ -52,29 +57,21 @@ public Collection<Defect> defects(final Map<String, XML> pkg) {
final Collection<Defect> defects = new LinkedList<>();
pkg.values().forEach(
xmir -> {
for (final XML alias : xmir.nodes("/program/metas/meta[head='alias']/tail")) {
if (xmir.nodes("/program/metas/meta[head='package']").size() != 1) {
continue;
}
final String pointer = alias.xpath("text()").get(0);
final String lookup;
if (Boolean.parseBoolean(alias.xpath("contains(text(), ' ')").get(0))) {
lookup = alias.xpath("substring-after(text(), ' ')").get(0);
} else {
lookup = String.format(
"%s.%s",
xmir.xpath("/program/metas/meta[head='package']/tail/text()").get(0),
pointer
);
}
final Xnav program = new Xnav(xmir.inner()).element("program");
for (final XML alias : xmir.nodes("/program/metas/meta[head='alias']")) {
final Xnav xml = new Xnav(alias.inner());
final String pointer = xml.element("tail").text().get();
final List<Xnav> parts = xml.elements(Filter.withName("part"))
.collect(Collectors.toList());
final String lookup = parts.get(parts.size() - 1).text().get().substring(2);
if (!pkg.containsKey(lookup)) {
defects.add(
new Defect.Default(
"incorrect-alias",
Severity.CRITICAL,
xmir.xpath("/program/@name").stream().findFirst().orElse("unknown"),
program.attribute("name").text().orElse("unknown"),
Integer.parseInt(
xmir.xpath("/program/metas/meta[head='alias'][1]/@line").get(0)
xml.attribute("line").text().orElse("0")
),
Logger.format(
"Alias \"%s\" points to \"%s\", but it's not in scope (%d): %[list]s",
Expand Down
24 changes: 11 additions & 13 deletions src/main/resources/org/eolang/lints/aliases/alias-too-long.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ SOFTWARE.
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="/program/metas/meta[head='alias']">
<xsl:if test="count(part) &gt; 2">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The alias has too many parts: </xsl:text>
<xsl:value-of select="eo:escape(tail)"/>
</xsl:element>
</xsl:if>
<xsl:for-each select="/program/metas/meta[head='alias' and count(part)&gt;2]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The alias has too many parts: </xsl:text>
<xsl:value-of select="eo:escape(tail)"/>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
27 changes: 13 additions & 14 deletions src/main/resources/org/eolang/lints/aliases/broken-alias-first.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ SOFTWARE.
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:variable name="pattern" select="'^[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*$'"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="/program/metas/meta[head='alias']">
<xsl:if test="part[1] and not(matches(part[1], '^[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*$'))">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The first part of the alias is invalid: </xsl:text>
<xsl:value-of select="eo:escape(part[1])"/>
<xsl:text> (it may only contain a relative name of the object, not its FQN)</xsl:text>
</xsl:element>
</xsl:if>
<xsl:for-each select="/program/metas/meta[head='alias' and not(matches(part[1], $pattern))]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The first part of the alias is invalid: </xsl:text>
<xsl:value-of select="eo:escape(part[1])"/>
<xsl:text> (it may only contain a relative name of the object, not its FQN)</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
27 changes: 13 additions & 14 deletions src/main/resources/org/eolang/lints/aliases/broken-alias-second.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ SOFTWARE.
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:variable name="pattern" select="'^Q\.[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*(\.[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*)*$'"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="/program/metas/meta[head='alias']">
<xsl:if test="part[2] and not(matches(part[2], '^[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*(\.[a-z]+[^&gt;&lt;.\[\]()!:&quot;@^$#&amp;/\s]*)*$'))">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The second part of the alias is invalid: </xsl:text>
<xsl:value-of select="eo:escape(part[2])"/>
<xsl:text> (it may only contain FQN)</xsl:text>
</xsl:element>
</xsl:if>
<xsl:for-each select="/program/metas/meta[head='alias' and not(matches(part[last()], $pattern))]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The second part of the alias is invalid: </xsl:text>
<xsl:value-of select="eo:escape(part[last()])"/>
<xsl:text> (it may only contain FQN started with 'Q.')</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ 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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="alias-without-tail" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="empty-alias" version="2.0">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="/program/metas/meta[head='alias']">
<xsl:if test="not(count(part))">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The alias doesn't have a tail</xsl:text>
</xsl:element>
</xsl:if>
<xsl:for-each select="/program/metas/meta[head='alias' and not(part[1]/text())]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The alias doesn't have a tail</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/eolang/lints/aliases/unused-alias.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ SOFTWARE.
<xsl:template match="/">
<defects>
<xsl:for-each select="/program/metas/meta[head='alias' and count(part)=2]">
<xsl:variable name="name" select="tokenize(tail, ' ')[2]"/>
<xsl:if test="count(//o[@base=$name]) = 0">
<xsl:variable name="name" select="tokenize(tail, ' ')[last()]"/>
<xsl:if test="count(//o[starts-with(@base, $name)])=0">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ SOFTWARE.
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[@base]">
<xsl:if test="count(o) != count(o[@as]) and count(o) != count(o[not(@as)])">
<xsl:variable name="args">
<xsl:choose>
<xsl:when test="starts-with(@base, '.')">
<xsl:copy-of select="o[position()&gt;1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="o"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="count($args/*) != count($args/*[@as]) and count($args/*) != count($args/*[not(@as)])">
<defect>
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:apply-templates select="//o[@atom and o[@name='@']]" mode="with-phi"/>
<xsl:apply-templates select="//o[@atom and o[@base='∅' and @name='@']]" mode="with-phi"/>
</defects>
</xsl:template>
<xsl:template match="o" mode="with-phi">
Expand Down
Loading

0 comments on commit 73df164

Please sign in to comment.