From 1d726b122c9792195e1b3ad925a25eec1e66b1e2 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Thu, 4 Jan 2024 18:42:59 +0100 Subject: [PATCH] misspell-rule: also use named resources 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 --- oelint_adv/rule_base/rule_var_misspell.py | 6 +++++- tests/test_class_oelint_vars_misspell.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/oelint_adv/rule_base/rule_var_misspell.py b/oelint_adv/rule_base/rule_var_misspell.py index 975ab5f1..758374fd 100644 --- a/oelint_adv/rule_base/rule_var_misspell.py +++ b/oelint_adv/rule_base/rule_var_misspell.py @@ -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): @@ -12,7 +13,7 @@ def __init__(self): severity='warning', message='') - 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: @@ -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): @@ -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: diff --git a/tests/test_class_oelint_vars_misspell.py b/tests/test_class_oelint_vars_misspell.py index 60fdf77d..aff4fe41 100644 --- a/tests/test_class_oelint_vars_misspell.py +++ b/tests/test_class_oelint_vars_misspell.py @@ -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):