Skip to content

Commit 1506503

Browse files
committed
Add a note on 'pep8', plus an example
1 parent fc36b3b commit 1506503

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and [pydocstyle](https://github.com/PyCQA/pydocstyle).
1818

1919
This is probably the linter to use, specifically for the `PEP 8` integration.
2020

21+
In fact, it was formerly called `pep8`.
22+
2123
However, I still like `pylint` quite a lot, for one thing it will complain if a file is not named in a Pythonesque
2224
way. And they've gamified `pylint` pretty well, it's oddly satisfying to clean up formatting and see the code score
2325
improve.
@@ -66,6 +68,43 @@ Run `pyreverse` as follows:
6668

6769
[The default output format is `dot`, here we are specifying the graphic format `png`.]
6870

71+
## An example of using `pylint` and `pycodestyle`
72+
73+
Here we will use a quick test case:
74+
75+
```bash
76+
$ python bad-python.py
77+
This code does not follow 'pylint' file naming conventions!
78+
This code does not follow 'pycodestyle' coding conventions!
79+
$
80+
```
81+
82+
These linters flag different things, so it's probably worth running both:
83+
84+
```bash
85+
$ pycodestyle *.py
86+
bad-python.py:10:80: E501 line too long (85 > 79 characters)
87+
bad-python.py:12:1: W391 blank line at end of file
88+
$
89+
```
90+
91+
And:
92+
93+
```bash
94+
$ pylint *.py
95+
No config file found, using default configuration
96+
************* Module bad-python
97+
C: 12, 0: Trailing newlines (trailing-newlines)
98+
C: 1, 0: Module name "bad-python" doesn't conform to snake_case naming style (invalid-name)
99+
W: 7, 0: String statement has no effect (pointless-string-statement)
100+
W: 10, 0: String statement has no effect (pointless-string-statement)
101+
102+
---------------------------------------------------------------------
103+
Your code has been rated at 0.00/10 (previous run: -10.00/10, +10.00)
104+
105+
$
106+
```
107+
69108
## pydocstyle
70109
71110
While not strictly a linter, having well-formed docstrings allows for the use of automated documentation generators.

bad-python.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
An example of Python code that will fail linting.
5+
"""
6+
7+
"""'pylint' will complain about the file name."""
8+
print "This code does not follow 'pylint' file naming conventions!"
9+
10+
"""'pycodestyle' will complain about the blank line following the print statement."""
11+
print "This code does not follow 'pycodestyle' coding conventions!"
12+

0 commit comments

Comments
 (0)