-
Notifications
You must be signed in to change notification settings - Fork 17
feat(#256): lint that find not merged bases #535
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
Open
Marat-Tim
wants to merge
3
commits into
objectionary:master
Choose a base branch
from
Marat-Tim:256
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/resources/org/eolang/lints/refs/base-must-be-merged.xsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())]"> | ||
| <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
64
src/main/resources/org/eolang/motives/refs/base-must-be-merged.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
16 changes: 16 additions & 0 deletions
16
...sources/org/eolang/lints/packs/single/base-must-be-merged/catches-not-merged-objects.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
13 changes: 13 additions & 0 deletions
13
...s/org/eolang/lints/packs/single/base-must-be-merged/no-merge-if-base-starts-with-dot.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
15 changes: 15 additions & 0 deletions
15
...ources/org/eolang/lints/packs/single/base-must-be-merged/no-merge-if-object-has-data.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
15 changes: 15 additions & 0 deletions
15
...rg/eolang/lints/packs/single/base-must-be-merged/no-merge-if-object-has-inner-object.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
13 changes: 13 additions & 0 deletions
13
...ces/org/eolang/lints/packs/single/base-must-be-merged/no-merge-if-object-is-abstract.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
15 changes: 15 additions & 0 deletions
15
...s/org/eolang/lints/packs/single/base-must-be-merged/prints-name-of-not-merged-object.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Marat-Tim actually it's pretty good, but I think you missed the one more condition -
and not(o). You can add this test:I believe with current approach you'll get a defect, but there's no one
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.
@maxonfjvipon This is checked with
not(text())because if element has an inner object,text()returns its text content. I added this test