Skip to content

Commit

Permalink
misspell-rule: also use named resources
Browse files Browse the repository at this point in the history
from SRC_URI to identify variables names.
In before this issue was also hidden due to too high confidence
setting in the best match function.

Lower the confidence to 0.5 and add named resources for
at leats SRCREV_{x} pattern as valid and known variables.

Closes #468

Signed-off-by: Konrad Weihmann <kweihmann@outlook.com>
  • Loading branch information
priv-kweihmann committed Jan 4, 2024
1 parent 0f05c7c commit 1d726b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion oelint_adv/rule_base/rule_var_misspell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from oelint_parser.cls_item import Variable
from oelint_parser.constants import CONSTANTS
from oelint_parser.helper_files import get_valid_package_names
from oelint_parser.helper_files import get_valid_named_resources


class VarMisspell(Rule):
Expand All @@ -12,7 +13,7 @@ def __init__(self):
severity='warning',
message='<FOO>')

def get_best_match(self, item, _list, minconfidence=0.8):
def get_best_match(self, item, _list, minconfidence=0.5):
_dict = sorted([(SequenceMatcher(None, item, k).ratio(), k)
for k in _list], key=lambda x: x[0], reverse=True)
if _dict and _dict[0][0] >= minconfidence:
Expand All @@ -24,6 +25,7 @@ def check(self, _file, stash):
items = stash.GetItemsFor(filename=_file, classifier=Variable.CLASSIFIER,
attribute=Variable.ATTR_VAR)
_all = stash.GetItemsFor(filename=_file)
_extras = [f'SRCREV_{x}' for x in get_valid_named_resources(stash, _file)]
for i in items:
_cleanvarname = i.VarName
for pkg in get_valid_package_names(stash, _file, strippn=True):
Expand All @@ -34,6 +36,8 @@ def check(self, _file, stash):
_cleanvarname.rsplit(pkg, 1)) # pragma: no cover
if _cleanvarname in CONSTANTS.VariablesKnown:
continue
if _cleanvarname in _extras:
continue
_used = False
for a in _all:
if a == i:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_class_oelint_vars_misspell.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def test_bad(self, input_, id_, occurrence):
INITSCRIPT_PARAMS_${PN}-foo = "bar"
''',
},
{
'oelint_adv_test.bb':
'''
FOO:qemux86 = "1"
SRC_URI = "git://github.com/znc/znc.git;name=znc;branch=master;protocol=https \\
git://github.com/jimloco/Csocket.git;destsuffix=git/third_party/Csocket;name=Csocket;branch=master;protocol=https"
SRCREV_znc = "bf253640d33d03331310778e001fb6f5aba2989e"
SRCREV_Csocket = "e8d9e0bb248c521c2c7fa01e1c6a116d929c41b4"
''',
},
],
)
def test_good(self, input_, id_, occurrence):
Expand Down

0 comments on commit 1d726b1

Please sign in to comment.