Skip to content

Commit

Permalink
Update pylint/checkers/spelling.py
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Walls <[email protected]>
  • Loading branch information
Pierre-Sassoulas and jacobtylerwalls committed Apr 20, 2022
1 parent 477969a commit 65dd830
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class SpellingChecker(BaseTokenChecker):
"type": "string",
"metavar": "<comma separated words>",
"help": "List of comma separated words that should be considered directives if "
"they appear and the beginning of a comment and should not be checked.",
"they appear at the beginning of a comment and should not be checked.",
},
),
)
Expand Down Expand Up @@ -305,7 +305,7 @@ def open(self) -> None:
self.spelling_dict = enchant.Dict(dict_name)

if self.linter.config.spelling_store_unknown_words:
self.unknown_words = set()
self.unknown_words: set = set()

self.tokenizer = get_tokenizer(
dict_name,
Expand All @@ -328,10 +328,11 @@ def close(self) -> None:

def _check_spelling(self, msgid: str, line: str, line_num: int) -> None:
original_line = line
try:
initial_space = re.search(r"^[^\S]\s*", line).regs[0][1]
except (IndexError, AttributeError):
result = re.search(r"^[^\S]\s*", line)
if result is None:
initial_space = 0
else:
initial_space = result.regs[0][1]
if line.strip().startswith("#") and "docstring" not in msgid:
line = line.strip()[1:]
# A ``Filter`` cannot determine if the directive is at the beginning of a line,
Expand Down Expand Up @@ -379,7 +380,10 @@ def _check_spelling(self, msgid: str, line: str, line_num: int) -> None:

# Store word to private dict or raise a message.
if self.linter.config.spelling_store_unknown_words:
if lower_cased_word not in self.unknown_words:
if (
self.private_dict_file is not None
and lower_cased_word not in self.unknown_words
):
self.private_dict_file.write(f"{lower_cased_word}\n")
self.unknown_words.add(lower_cased_word)
else:
Expand Down Expand Up @@ -430,7 +434,7 @@ def visit_classdef(self, node: nodes.ClassDef) -> None:

@check_messages("wrong-spelling-in-docstring")
def visit_functiondef(
self, node: Union[nodes.FunctionDef, nodes.AsyncFunctionDef]
self, node: nodes.FunctionDef | nodes.AsyncFunctionDef
) -> None:
if not self.initialized:
return
Expand All @@ -440,9 +444,10 @@ def visit_functiondef(

def _check_docstring(
self,
node: Union[
nodes.FunctionDef, nodes.AsyncFunctionDef, nodes.ClassDef, nodes.Module
],
node: nodes.FunctionDef
| nodes.AsyncFunctionDef
| nodes.ClassDef
| nodes.Module,
) -> None:
"""Check the node has any spelling errors."""
if not node.doc_node:
Expand Down

0 comments on commit 65dd830

Please sign in to comment.