Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
29 changes: 29 additions & 0 deletions src/main/resources/org/eolang/lints/misc/phi-not-at-top-level.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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" version="2.0" id="phi-not-at-top-level">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[@name = '@' and preceding-sibling::o[o[@base = '$.@']]]">
<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">warning</xsl:attribute>
<xsl:text>Phi attribute must be at the top level of attributes in a formation</xsl:text>
</defect>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
27 changes: 27 additions & 0 deletions src/main/resources/org/eolang/motives/misc/phi-not-at-top-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Attribute `@` must be at top level in formation

Since the decorated object is key piece of information in the code,
it's better to keep it at the top level of attributes in formation.
In other words, the `@` attribute shouldn't belong to an object that's
itself an attribute of the formation.
If such structure is needed, it’s better to move the `@`
declaration higher and use the name `@` to create object.

Incorrect:

```eo
# Comment.
[] > app
foo > x
bar > @
Copy link
Copy Markdown
Member

@yegor256 yegor256 May 12, 2025

Choose a reason for hiding this comment

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

@Marat-Tim maybe just this:

[] > app
  foo > x
  bar > @

This will better illustrate what you expect users to write.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yegor256 I don't get it - the example here is Incorrect, but the code you're suggesting doesn't actually violate rules of this lint

```

Correct:

```eo
# Comment.
[] > app
bar > @
foo > x
@
```
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/misc/phi-not-at-top-level.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# No comments.
[] > app
baz > y
bar > @
foo > x
@
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/misc/phi-not-at-top-level.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='6']
input: |
# No comments.
[] > app
a > b
c > d
e > f
g > @
h
i > j
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/misc/phi-not-at-top-level.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# No comments.
[] > app
foo > x
bar > @
Loading