Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: objectionary/lints
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.25
Choose a base ref
...
head repository: objectionary/lints
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 12 commits
  • 8 files changed
  • 3 contributors

Commits on Dec 13, 2024

  1. Copy the full SHA
    81f2655 View commit details
  2. Copy the full SHA
    eb4b7ab View commit details
  3. Copy the full SHA
    6d64245 View commit details
  4. Copy the full SHA
    218200a View commit details
  5. Copy the full SHA
    26e8f05 View commit details
  6. Copy the full SHA
    d628795 View commit details
  7. Copy the full SHA
    61ba2f3 View commit details

Commits on Dec 15, 2024

  1. extra tests

    yegor256 committed Dec 15, 2024
    Copy the full SHA
    e278650 View commit details

Commits on Dec 16, 2024

  1. Copy the full SHA
    d6dc979 View commit details
  2. Copy the full SHA
    600f25e View commit details
  3. new version in README

    rultor authored and github-actions[bot] committed Dec 16, 2024
    Copy the full SHA
    f1fbded View commit details
  4. Merge pull request #146 from objectionary/version-up

    New version in README
    yegor256 authored Dec 16, 2024
    Copy the full SHA
    9ed793e View commit details
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ We use this package as a dependency in the
<dependency>
<groupId>org.eolang</groupId>
<artifactId>lints</artifactId>
<version>0.0.24</version>
<version>0.0.25</version>
</dependency>
```

7 changes: 7 additions & 0 deletions src/it/lints-it/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Lints integration test

If you need to run only this test, use the following command:

```shell
mvn clean integration-test -Dinvoker.test=lints-it -DskipTests
```
34 changes: 16 additions & 18 deletions src/main/java/org/eolang/lints/LintByXsl.java
Original file line number Diff line number Diff line change
@@ -59,24 +59,6 @@ final class LintByXsl implements Lint<XML> {
*/
private final Input doc;

/**
* Ctor.
* @param xsl Relative path of XSL
* @param motive Relative path of motive document
* @throws IOException If fails
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
LintByXsl(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.sheet = new XSLDocument(xml, this.rule).with(new ClasspathSources());
this.doc = motive;
}

/**
* Ctor.
* @param xsl Relative path of XSL
@@ -93,6 +75,22 @@ final class LintByXsl implements Lint<XML> {
);
}

/**
* Ctor.
* @param xsl Relative path of XSL
* @param motive Relative path of a motive document
* @throws IOException If fails
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
LintByXsl(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.sheet = new MeasuredXsl(
this.rule, new XSLDocument(xml, this.rule).with(new ClasspathSources())
);
this.doc = motive;
}

@Override
public Collection<Defect> defects(final XML xmir) {
final XML report = this.sheet.transform(xmir);
109 changes: 109 additions & 0 deletions src/main/java/org/eolang/lints/MeasuredXsl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 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.log.Logger;
import com.jcabi.xml.Sources;
import com.jcabi.xml.XML;
import com.jcabi.xml.XSL;

/**
* XSL that measures the time of transformation.
* @since 0.1
*/
final class MeasuredXsl implements XSL {

/**
* Default threshold in milliseconds.
*/
private static final long DEFAULT = 100L;

/**
* Rule name.
*/
private final String rule;

/**
* Origin XSL.
*/
private final XSL origin;

/**
* Custom threshold in milliseconds.
*/
private final long threshold;

/**
* Ctor.
* @param name Rule name.
* @param decorated Decorated XSL.
*/
MeasuredXsl(final String name, final XSL decorated) {
this(name, decorated, MeasuredXsl.DEFAULT);
}

/**
* Ctor.
* @param name Rule name.
* @param decorated Decorated XSL.
* @param threshold Custom threshold in milliseconds.
*/
private MeasuredXsl(final String name, final XSL decorated, final long threshold) {
this.rule = name;
this.origin = decorated;
this.threshold = threshold;
}

@Override
public XML transform(final XML xml) {
final long start = System.currentTimeMillis();
final XML res = this.origin.transform(xml);
final long end = System.currentTimeMillis();
if (end - start > this.threshold) {
Logger.warn(
this,
"XSL transformation '%s' took %[ms]s, whereas threshold is %[ms]s\n",
this.rule,
end - start,
this.threshold
);
}
return res;
}

@Override
public String applyTo(final XML xml) {
return this.origin.applyTo(xml);
}

@Override
public XSL with(final Sources src) {
return this.origin.with(src);
}

@Override
public XSL with(final String name, final Object value) {
return this.origin.with(name, value);
}
}
Original file line number Diff line number Diff line change
@@ -26,24 +26,25 @@ SOFTWARE.
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[@line and @name]">
<xsl:for-each select="/program/objects//o[@line and @name]">
<xsl:apply-templates select="." mode="check"/>
</xsl:for-each>
</defects>
</xsl:template>
<xsl:template match="o" mode="check">
<xsl:variable name="x" select="."/>
<xsl:for-each select="(following::o | descendant::o)[@name=$x/@name and @line=$x/@line]">
<xsl:for-each select="/program/objects//o[not(. is $x) and @name=$x/@name and @line=$x/@line]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="if (@line) then @line else '0'"/>
<xsl:value-of select="@line"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The name "</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>" has already been used on the same line</xsl:text>
<xsl:text>" has been used twice on line no.</xsl:text>
<xsl:value-of select="@line"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
17 changes: 5 additions & 12 deletions src/main/resources/org/eolang/lints/refs/line-is-absent.xsl
Original file line number Diff line number Diff line change
@@ -29,23 +29,16 @@ SOFTWARE.
everything is OK. If we don't, we report an error.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:key name="objsNoLineByName" match="o[not(@line)]" use="@name"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[@base and not(starts-with(@base, '.')) and @base!='$' and @base!='^']">
<xsl:variable name="self" select="."/>
<xsl:variable name="target" select="ancestor::*[o[@name=$self/@base and not(@line)]][1]/o[@name=$self/@base and not(@line)]"/>
<xsl:variable name="target" select="key('objsNoLineByName', $self/@base)"/>
<xsl:if test="$target">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="if (@line) then @line else '0'"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>error</xsl:text>
</xsl:attribute>
<xsl:text>The @line attribute is absent at "</xsl:text>
<xsl:value-of select="$target/@name"/>
<xsl:text>"</xsl:text>
</xsl:element>
<defect line="{if (@line) then @line else '0'}" severity="error">
The @line attribute is absent at <xsl:value-of select="$target/@name"/>
</defect>
</xsl:if>
</xsl:for-each>
</defects>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
sheets:
- /org/eolang/lints/critical/same-line-names.xsl
asserts:
- /defects[count(defect)=0]
input: |
# no comments.
[] > app
foo.
bar > @
x
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
sheets:
- /org/eolang/lints/critical/same-line-names.xsl
document:
<?xml version="1.0" encoding="UTF-8"?>
<program>
<objects>
<o name="foo" line="4"/>
<o name="foo" line="4"/>
</objects>
</program>
asserts:
- /defects[count(defect)=2]