-
Notifications
You must be signed in to change notification settings - Fork 19
feat(#13): missing-rho-reference lint
#450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5649a1e
13dcb3f
667add6
0159fe8
4d7fd36
6f59c21
140e974
fc4fbb0
94ed688
07f9892
fb0f8d9
a9f338c
268c521
8b7b070
14e7c5f
c76ab8d
22e9d89
771770a
306e92c
e367bfe
d73f842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| --> | ||
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="missing-rho-reference" version="2.0"> | ||
| <xsl:import href="/org/eolang/parser/_funcs.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/lineno.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/escape.xsl"/> | ||
| <xsl:import href="/org/eolang/funcs/defect-context.xsl"/> | ||
| <xsl:output encoding="UTF-8" method="xml"/> | ||
| <!-- | ||
| Recursively check if owner object is not auto named object, otherwise check is attribute is present. | ||
| You can read more about auto named objects here: https://news.eolang.org/2025-02-21-auto-named-abstract-objects.html. | ||
| @todo #13:45min Restructure `report-missing` template and its call in the root template. | ||
| Currently, we are calling `report-missing` template from root template to do the job, while | ||
| we should return only the parent object to which the rho attribute refers. Also, don't forget | ||
| to rename the template to something like `rho-parent`. | ||
| --> | ||
| <xsl:template name="report-missing"> | ||
| <xsl:param name="position"/> | ||
| <xsl:param name="attribute"/> | ||
| <xsl:param name="owner"/> | ||
| <xsl:choose> | ||
| <xsl:when test="$owner[not(eo:abstract(.))] or not(empty($owner/o[starts-with(@name, 'a🌵')]))"> | ||
| <xsl:variable name="up" select="ancestor::node()[$position + 1]"/> | ||
| <xsl:if test="name($up) = 'o'"> | ||
| <xsl:call-template name="report-missing"> | ||
| <xsl:with-param name="position" select="$position + 1"/> | ||
| <xsl:with-param name="attribute" select="$attribute"/> | ||
| <xsl:with-param name="owner" select="$up"/> | ||
| </xsl:call-template> | ||
|
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFragile ancestor navigation logic. Using Verify that the position calculation correctly navigates to parent objects in all cases by examining the XML structure: 🏁 Script executed: #!/bin/bash
# Search for test cases that might reveal the expected XML structure
fd -e yaml -e xml | xargs rg -l "missing-rho-reference|\\$\\.\\^" | head -10 | xargs catLength of output: 2048 Use The current lookup <xsl:variable name="up" select="ancestor::node()[$position + 1]"/>depends on every ancestor (including text or comment nodes) and is brittle. Instead, pick the Nth object ancestor directly: Replace - <xsl:variable name="up" select="ancestor::node()[$position + 1]"/>
+ <xsl:variable name="up" select="(ancestor::o)[$position + 1]"/>This way you only count 🤖 Prompt for AI Agents |
||
| </xsl:if> | ||
| </xsl:when> | ||
| <xsl:otherwise> | ||
| <!-- | ||
| @todo #13:90min Enable processing of rho references inside auto named objects. | ||
| For now we ignore them, but we need to check them as well, as they are abstract | ||
| objects. Don't forget to add test packs with auto named objects. | ||
| --> | ||
| <xsl:if test="not($owner/o[@name=$attribute]) and not(contains($owner/@name, 'a🌵'))"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent pattern matching for auto-named objects. Line 41 uses Apply consistent pattern matching: -<xsl:if test="not($owner/o[@name=$attribute]) and not(contains($owner/@name, 'a🌵'))">
+<xsl:if test="not($owner/o[@name=$attribute]) and not(starts-with($owner/@name, 'a🌵'))">🤖 Prompt for AI Agents |
||
| <xsl:element name="defect"> | ||
| <xsl:variable name="line" select="eo:lineno(@line)"/> | ||
| <xsl:attribute name="line"> | ||
| <xsl:value-of select="$line"/> | ||
| </xsl:attribute> | ||
| <xsl:if test="$line = '0'"> | ||
| <xsl:attribute name="context"> | ||
| <xsl:value-of select="eo:defect-context(.)"/> | ||
| </xsl:attribute> | ||
| </xsl:if> | ||
| <xsl:attribute name="severity"> | ||
| <xsl:text>error</xsl:text> | ||
| </xsl:attribute> | ||
| <xsl:text>The rho reference </xsl:text> | ||
| <xsl:value-of select="eo:escape($attribute)"/> | ||
| <xsl:text> is missing in </xsl:text> | ||
| <xsl:value-of select="eo:escape($owner/@name)"/> | ||
| <xsl:text> object</xsl:text> | ||
| </xsl:element> | ||
| </xsl:if> | ||
| </xsl:otherwise> | ||
| </xsl:choose> | ||
| </xsl:template> | ||
| <xsl:template match="/"> | ||
| <defects> | ||
| <xsl:for-each select="//o[@base and starts-with(@base, '$.^')]"> | ||
| <xsl:variable name="position" select="(count(tokenize(@base, '\^')) - 1) * 2"/> | ||
| <xsl:call-template name="report-missing"> | ||
| <xsl:with-param name="position" select="$position"/> | ||
| <xsl:with-param name="attribute" select="translate(translate(@base, '.^', ''), '$', '')"/> | ||
| <xsl:with-param name="owner" select="ancestor::node()[$position]"/> | ||
|
Comment on lines
+68
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainUnclear position calculation logic. The position calculation Add documentation or verify the calculation: 🏁 Script executed: #!/bin/bash
# Search for examples of rho references to understand the pattern
rg -A 5 -B 5 '\$\.\^' --type yamlLength of output: 35 Here’s a deeper inspection across all XSL error templates to see if this “* 2” pattern recurs and how other templates document it: 🏁 Script executed: #!/bin/bash
echo "1) Listing all missing-*-reference.xsl files:"
ls src/main/resources/org/eolang/lints/errors/missing-*-reference.xsl
echo
echo "2) Looking for all count(tokenize occurrences in these XSLs:"
rg -n "count(tokenize" src/main/resources/org/eolang/lints/errors/*.xsl
echo
echo "3) Checking how ancestor::node() is used elsewhere:"
rg -n "ancestor::node" src/main/resources/org/eolang/lints/errors/*.xsl
echo
echo "4) Finding the report-missing template definition for context:"
rg -n "<xsl:template name=\"report-missing\"" src/main/resources/org/eolang/lints/errors/*.xslLength of output: 2011 Document the position‐calculation logic The Please update <!--
Each '^' in @base represents a missing ρ-reference.
We step up two ancestor nodes per caret, so:
(count of '^') - 1 → number of jumps
× 2 → levels per jump
-->
<xsl:variable name="position"
select="(count(tokenize(@base, '\^')) - 1) * 2"/>
🤖 Prompt for AI Agents |
||
| </xsl:call-template> | ||
| </xsl:for-each> | ||
| </defects> | ||
| </xsl:template> | ||
| </xsl:stylesheet> | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||
| # Missing `^.` Reference | ||||||||||
|
|
||||||||||
| Each [rho][EO-specials] reference (`^.`) should point only to an existing | ||||||||||
| objects. | ||||||||||
|
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix grammar error in documentation. -Each [rho][EO-specials] reference (`^.`) should point only to an existing
-objects.
+Each [rho][EO-specials] reference (`^.`) should point only to existing
+objects.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~3-~3: The plural noun “objects” cannot be used with the article “an”. Did you mean “an existing object” or “existing objects”? (A_NNS) 🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| Incorrect: | ||||||||||
|
|
||||||||||
| ```eo | ||||||||||
| # Foo. | ||||||||||
| [] > foo | ||||||||||
| [] > message | ||||||||||
| [] > bar | ||||||||||
| ^.boom > @ | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Correct: | ||||||||||
|
|
||||||||||
| ```eo | ||||||||||
| # Foo. | ||||||||||
| [] > foo | ||||||||||
| [] > message | ||||||||||
| [] > bar | ||||||||||
| ^.message > @ | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| [EO-specials]: https://news.eolang.org/2024-05-14-rho-sigma-delta-lambda.html | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/errors/missing-rho-reference.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='error'])=0] | ||
| input: | | ||
| # Foo. | ||
| [] > foo | ||
| "yes" > message | ||
| [] > bar | ||
| while > @ | ||
| [i] >> | ||
| if. > @ | ||
| i.lt 5 | ||
| QQ.io.stdout | ||
| ^.^.message | ||
| true | ||
| true > [i] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/errors/missing-rho-reference.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='error'])=0] | ||
| input: | | ||
| # Foo. | ||
| [] > foo | ||
| [] > hello | ||
| [] > bar | ||
| ^.hello > @ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/errors/missing-rho-reference.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='error'])=0] | ||
| input: | | ||
| # Foo. | ||
| [] > foo | ||
| [] > hello | ||
| [] > message | ||
| [] > bar | ||
| ^.message > @ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| # yamllint disable rule:line-length | ||
| sheets: | ||
| - /org/eolang/lints/errors/missing-rho-reference.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='error'])=1] | ||
| - /defects/defect[@line='9'] | ||
| - /defects/defect[1][normalize-space()='The rho reference "messageeee" is missing in "foo" object'] | ||
| input: | | ||
| # Foo. | ||
| [] > foo | ||
| [] > bar | ||
| while > @ | ||
| [i] >> | ||
| if. > @ | ||
| i.lt 5 | ||
| QQ.io.stdout | ||
| ^.^.messageeee | ||
| true | ||
| true > [i] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| sheets: | ||
| - /org/eolang/lints/errors/missing-rho-reference.xsl | ||
| asserts: | ||
| - /defects[count(defect[@severity='error'])=1] | ||
| - /defects/defect[@line='4'] | ||
| input: | | ||
| # Foo. | ||
| [] > foo | ||
| [] > bar | ||
| ^.hello > @ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic appears inverted in the recursion condition.
The condition on line 25 seems to continue recursion when the owner is NOT abstract or HAS auto-named children. Based on the comment at line 13-14, shouldn't this skip auto-named objects instead? This logic appears inverted.
Consider reversing the logic:
📝 Committable suggestion
🤖 Prompt for AI Agents