I use flycheck-mode
as my syntax checker/linter for Python. It works great for the most part, however I can't get it to warn me when I have gone over a specified line length.
I am using flake8
as my checker for Python, and have confirmed this with flycheck-verify-setup
. The output from this command in a python-mode
buffer is:
Syntax checkers for buffer config.py in python-mode:
python-flake8
- predicate: t
- executable: Found at /usr/bin/flake8
python-pylint
- predicate: nil
- executable: Not found
python-pycompile
- predicate: t
- executable: Found at /usr/bin/python
The following checker is explicitly selected for this buffer:
python-flake8
- major mode: `python-mode' supported
- predicate: t
- executable: Found at /usr/bin/flake8
Flycheck Mode is enabled. Use C-u C-c ! x to enable disabled
checkers.
The checking works in general, so if I have the following Python code:
import re
long_string = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
class Foo():
pass
I get two warnings from flycheck
:
're' imported but unused [F401]
expected 2 blank lines, found 0 [E302]
I do not, however, get a warning that long_string
is too long. I have tried setting:
(setq-default flycheck-flake8-maximum-line-length 79)
in my init file as suggested here. I have tried configuring flake8
with a flake8
file in my ~/.config/
directory, as described here, which I assume flycheck
is supposed to respect, based on this answer. I have also tried setting the value of flycheck-flake8rc
to point to that flake8
file. I have tried using a local configuration file within a project as described here. None of these have worked for me. Instead, flycheck
seems to ignore any flake8
config I try to give it, and will not warn about line length. This is the case even when I use emacs -Q
, initialize packages, and enable global-flycheck-mode
- although, in this case the output of flycheck-verify-setup
is the same. Any suggestions how I might be able to:
- Get
flycheck-mode
to respect myflake8
configuration file? - Get
flycheck-mode
to warn me about going over a specified line length?
Question 2 would be solved, in theory, by any solution to question 1, because I could set, e.g.:
[flake8]
max-line-length = 79
in my configuration file, but I would be satisfied with a solution to question 2 alone. Thank you!
C-c ! C-c python-flake8
to check how Flycheck invokesflake8
in an affected buffer?setq
for the line length option and that it'sflycheck-flake8rc
(note the dash).setq-default
from your comment on this issue: github.com/flycheck/flycheck/issues/378. I triedsetq
as well, and it didn't make a difference. Also, you suggestion to runC-c ! C-c python-flake8
brought something very interesting to my attention: this command still doesn't warn about lines that are too long, but it shows the command being run asflake8 --format\=default --max-line-length 79 - < /tmp/test.py
, so it seems like it is checking line length. Does this illuminate things?flake8
version is2.5.4
. But you are right, it seems like the issue is independent offlycheck
and even Emacs, since usingflake8
from the command line outside of Emacs also doesn't expose the line length issue...I will do some more investigating now that I have this new information. Thanks for your help!