Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3fb11b6
feat(#107): decode ascii to string
h1alexbel Jan 7, 2025
455bcd3
feat(#107): sprintf args
h1alexbel Jan 8, 2025
fcba685
feat(#107): nested-args
h1alexbel Jan 8, 2025
06cf2f5
feat(#107): cases
h1alexbel Jan 8, 2025
245c6fb
feat(#107): passes
h1alexbel Jan 8, 2025
0907ec0
feat(#107): more tests
h1alexbel Jan 8, 2025
16bfa10
feat(#107): tests
h1alexbel Jan 8, 2025
b258f13
feat(#107): wrong-sprintf-arguments, fqn
h1alexbel Jan 8, 2025
ba66bb5
feat(#107): clean for qulice
h1alexbel Jan 8, 2025
b9b4612
Merge branch 'master' into 107-sprintf
h1alexbel Jan 8, 2025
8f3af6c
chore: timeouts
h1alexbel Jan 8, 2025
35f38a5
chore: timeouts 2x
h1alexbel Jan 8, 2025
d3ed3d6
chore: default timeout puzzle
h1alexbel Jan 8, 2025
14404b0
chore: unused
h1alexbel Jan 8, 2025
7169d59
feat(#107): allows more formatters
h1alexbel Jan 9, 2025
303aef2
feat(#107): path to fqn
h1alexbel Jan 9, 2025
061ac56
chore: move to separate bug
h1alexbel Jan 9, 2025
1d2f6a6
feat(#107): trigger
h1alexbel Jan 9, 2025
b2bf44a
feat(#107): back
h1alexbel Jan 9, 2025
61ed732
feat(#107): sprintf-text
h1alexbel Jan 12, 2025
374f92c
feat(#107): empty tuple
h1alexbel Jan 15, 2025
ad82171
feat(#107): iterates all sprintfs
h1alexbel Jan 15, 2025
4f13f86
feat(#107): indents
h1alexbel Jan 17, 2025
2466b0a
Merge branch 'master' into 107-sprintf
h1alexbel Jan 17, 2025
97c111e
feat(#107): clean grammar
h1alexbel Jan 17, 2025
3a06fc0
feat(#107): allows percentage sign
h1alexbel Jan 19, 2025
bee758f
feat(#107): clean grammar
h1alexbel Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eo="https://www.eolang.org" version="2.0" id="wrong-sprintf-arguments">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:function name="eo:hex-to-placeholder" as="xs:integer">
<xsl:param name="hex" as="xs:string"/>
<xsl:variable name="hex-upper" select="upper-case($hex)"/>
<xsl:variable name="length" select="string-length($hex-upper)"/>
<xsl:variable name="decimal" select="sum(for $i in 1 to $length return (index-of(string-to-codepoints('0123456789ABCDEF'), string-to-codepoints(substring($hex-upper, $i, 1))) - 1) * xs:integer(math:pow(16, $length - $i)))"/>
<xsl:sequence select="$decimal"/>
</xsl:function>
<xsl:variable name="sprintf" select="//o[@base='.sprintf'][o[@base='.txt']/o[@base='.eolang']/o[@base='org']] | //o[@base='.sprintf'][o[@base='.txt']/o[@base='.eolang']/o[@base='org']/o[@base='Q']]"/>
<xsl:template name="nested-args">
<xsl:param name="node"/>
<xsl:for-each select="$node/o[not(@base='tuple') and not(@base='.empty')]">
<xsl:value-of select="@base"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:for-each select="$node/o[@base='tuple']">
<xsl:call-template name="nested-args">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template match="/">
<defects>
<xsl:for-each select="$sprintf">
<xsl:variable name="sprintf-text" select="o[@base='string'][1]/text()"/>
<xsl:variable name="tokens" select="tokenize($sprintf-text, '-')"/>
<xsl:variable name="placeholder">
<xsl:for-each select="$tokens">
<xsl:value-of select="codepoints-to-string(eo:hex-to-placeholder(.))"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="allowed">
<xsl:analyze-string select="$placeholder" regex="%[sdfxb]">
<xsl:matching-substring>
<match/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="declared" select="count($allowed/match)"/>
<xsl:variable name="tupled" select="o[@base='tuple']/o[not(@base='.empty')]"/>
<xsl:variable name="nested">
<xsl:for-each select="$tupled">
<xsl:call-template name="nested-args">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="used" select="count($tupled[not(@base='tuple')]/@base) + count(tokenize(substring($nested, 1, string-length($nested) - 1), '\s+'))"/>
<xsl:if test="$sprintf-text != '' and $declared != $used">
<defect>
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
</xsl:attribute>
<xsl:text>The sprintf object has the wrong number of arguments: </xsl:text>
<xsl:value-of select="$declared"/>
<xsl:text> in the placeholder, but </xsl:text>
<xsl:value-of select="$used"/>
<xsl:text> are passed</xsl:text>
</defect>
</xsl:if>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Wrong `QQ.txt.sprintf` Arguments

The `QQ.txt.sprintf` object must have a match between its placeholder variables
and passed arguments.

Incorrect:

```eo
[] > app
QQ.io.stdout > @
QQ.txt.sprintf
"Hello, %s! Your account is %d."
* name
```

Correct:

```eo
[] > app
QQ.io.stdout > @
QQ.txt.sprintf
"Hello, %s! Your account is %d."
* name acc
```
2 changes: 1 addition & 1 deletion src/test/java/org/eolang/lints/GrammarMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean matches(final Object obj) {
for (final Rule rule : tool.getAllActiveRules()) {
if (rule instanceof SpellingCheckRule) {
((SpellingCheckRule) rule).addIgnoreTokens(
Arrays.asList("decoratee", "eolang")
Arrays.asList("decoratee", "eolang", "sprintf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel better enquote the string inside the error message, to make it look like this:

According to the formatting template of the "sprintf" object, a tuple of 3 elements is expected as the second argument of it, while a tuple of 2 elements is provided

);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s! Your account is %d."
* name acc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s (%x, match: %b)! Your account is %d, your temperature %f."
* name name.as-bytes true acc t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Привет, %d"
* 52
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s"
* "Jeff"
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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s! Your account is %d."
*
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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s! Your account is %d."
* name acc foo bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='7']
input: |
# App.
[] > app
QQ.io.stdout > @
org.eolang.txt.sprintf
"Hello, %s! Your account is %d."
* name acc
org.eolang.txt.sprintf
"Hello, %s! Your account is %f."
* f
Loading
Loading