Skip to content

Commit

Permalink
inline-suppressions: allow comments after ids
Browse files Browse the repository at this point in the history
filter out any words that are not part of the
known IDs list and treat them as comments.
Like this further explanations can be added by the user

Closes #679

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Jan 8, 2025
1 parent 059ba75 commit 61e79b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,17 @@ You can find an example file [here](docs/.oelint.cfg.example)
You can suppress one or more checks on a line by line basis
```bitbake
# nooelint: <id>[,<id>,...]
# nooelint: <id>[,<id>,...][ comment]
```
suppresses all the specified IDs for the next line.
Multiple IDs can be separated by commas.
You can add a comment after the ids and separated by at least a single space.
### Example
```bitbake
# nooelint: oelint.vars.insaneskip
# nooelint: oelint.vars.insaneskip - this is an acceptable risk here
INSANE_SKIP:${PN} = "foo"
```
Expand Down
7 changes: 5 additions & 2 deletions oelint_adv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def group_run(group: List[Tuple],
if item.Origin not in inline_supp_map: # pragma: no cover
inline_supp_map[item.Origin] = {}
inline_supp_map[item.Origin][item.InFileLine] = [
x.strip() for x in m.group('ids').split(',') if x]

x.strip() for x in re.split(r',|\s+', m.group('ids')) if x]
state.inline_suppressions = {**state.inline_suppressions, **inline_supp_map}

rules = [copy.deepcopy(x) for x in rules]
Expand Down Expand Up @@ -237,10 +237,13 @@ def group_run(group: List[Tuple],
lvl='debug', msg='Applied automatic fixes'))

if any(isinstance(x, FileNotApplicableInlineSuppression) for x in rules):
known_ids = list(itertools.chain(*[x.get_ids() for x in rules]))
for _file, _lineobj in inline_supp_map.items():
for _line, _ids in _lineobj.items():
for _id in _ids:
if not state.get_inline_suppression_seen(_file, _line, _id):
if _id not in known_ids:
continue
obj = FileNotApplicableInlineSuppression(state)
issues += obj.finding(_file, _line, override_msg=obj.Msg.format(id=_id))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_oelint_inlinesupp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class TestClassOelintNAInlineSuppression(TestBaseClass):
{
'oelint_adv_test.bb':
'''
# nooelint: foo.bar.baz
# nooelint: oelint.var.badimagefeature
A = "2"
''',
},
{
'oelint_adv_test.bb':
'''
# nooelint: oelint.vars.mispell, foo.bar.baz
# nooelint: oelint.vars.mispell, oelint.var.badimagefeature
SRR_URI = "2"
''',
},
Expand Down
17 changes: 17 additions & 0 deletions tests/test_inlinesuppressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,20 @@ def test_inlinesuppressions_multiple_scope(self, input_):
def test_inlinesuppressions_remove_empty(self, input_):
self.check_for_id(self._create_args(input_),
'oelint.var.badimagefeature', 0)

@pytest.mark.parametrize('input_',
[
{
'oelint adv-test.bb':
'''
# nooelint: oelint.var.badimagefeature.allow-empty-password - this is a comment
IMAGE_FEATURES:append = " \
allow-empty-password \
"
''',
},
],
)
def test_inlinesuppressions_with_comment(self, input_):
self.check_for_id(self._create_args(input_),
'oelint.var.badimagefeature', 0)

0 comments on commit 61e79b2

Please sign in to comment.