-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oelint.var.inherit: check on correct usage
of inherit and inherit_defer statements Closes #477 Signed-off-by: Konrad Weihmann <[email protected]>
- Loading branch information
1 parent
34ec3f9
commit d84deb1
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import List, Tuple | ||
|
||
from oelint_parser.cls_item import Inherit | ||
from oelint_parser.cls_stash import Stash | ||
|
||
from oelint_adv.cls_rule import Rule | ||
|
||
|
||
class VarInherit(Rule): | ||
def __init__(self) -> None: | ||
self.__supports_defer = False | ||
super().__init__(id='oelint.var.inherit', | ||
severity='warning', | ||
message='<FOO>', | ||
appendix=['inherit', 'inherit_defer']) | ||
|
||
def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]: | ||
res = [] | ||
if not self.__supports_defer: | ||
return res | ||
items: List[Inherit] = stash.GetItemsFor(filename=_file, classifier=Inherit.CLASSIFIER) | ||
for i in items: | ||
if '${' not in i.RealRaw and i.Statement == 'inherit_defer': | ||
res += self.finding(i.Origin, i.InFileLine, | ||
'inherit_defer should only be used if there is a variable involved', | ||
appendix='inherit') | ||
if '${' in i.RealRaw and i.Statement == 'inherit': | ||
res += self.finding(i.Origin, i.InFileLine, | ||
'Variable detected in inherit statement. Use inherit_defer instead', | ||
appendix='inherit_defer') | ||
return res | ||
|
||
def check_release_range(self, release_range: List[str]) -> bool: | ||
if 'scarthgap' in release_range: | ||
self.__supports_defer = True | ||
return super().check_release_range(release_range) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest # noqa: I900 | ||
|
||
from .base import TestBaseClass | ||
|
||
|
||
class TestClassOelintVarInherit(TestBaseClass): | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.var.inherit.inherit_defer']) | ||
@pytest.mark.parametrize('occurrence', [1]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
'inherit ${A}', | ||
}, | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit def ${C} | ||
''', | ||
}, | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit def ${@oe.utils.ifelse(1 == 1, 'a', C} | ||
''', | ||
}, | ||
], | ||
) | ||
def test_bad_inherit(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.var.inherit.inherit']) | ||
@pytest.mark.parametrize('occurrence', [1]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
'inherit_defer A', | ||
}, | ||
], | ||
) | ||
def test_bad_inherit_defer(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.var.inherit.inherit']) | ||
@pytest.mark.parametrize('occurrence', [0]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit abc def | ||
''', | ||
}, | ||
], | ||
) | ||
def test_good_inherit(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) | ||
|
||
@pytest.mark.parametrize('id_', ['oelint.var.inherit.inherit_defer']) | ||
@pytest.mark.parametrize('occurrence', [0]) | ||
@pytest.mark.parametrize('input_', | ||
[ | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit_defer ${A} | ||
''', | ||
}, | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit_defer abc ${A} | ||
''', | ||
}, | ||
{ | ||
'oelint_adv_test.bb': | ||
''' | ||
inherit_defer ${@oe.utils.ifelse(1 == 1, 'a', C} | ||
''', | ||
}, | ||
], | ||
) | ||
def test_good_inherit_defer(self, input_, id_, occurrence): | ||
self.check_for_id(self._create_args(input_), id_, occurrence) |