flake8 not reporting on lines that are too long
Asked Answered
D

1

8

If I create a file test.py with the following poorly-formatted contents:

import re
long_string = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
class Foo():
    pass

and run flake8 on the file from the command-line like this:

$ flake8 --max-line-length=79 test.py

only two errors are reported:

test.py:1:1: F401 're' imported but unused
test.py:3:1: E302 expected 2 blank lines, found 0

The max-line-length violation on line two is not reported.

Completely by accident (I was testing if any of the command options would be respected), I found that if I add an ignore option like this:

$ flake8 --max-line-length=79 --ignore=E302 test.py

Then the line length violation is reported:

test.py:1:1: F401 're' imported but unused
test.py:2:80: E501 line too long (97 > 79 characters)

I am on Ubuntu 16.04 and my flake8 version info is:

2.5.4 (pep8: 1.7.0, mccabe: 0.2.1, pyflakes: 1.1.0) CPython 3.5.1+ on Linux

When I posted a related question on the Emacs Stack Exchange site (I thought the issue was with an Emacs package initially), one of the users there pointed out that flake8 2.5.4 requires a lower version of pyflakes. However, installing flake8 through apt or pip automatically installs that particular version of pyflakes as a dependency, and I have been unable to get an older version of pyflakes to see if that solves the problem (maybe that is another question altogether).

Am I doing something wrong here, or is this a bug?

Donell answered 3/6, 2016 at 12:43 Comment(0)
H
13

E501 is being ignored somewhere. It's either in ~/.config/flake8 or in the local directory in tox.ini, setup.cfg, or .flake8. Somewhere in one of those files you will probably find something akin to:

[flake8]
ignore = E501

(You may see it among other error codes too.)

This is not a bug in Flake8, and is almost certainly something in your environment causing this. The reason you see E501 is because you override the config file setting by providing --ignore on the command line.

Hull answered 4/6, 2016 at 12:50 Comment(2)
Well, I feel stupid now. I had added ignore = E501 to my ~/.config/flake8 at my previous job. Recently I updated my config by adding max-line-length = 80, but kept the ignore line, not realizing what E501 corresponded to...I assume then, that when I added --ignore=E302 as a command-line option, I was this overriding the ignore options in the ~/.config/flake8. Thanks for the help!Donell
That's exactly what you did. I was in a rush when I answered earlier and meant to mention that.Hull

© 2022 - 2024 — McMap. All rights reserved.