diff --git a/src/main/resources/org/eolang/lints/errors/missing-rho-reference.xsl b/src/main/resources/org/eolang/lints/errors/missing-rho-reference.xsl new file mode 100644 index 000000000..5efd39184 --- /dev/null +++ b/src/main/resources/org/eolang/lints/errors/missing-rho-reference.xsl @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error + + The rho reference + + is missing in + + object + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/org/eolang/motives/errors/missing-rho-reference.md b/src/main/resources/org/eolang/motives/errors/missing-rho-reference.md new file mode 100644 index 000000000..65060ab67 --- /dev/null +++ b/src/main/resources/org/eolang/motives/errors/missing-rho-reference.md @@ -0,0 +1,26 @@ +# Missing `^.` Reference + +Each [rho][EO-specials] reference (`^.`) should point only to an existing +objects. + +Incorrect: + +```eo +# Foo. +[] > foo + [] > message + [] > bar + ^.boom > @ +``` + +Correct: + +```eo +# Foo. +[] > foo + [] > message + [] > bar + ^.message > @ +``` + +[EO-specials]: https://news.eolang.org/2024-05-14-rho-sigma-delta-lambda.html diff --git a/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object-from-deeply-nested.yaml b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object-from-deeply-nested.yaml new file mode 100644 index 000000000..97703bc4d --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object-from-deeply-nested.yaml @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/errors/missing-rho-reference.xsl +asserts: + - /defects[count(defect[@severity='error'])=0] +input: | + # Foo. + [] > foo + "yes" > message + [] > bar + while > @ + [i] >> + if. > @ + i.lt 5 + QQ.io.stdout + ^.^.message + true + true > [i] diff --git a/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object.yaml b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object.yaml new file mode 100644 index 000000000..0678494c3 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-to-present-object.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/errors/missing-rho-reference.xsl +asserts: + - /defects[count(defect[@severity='error'])=0] +input: | + # Foo. + [] > foo + [] > hello + [] > bar + ^.hello > @ diff --git a/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-when-parent-has-multiple-objects.yaml b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-when-parent-has-multiple-objects.yaml new file mode 100644 index 000000000..d5a8e2507 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/allows-rho-ref-when-parent-has-multiple-objects.yaml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/errors/missing-rho-reference.xsl +asserts: + - /defects[count(defect[@severity='error'])=0] +input: | + # Foo. + [] > foo + [] > hello + [] > message + [] > bar + ^.message > @ diff --git a/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catch-missing-rho-ref-from-deeply-nested.yaml b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catch-missing-rho-ref-from-deeply-nested.yaml new file mode 100644 index 000000000..1ab946947 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catch-missing-rho-ref-from-deeply-nested.yaml @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com +# SPDX-License-Identifier: MIT +--- +# yamllint disable rule:line-length +sheets: + - /org/eolang/lints/errors/missing-rho-reference.xsl +asserts: + - /defects[count(defect[@severity='error'])=1] + - /defects/defect[@line='9'] + - /defects/defect[1][normalize-space()='The rho reference "messageeee" is missing in "foo" object'] +input: | + # Foo. + [] > foo + [] > bar + while > @ + [i] >> + if. > @ + i.lt 5 + QQ.io.stdout + ^.^.messageeee + true + true > [i] diff --git a/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catches-missing-rho-ref.yaml b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catches-missing-rho-ref.yaml new file mode 100644 index 000000000..ba58717dc --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/missing-rho-reference/catches-missing-rho-ref.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/errors/missing-rho-reference.xsl +asserts: + - /defects[count(defect[@severity='error'])=1] + - /defects/defect[@line='4'] +input: | + # Foo. + [] > foo + [] > bar + ^.hello > @