Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell flake8 to ignore comments

I'm using flake8 in emacs in order to clean up my python code. I find it annoying to have my comments flagged as errors (E501 line too long (x > 79 characters)). I'm wondering if anyone knows a way to kindly ask flake8 to ignore comments, both single and multi-line, but still let me know when my non-comment lines are too long?

Thanks in advance!

like image 245
sacuL Avatar asked Dec 18 '17 20:12

sacuL


People also ask

How do I get flake8 to ignore?

There are two ways to ignore the file: By explicitly adding it to our list of excluded paths (see: flake8 --exclude ) By adding # flake8: noqa to the file.

How do I ignore E501 in flake8?

[flake8] per-file-ignores = # line too long path/to/file.py: E501, This may be easier than using # noqa comments.

How do you override flake8?

Selecting Violations with Flake8 This list can be overridden by specifying flake8 --select . Just as specifying flake8 --ignore will change the behaviour of Flake8, so will flake8 --select . Suddenly we now have far more errors that are reported to us. Using --select alone will override the default --ignore list.

What is flake8 NOQA?

# flake8: noqa : files that contain this line are skipped. lines that contain a # noqa comment at the end: will not issue warnings.


2 Answers

I've figured out a possible solution to this, but there might be something better. If you write a comment that will raise an E501 error, i.e. it is too long, you can append that line with # noqa: E501, and flake8 will ignore it. For example:

# This is a really really long comment that would usually be flagged by flake8 because it is longer than 79 characters

would usually raise an E501, but

# This is a really really long comment that would usually be flagged by flake8 because it is longer than 79 characters # noqa: E501

will not.

documented here.

like image 50
sacuL Avatar answered Sep 20 '22 18:09

sacuL


You can change the list of codes ignored by flake8 using a configuration file. For example, in your project directory create a file named .flake8 with the following content:

[flake8] per-file-ignores =     # line too long     path/to/file.py: E501, 

This may be easier than using # noqa comments.

like image 42
Eugene Yarmash Avatar answered Sep 19 '22 18:09

Eugene Yarmash