请考虑以下示例代码:
# -*- coding: utf-8 -*- """Test module.""" def test(): """Tets function""" return 10
pylint
给它10个10,flake8
没有发现任何警告:
$ pylint test.py ... Global evaluation ----------------- Your code has been rated at 10.00/10 ... $ flake8 test.py $
但是,正如您所看到的,test
函数的文档字符串中存在拼写错误.并且,您的编辑器可能会自动突出显示它,例如,这是Pycharm如何做到的:
多亏了/sf/ask/17360801/话题,现在我知道有一个叫相关的拼写检查库PyEnchant
那可用于检测拼写错误.
我的最终目标是自动检测项目中的拼写错误,并使拼写检查成为持续构建,测试和代码质量检查运行的一部分.
有没有办法实现这一目标pylint
?如果没有,我也会感谢任何关于在PyEnchant
项目方面应用于文档字符串和注释的提示(在这种情况下,pylint
或pyflakes
插件可以由它制作).
如果我疯狂地关注代码质量,也请告诉我.
Pylint刚刚发布了1.4.0,其中包括一个spell-checker
.这是最初的拉动请求.
请注意,要使检查器工作,您需要安装pyenchant
python模块并在enchant
系统范围内安装库.在Mac上,它可以通过brew
以下方式安装:
$ brew install enchant
默认情况下,spelling
pylint检查程序已关闭.您可以在pylint rc
配置文件中或从命令行启用它:
$ 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)