Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions src/main/resources/org/eolang/lints/refs/base-must-be-merged.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="base-must-be-merged" 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/defect-context.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[not(eo:abstract(.)) and parent::o[starts-with(@base, '.')] and not(starts-with(@base, '.')) and not(text())]">
Copy link
Member

Choose a reason for hiding this comment

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

@Marat-Tim actually it's pretty good, but I think you missed the one more condition - and not(o). You can add this test:

<o base=".foo">
  <o base="bar">
    <o base="baz"/>
  </o>
</o>

I believe with current approach you'll get a defect, but there's no one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxonfjvipon This is checked with not(text()) because if element has an inner object, text() returns its text content. I added this test

<xsl:message select="."/>
<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>warning</xsl:text>
</xsl:attribute>
<xsl:text>Object </xsl:text>
<xsl:if test="@name">
<xsl:value-of select="@name"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:text>can be merged with its parent</xsl:text>
</defect>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
64 changes: 64 additions & 0 deletions src/main/resources/org/eolang/motives/refs/base-must-be-merged.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# '@base' attributes of objects must be merged if possible

In [XMIR], the object must be merged with parent if the following
conditions are met:

1. Object is not abstract
2. Attribute `@base` of parent object should start with dot
3. Attribute `@base` object should not start with dot
4. Object should not have data
5. Object should not have inner objects

Incorrect:

```xml
<o base=".foo">
<o base=".bar">
<o base="x"/>
</o>
</o>
```

Correct:

```xml
<o base="x.bar.foo"/>
```

Correct:

```xml
<o base=".foo">
<o base=".bar"/>
</o>
```

Correct:

```xml
<o base=".foo">
<o/>
</o>
```

Correct:

```xml
<o base=".foo">
<o base="bar">
A1-B2-C3-D4-E5
</o>
</o>
```

Correct:

```xml
<o base=".foo">
<o base="bar">
<o base="baz"/>
</o>
</o>
```

[XMIR]: https://news.eolang.org/2022-11-25-xmir-guide.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/refs/base-must-be-merged.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='2']
document: |
<object>
<o base=".foo">
<o base=".bar">
<o base="x" line="2"/>
</o>
</o>
</object>
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/refs/base-must-be-merged.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<object>
<o base=".foo">
<o base=".bar"/>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/refs/base-must-be-merged.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<object>
<o base=".foo">
<o base="bar">
A1-B2-C3-D4-E5
</o>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/refs/base-must-be-merged.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<object>
<o base=".foo">
<o base="bar">
<o base="baz"/>
</o>
</o>
</object>
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/refs/base-must-be-merged.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<object>
<o base=".foo">
<o/>
</o>
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/refs/base-must-be-merged.xsl
asserts:
- /defects/defect[contains(text(), 'abracadabra')]
document: |
<object>
<o base=".foo">
<o base=".bar">
<o base="x" name="abracadabra"/>
</o>
</o>
</object>
Loading