简体   繁体   中英

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

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?

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

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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