Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misspell-rule: also use named resources #469

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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