@@ -263,44 +263,48 @@ class SpellingChecker(BaseTokenChecker):
263
263
),
264
264
)
265
265
266
+ def __init__ (self , linter : "PyLinter" ) -> None :
267
+ super ().__init__ (linter , future_option_parsing = True )
268
+
266
269
def open (self ):
267
270
self .initialized = False
268
271
self .private_dict_file = None
269
272
270
273
if enchant is None :
271
274
return
272
- dict_name = self .config .spelling_dict
275
+ dict_name = self .linter . namespace .spelling_dict
273
276
if not dict_name :
274
277
return
275
278
276
279
self .ignore_list = [
277
- w .strip () for w in self .config .spelling_ignore_words .split ("," )
280
+ w .strip () for w in self .linter . namespace .spelling_ignore_words .split ("," )
278
281
]
279
282
# "param" appears in docstring in param description and
280
283
# "pylint" appears in comments in pylint pragmas.
281
284
self .ignore_list .extend (["param" , "pylint" ])
282
285
283
286
self .ignore_comment_directive_list = [
284
- w .strip () for w in self .config .spelling_ignore_comment_directives .split ("," )
287
+ w .strip ()
288
+ for w in self .linter .namespace .spelling_ignore_comment_directives .split ("," )
285
289
]
286
290
287
291
# Expand tilde to allow e.g. spelling-private-dict-file = ~/.pylintdict
288
- if self .config .spelling_private_dict_file :
289
- self .config .spelling_private_dict_file = os .path .expanduser (
290
- self .config .spelling_private_dict_file
292
+ if self .linter . namespace .spelling_private_dict_file :
293
+ self .linter . namespace .spelling_private_dict_file = os .path .expanduser (
294
+ self .linter . namespace .spelling_private_dict_file
291
295
)
292
296
293
- if self .config .spelling_private_dict_file :
297
+ if self .linter . namespace .spelling_private_dict_file :
294
298
self .spelling_dict = enchant .DictWithPWL (
295
- dict_name , self .config .spelling_private_dict_file
299
+ dict_name , self .linter . namespace .spelling_private_dict_file
296
300
)
297
301
self .private_dict_file = open ( # pylint: disable=consider-using-with
298
- self .config .spelling_private_dict_file , "a" , encoding = "utf-8"
302
+ self .linter . namespace .spelling_private_dict_file , "a" , encoding = "utf-8"
299
303
)
300
304
else :
301
305
self .spelling_dict = enchant .Dict (dict_name )
302
306
303
- if self .config .spelling_store_unknown_words :
307
+ if self .linter . namespace .spelling_store_unknown_words :
304
308
self .unknown_words = set ()
305
309
306
310
self .tokenizer = get_tokenizer (
@@ -374,14 +378,14 @@ def _check_spelling(self, msgid, line, line_num):
374
378
continue
375
379
376
380
# Store word to private dict or raise a message.
377
- if self .config .spelling_store_unknown_words :
381
+ if self .linter . namespace .spelling_store_unknown_words :
378
382
if lower_cased_word not in self .unknown_words :
379
383
self .private_dict_file .write (f"{ lower_cased_word } \n " )
380
384
self .unknown_words .add (lower_cased_word )
381
385
else :
382
386
# Present up to N suggestions.
383
387
suggestions = self .spelling_dict .suggest (word )
384
- del suggestions [self .config .max_spelling_suggestions :]
388
+ del suggestions [self .linter . namespace .max_spelling_suggestions :]
385
389
line_segment = line [word_start_at :]
386
390
match = re .search (rf"(\W|^)({ word } )(\W|$)" , line_segment )
387
391
if match :
0 commit comments