From 7e9d7ec62f117313858bbed0f0e86c2e7d1983e4 Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Tue, 9 Jan 2024 07:23:05 +0100 Subject: [PATCH] misspell: make confidence configurable but go back to 0.8 as a default as too many users were complaining about too many new warnings. Value can now be controlled by env var OELINT_MISSPELL_CONFIDENCE Closes #482 Signed-off-by: Konrad Weihmann --- oelint_adv/rule_base/rule_var_misspell.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/oelint_adv/rule_base/rule_var_misspell.py b/oelint_adv/rule_base/rule_var_misspell.py index 703e2205..77edcede 100644 --- a/oelint_adv/rule_base/rule_var_misspell.py +++ b/oelint_adv/rule_base/rule_var_misspell.py @@ -1,11 +1,14 @@ +import os from difflib import SequenceMatcher -from oelint_adv.cls_rule import Rule -from oelint_parser.cls_item import Function -from oelint_parser.cls_item import Variable +from oelint_parser.cls_item import Function, 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 +from oelint_parser.helper_files import ( + get_valid_named_resources, + get_valid_package_names, +) + +from oelint_adv.cls_rule import Rule class VarMisspell(Rule): @@ -13,11 +16,15 @@ def __init__(self): super().__init__(id='oelint.vars.mispell', severity='warning', message='') + try: + self._minconfidence = float(os.environ.get('OELINT_MISSPELL_CONFIDENCE', 'not-a-float')) + except ValueError: + self._minconfidence = 0.8 - def get_best_match(self, item, _list, minconfidence=0.5): + def get_best_match(self, item, _list): _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: + if _dict and _dict[0][0] >= self._minconfidence: return _dict[0][1] return ''