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

不问归期 提交于 2019-12-03 10:54:36

问题


According to Google's standard for Python:

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

Perhaps a group of tools that can cover most of the standard?


回答1:


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.

Google publishes this pylink file as part of various projects.

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

The rc file itself is here:

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

Copy it to /path/to/pylintrc and run pylint on your files:

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



回答2:


You can find the pylint.rc files used by Google's projects on github, such as the following two:

  • https://github.com/google/apitools/blob/master/default.pylintrc (Link is dead)
  • https://github.com/google/seq2seq/blob/master/pylintrc

It seems that different projects could use differently customized pylint configuration files, although most of the configurations are the same.

You can further customize the pylintrc files based on these Google published pylint.rc files.

To get a complete pylint report with the score, use command:

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


来源:https://stackoverflow.com/questions/29597618/is-there-a-tool-to-lint-python-based-on-the-google-style-guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!