Skip to content

Commit

Permalink
misspell: make confidence configurable
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
priv-kweihmann committed Jan 9, 2024
1 parent 3586476 commit 7e9d7ec
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions oelint_adv/rule_base/rule_var_misspell.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
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):
def __init__(self):
super().__init__(id='oelint.vars.mispell',
severity='warning',
message='<FOO>')
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 ''

Expand Down

0 comments on commit 7e9d7ec

Please sign in to comment.