diff --git a/src/main/resources/org/eolang/lints/design/excessive-visibility.xsl b/src/main/resources/org/eolang/lints/design/excessive-visibility.xsl new file mode 100644 index 000000000..e060cc703 --- /dev/null +++ b/src/main/resources/org/eolang/lints/design/excessive-visibility.xsl @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + warning + true + The method + + is public but is not used by any unit test; obfuscate it with >> + + + + + + diff --git a/src/main/resources/org/eolang/motives/design/excessive-visibility.md b/src/main/resources/org/eolang/motives/design/excessive-visibility.md new file mode 100644 index 000000000..adceec50c --- /dev/null +++ b/src/main/resources/org/eolang/motives/design/excessive-visibility.md @@ -0,0 +1,18 @@ +# Excessive visibility + +Public methods should be exercised by a unit test. If a method is only an +implementation detail and no test refers to it, make it private with the +`>>` decoration instead of exposing it as part of the object's public API. + +Incorrect: + +```eo +[text] > phrase + text.index-of " " > position + + [] +> checks-phrase + phrase "Object Thinking" > @ +``` + +`position` is public but the test never refers to it. It should be written as +`text.index-of " " >> position`. diff --git a/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/allows-public-method-used-by-test.yaml b/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/allows-public-method-used-by-test.yaml new file mode 100644 index 000000000..4e1133639 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/allows-public-method-used-by-test.yaml @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/excessive-visibility.xsl +defects: 0 +input: | + # Phrase. + [text] > phrase + text.index-of " " > position + [] +> checks-phrase + position > @ diff --git a/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/catches-public-method-not-used-by-test.yaml b/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/catches-public-method-not-used-by-test.yaml new file mode 100644 index 000000000..b65ffe911 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/excessive-visibility/catches-public-method-not-used-by-test.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/excessive-visibility.xsl +asserts: + - /defects[count(defect[@severity='warning' and @experimental])=1] + - /defects/defect[@line='3'] + - /defects/defect[contains(text(), 'position')] +input: | + # Phrase. + [text] > phrase + text.index-of " " > position + [] +> checks-phrase + phrase "Object Thinking" > @