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

Add a functional test for the spelling checker #6137

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 14 additions & 12 deletions pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
WikiWordFilter,
get_tokenizer,
)

PYENCHANT_AVAILABLE = True
except ImportError:
enchant = None
PYENCHANT_AVAILABLE = False

class EmailFilter: # type: ignore[no-redef]
...
Expand All @@ -62,17 +65,16 @@ def get_tokenizer(
return Filter()


if enchant is not None:
br = enchant.Broker()
dicts = br.list_dicts()
dict_choices = [""] + [d[0] for d in dicts]
dicts = [f"{d[0]} ({d[1].name})" for d in dicts]
dicts = ", ".join(dicts)
instr = ""
INSTALL_ENCHANT = " To make it work, install the 'python-enchant' package."
if PYENCHANT_AVAILABLE:
broker = enchant.Broker()
enchant_dicts = broker.list_dicts()
enchant_dict_choices = [""] + [d[0] for d in enchant_dicts]
enchant_dicts = [f"{d[0]} ({d[1].name})" for d in enchant_dicts]
enchant_dicts = ", ".join(enchant_dicts)
else:
dicts = "none"
dict_choices = [""]
instr = " To make it work, install the 'python-enchant' package."
enchant_dicts = "none"
enchant_dict_choices = [""]


class WordsWithDigitsFilter(Filter):
Expand Down Expand Up @@ -235,9 +237,9 @@ class SpellingChecker(BaseTokenChecker):
"default": "",
"type": "choice",
"metavar": "<dict name>",
"choices": dict_choices,
"choices": enchant_dict_choices,
"help": "Spelling dictionary name. "
f"Available dictionaries: {dicts}.{instr}",
f"Available dictionaries: {enchant_dicts}.{INSTALL_ENCHANT}",
},
),
(
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/s/spelling/spelling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Functional test for speling.""" # [wrong-spelling-in-docstring, wrong-spelling-in-comment]

# mispeled text # [wrong-spelling-in-comment]

def function_name():
"""mispeled text.""" # [wrong-spelling-in-docstring, wrong-spelling-in-comment]
2 changes: 2 additions & 0 deletions tests/functional/s/spelling/spelling.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[SPELLING]
spelling-dict=en_US
20 changes: 20 additions & 0 deletions tests/functional/s/spelling/spelling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
wrong-spelling-in-comment:1:0:None:None::"Wrong spelling of a word 'docstring' in a comment:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we understand why we get None:None here on 3.10?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's the same on 3.7, 3.8, 3.9.. Probably because we're passing the line as an int instead of a node.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to fix this in a follow-up PR? Or in this PR?

Copy link
Member Author

@Pierre-Sassoulas Pierre-Sassoulas Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to do two:

  • Pass node instead of line number as int
  • Add pylint's msgids and symbols to the dictionary automatically

Probably better after we merge this one and #5929 though, we're very bsy right now 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Could you make an issue about passing node instead of line in this checker though? So we don't forget about it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# [wrong-spelling-in-docstring, wrong-spelling-in-comment]
^^^^^^^^^
Did you mean: ''doc string' or 'doc-string' or 'stringing''?":UNDEFINED
wrong-spelling-in-docstring:1:0:None:None::"Wrong spelling of a word 'speling' in a docstring:
Functional test for speling.
^^^^^^^
Did you mean: ''spieling' or 'spelling' or 'spewing' or 'peeling''?":UNDEFINED
wrong-spelling-in-comment:3:0:None:None::"Wrong spelling of a word 'mispeled' in a comment:
# mispeled text # [wrong-spelling-in-comment]
^^^^^^^^
Did you mean: ''misspelled' or 'dispelled' or 'misspell' or 'misled''?":UNDEFINED
wrong-spelling-in-comment:6:0:None:None::"Wrong spelling of a word 'docstring' in a comment:
# [wrong-spelling-in-docstring, wrong-spelling-in-comment]
^^^^^^^^^
Did you mean: ''doc string' or 'doc-string' or 'stringing''?":UNDEFINED
wrong-spelling-in-docstring:6:0:None:None::"Wrong spelling of a word 'mispeled' in a docstring:
mispeled text.
^^^^^^^^
Did you mean: ''misspelled' or 'dispelled' or 'misspell' or 'misled''?":UNDEFINED