From cb62bb58f1866d95f6da62afd750af2940579ff2 Mon Sep 17 00:00:00 2001 From: Marat-Tim Date: Sun, 11 May 2025 19:14:29 +0300 Subject: [PATCH 1/2] feat(#108): `@` must be at top level --- .../lints/misc/phi-not-at-top-level.xsl | 29 +++++++++++++++++++ .../motives/misc/phi-not-at-top-level.md | 27 +++++++++++++++++ .../allows-phi-on-top-level.yaml | 14 +++++++++ ...tches-phi-as-sub-attr-when-many-attrs.yaml | 17 +++++++++++ .../catches-phi-as-sub-attr.yaml | 13 +++++++++ 5 files changed, 100 insertions(+) create mode 100644 src/main/resources/org/eolang/lints/misc/phi-not-at-top-level.xsl create mode 100644 src/main/resources/org/eolang/motives/misc/phi-not-at-top-level.md create mode 100644 src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-on-top-level.yaml create mode 100644 src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr-when-many-attrs.yaml create mode 100644 src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-as-sub-attr.yaml 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..6b1aad4f0 --- /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-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..80701f463 --- /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,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 + @ 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 > @ From 6142061d412af1ad5ab7495d2b7e70a46fcb3554 Mon Sep 17 00:00:00 2001 From: Marat-Tim Date: Mon, 12 May 2025 16:13:04 +0300 Subject: [PATCH 2/2] feat(#108): new logic --- .../eolang/lints/misc/phi-not-at-top-level.xsl | 2 +- .../allows-phi-after-it-usage.yaml | 13 +++++++++++++ .../allows-phi-on-top-level.yaml | 1 - .../catches-phi-in-very-nested-object.yaml | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/allows-phi-after-it-usage.yaml create mode 100644 src/test/resources/org/eolang/lints/packs/single/phi-not-at-top-level/catches-phi-in-very-nested-object.yaml 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 index 6b1aad4f0..848115ac2 100644 --- 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 @@ -9,7 +9,7 @@ - + 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 index 80701f463..9a3ed214e 100644 --- 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 @@ -8,7 +8,6 @@ asserts: input: | # No comments. [] > app - baz > y bar > @ foo > x @ 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