自动文档字符串和注释拼写检查 [英] Automated docstring and comments spell check
问题描述
请考虑以下示例代码:
# -*- coding: utf-8 -*-
"""Test module."""
def test():
"""Tets function"""
return 10
pylint
给出10的10, flake8
找不到任何警告:
pylint
gives it 10 of 10, flake8
doesn't find any warnings:
$ pylint test.py
...
Global evaluation
-----------------
Your code has been rated at 10.00/10
...
$ flake8 test.py
$
但是,您可能会看到错字在 test
函数的文档字符串中。并且,您的编辑器可能会自动突出显示它,例如,Pycharm就是这样:
But, as you may see, there is a typo in the test
function's docstring. And, your editor would probably highlight it automagically, for example, here's how Pycharm does it:
感谢 https://stackoverflow.com/questions/2151300/whats-the-best-way-to-spell-check-python-source-代码主题,现在我知道有一个名为 PyEnchant
可以用来检测错别字。
Thanks to the https://stackoverflow.com/questions/2151300/whats-the-best-way-to-spell-check-python-source-code topic, now I know that there is a relevant spell-checking library called PyEnchant
that can be used to detect typos.
我的最终目标是自动检测项目中的错别字并使拼写检查成为持续构建,测试和代码质量检查运行的一部分。
My end goal is to automatically detect typos in the project and make the spell check a part of a continuous build, test and code-quality check run.
是否可以用 pylint
来实现?如果没有,我也希望在文档字符串上应用 PyEnchant
并在项目方面进行注释(在这种情况下,为 pylint
或 pyflakes
插件都可以做成)。
Is there a way to achieve that with pylint
? If not, I would also appreciate any hints on applying PyEnchant
to docstrings and comments project-wise (in this case, pylint
or pyflakes
plugin could be made out of it).
也请让我知道
推荐答案
Pylint刚发布了1.4.0,其中包括一个 拼写检查器
。这是最初的拉动请求。
Pylint just released 1.4.0, which includes a spell-checker
. Here is the initial pull-request.
请注意,要使检查器正常工作,您需要安装 pyenchant
python模块,并具有 附魔
库安装在系统范围内。在Mac上,可以通过 brew
安装:
Note that, to make the checker work, you need to install pyenchant
python module and have an enchant
library installed system-wide. On mac, it can be installed via brew
:
$ brew install enchant
默认情况下,拼写
pylint检查器已关闭。您可以在pylint rc
配置文件中或从命令行启用它:
By default, the spelling
pylint checker is turned off. You can enable it either in the pylint rc
configuration file, or from the command-line:
$ cat test.py
# I am the tyop
$ pylint --disable all --enable spelling --spelling-dict en_US test.py
C: 1, 0: Wrong spelling of a word 'tyop' in a comment:
# I am the tyop
^^^^
Did you mean: 'typo' or 'top' or 'tip' or 'topi'? (wrong-spelling-in-comment)
这篇关于自动文档字符串和注释拼写检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!