From f12992dddcdf72b9474e0d28cefbb5bbb71019d2 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Thu, 27 Jun 2024 06:10:28 +0200 Subject: [PATCH] multilineident: add tests and documentation for the new fix method Signed-off-by: Konrad Weihmann --- README.md | 2 +- .../rule_base/rule_var_multilineindent.py | 2 +- .../test_class_oelint_vars_multilineident.py | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7cd8a4..04c97b0 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Rules marked with **[S]** can have multiple sub-IDs * [oelint.vars.listappend](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.listappend.md) - Proper append/prepend to lists **[F]** * [oelint.vars.mispell.unknown](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.mispell.unknown.md) - Variable is not known from CONSTANTS, typo is unlikely * [oelint.vars.mispell](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.mispell.md) - Possible typo detected -* [oelint.vars.multilineident](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.multilineident.md) - On a multiline assignment, line indent is desirable +* [oelint.vars.multilineident](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.multilineident.md) - On a multiline assignment, line indent is desirable **[F]** * [oelint.vars.notneededspace](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.notneededspace.md) - Space at the beginning of the var is not needed **[F]** * [oelint.vars.notrailingslash](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.notrailingslash.md) - Variable shall not end on a slash * [oelint.vars.overrideappend](https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.overrideappend.md) - Check correct order of append/prepend on variables with override syntax diff --git a/oelint_adv/rule_base/rule_var_multilineindent.py b/oelint_adv/rule_base/rule_var_multilineindent.py index 062424a..15ab067 100644 --- a/oelint_adv/rule_base/rule_var_multilineindent.py +++ b/oelint_adv/rule_base/rule_var_multilineindent.py @@ -72,7 +72,7 @@ def fix(self, _file: str, stash: Stash) -> List[str]: found = True _lines[index] = " " * _likeliest_indent + _lines[index].lstrip() res.append(_file) - if found: + if found: # pragma: no cover i.Raw = "\n".join(_lines) i.RealRaw = "\n".join(_lines) return res diff --git a/tests/test_class_oelint_vars_multilineident.py b/tests/test_class_oelint_vars_multilineident.py index c218cff..1901df5 100644 --- a/tests/test_class_oelint_vars_multilineident.py +++ b/tests/test_class_oelint_vars_multilineident.py @@ -75,6 +75,57 @@ class TestClassOelintVarsMultilineIdent(TestBaseClass): def test_bad(self, input_, id_, occurrence): self.check_for_id(self._create_args(input_), id_, occurrence) + @pytest.mark.parametrize('id_', ['oelint.vars.multilineident']) + @pytest.mark.parametrize('input_', + [ + { + 'oelint_adv_test.bb': + ''' + D = "a \\ + e \\ + " + ''', + }, + { + 'oelint_adv_test.bb': + ''' + D = " a \\ + e \\ + " + ''', + }, + { + 'oelint_adv_test.bb': + ''' + A = "a \\ + b \\ + c \\ + " + ''', + }, + { + 'oelint_adv_test.bb': + ''' + A:append = "a \\ + b \\ + c \\ + " + ''', + }, + { + 'oelint_adv_test.bb': + ''' + A += "a \\ + b \\ + c \\ + " + ''', + }, + ], + ) + def test_fix(self, input_, id_): + self.fix_and_check(self._create_args_fix(input_), id_) + @pytest.mark.parametrize('id_', ['oelint.vars.multilineident']) @pytest.mark.parametrize('occurrence', [2]) @pytest.mark.parametrize('input_',