简体   繁体   English

是否有基于Google风格指南的lint Python工具?

[英]Is there a tool to lint Python based on the Google style guide?

According to Google's standard for Python: 根据谷歌的Python标准:

http://google-styleguide.googlecode.com/svn/trunk/pyguide.html http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

Perhaps a group of tools that can cover most of the standard? 也许一组工具可以涵盖大部分标准?

pylint will do this kind of checking but you need a configuration file to make it look for things exactly as Google's style guide dictates. pylint会进行这种检查,但是你需要一个配置文件来让它完全按照谷歌风格指南的要求来查找。

Google publishes this pylink file as part of various projects. Google将此pylink文件作为各种项目的一部分发布。

https://www.chromium.org/chromium-os/python-style-guidelines#TOC-pylint https://www.chromium.org/chromium-os/python-style-guidelines#TOC-pylint

The rc file itself is here: rc文件本身在这里:

https://github.com/vinitkumar/googlecl/blob/master/googlecl-pylint.rc https://github.com/vinitkumar/googlecl/blob/master/googlecl-pylint.rc

Copy it to /path/to/pylintrc and run pylint on your files: 将其复制到/path/to/pylintrc并在文件上运行pylint:

pylint -E --rcfile=/path/to/pylintrc file.py file2.py

You can find the pylint.rc files used by Google's projects on github, such as the following two: 您可以在github上找到Google项目使用的pylint.rc文件,例如以下两个:

It seems that different projects could use differently customized pylint configuration files, although most of the configurations are the same. 虽然大多数配置都是相同的,但似乎不同的项目可以使用不同的自定义pylint配置文件。

You can further customize the pylintrc files based on these Google published pylint.rc files. 您可以根据这些Google发布的pylint.rc文件进一步自定义pylintrc文件。

To get a complete pylint report with the score, use command: 要使用分数获得完整的pylint报告,请使用命令:

pylint --rcfile=<path to google pylintrc> <your.py>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM