Skip to content

Commit

Permalink
rulefile: enabled use of subids only
Browse files Browse the repository at this point in the history
In the latest rework an issues slipped in that
allowed only entire groups (or ID) to be
enabled/disabled, mind the subIDs as well when
loading the rules.
As they are filtered out afterwards it should be fine.
This applies of course only to the rule itself,
thus we don't run into conflicts with the fix method call

Closes #436

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Oct 12, 2023
1 parent 2542421 commit 06dbba2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oelint_adv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def run(args):

def rule_applicable(rule):
if isinstance(rule, Rule):
res = not _rule_file or rule.ID in _rule_file
res = not _rule_file or any(x in _rule_file for x in rule.get_ids()) # pragma: no cover
res &= rule.ID not in get_suppressions()
else:
res = not _rule_file or rule in _rule_file
Expand Down
30 changes: 29 additions & 1 deletion tests/test_user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,34 @@ def test_rulefile(self, input_):
issues = [x[1] for x in run(_args)]
assert(any(issues))

@pytest.mark.parametrize('input_',
[
{
'oelint adv-test.bb':
'''
A = "1"
''',
},
],
)
def test_rulefile_subids_only(self, input_):
# local imports only
from oelint_adv.__main__ import run

_rule_file = {
"oelint.var.mandatoryvar.DESCRIPTION": "error",
"oelint.var.mandatoryvar.LICENSE": "error",
"oelint.var.mandatoryvar.SRC_URI": "error"
}

_cstfile = self._create_tempfile('rules.json', json.dumps(_rule_file))

_args = self._create_args(
input_, extraopts=['--rulefile={file}'.format(file=_cstfile)])
issues = [x[1] for x in run(_args)]
assert(not any(any(x.startswith(y) for y in _rule_file.keys()) for x in issues))


@pytest.mark.parametrize('input_',
[
{
Expand Down Expand Up @@ -687,7 +715,7 @@ def test_rulefile_filtering2(self, input_):
_args = self._create_args(
input_, extraopts=['--rulefile={file}'.format(file=_cstfile)])
issues = [x[1] for x in run(_args)]
assert(not any(issues))
assert(not any("oelint.var.mandatoryvar.DESCRIPTION" in x for x in issues))

@pytest.mark.parametrize('input_',
[
Expand Down

0 comments on commit 06dbba2

Please sign in to comment.