diff --git a/src/main/resources/org/eolang/lints/misc/phi-not-at-top-level.xsl b/src/main/resources/org/eolang/lints/misc/phi-not-at-top-level.xsl new file mode 100644 index 000000000..848115ac2 --- /dev/null +++ b/src/main/resources/org/eolang/lints/misc/phi-not-at-top-level.xsl @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + warning + Phi attribute must be at the top level of attributes in a formation + + + + + diff --git a/src/main/resources/org/eolang/motives/misc/phi-not-at-top-level.md b/src/main/resources/org/eolang/motives/misc/phi-not-at-top-level.md new file mode 100644 index 000000000..62b553b4f --- /dev/null +++ b/src/main/resources/org/eolang/motives/misc/phi-not-at-top-level.md @@ -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 > @ +``` + +Correct: + +```eo +# Comment. +[] > app + bar > @ + foo > x + @ +``` diff --git a/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-after-it-usage.yaml b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-after-it-usage.yaml new file mode 100644 index 000000000..0b78954b7 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-after-it-usage.yaml @@ -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'])=0] +input: | + # No comments. + [] > app + foo > x + @ + bar > @ diff --git a/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-on-top-level.yaml b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-on-top-level.yaml new file mode 100644 index 000000000..9a3ed214e --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-on-top-level.yaml @@ -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'])=0] +input: | + # No comments. + [] > app + bar > @ + foo > x + @ diff --git a/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr-when-many-attrs.yaml b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr-when-many-attrs.yaml new file mode 100644 index 000000000..bcaa6eb51 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr-when-many-attrs.yaml @@ -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 diff --git a/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr.yaml b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr.yaml new file mode 100644 index 000000000..228fc5980 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr.yaml @@ -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 > @ diff --git a/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-in-very-nested-object.yaml b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-in-very-nested-object.yaml new file mode 100644 index 000000000..d87606764 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-in-very-nested-object.yaml @@ -0,0 +1,16 @@ +# 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='5'] +input: | + # No comments. + [] > app + a > x + b + c > @ + d + e