flake8-bugbear icon indicating copy to clipboard operation
flake8-bugbear copied to clipboard

Version 16.12.2 breaks opinionated rules enabled via `enable-extensions`

Open 153957 opened this issue 8 years ago • 5 comments

I have the following in my setup.cfg

[flake8]
enable-extensions=B950
ignore=E501
max-line-length=109

Here I enabled the opinionated B950 rule using the enable-extensions option for flake8: http://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-enable-extensions

With flake8-bugbear version 16.12.1 I get the (expected) error:

$ flake8
./project/settings.py:147:133: B950: line too long (132 > 109 characters)

But version 16.12.2 (and newer) do not raise an error. With those versions I would have to use the select option for flake8 to manually enable all checks (the default ones), and also specifically this check:

select=A,B,C,D,E,F,…U,V,W,X,Y,Z,B950

Probably relevant lines missing a check for enable-extensions: https://github.com/PyCQA/flake8-bugbear/blob/master/bugbear.py#L108-L110

153957 avatar May 02 '17 12:05 153957

@ambv

153957 avatar Jun 28 '17 20:06 153957

I changed handling of it to require explicit selection because "enable-extension" doesn't work as expected.

Note that with 16.12.1 you don't have to "enable-extensions" at all. It's enough for you to ignore=E501 for all optional warnings (including the ones from pycodestyle) to be turned on implicitly. This is misleading and exactly why I did something custom here.

The enable-extensions= line did nothing for you all along.

ambv avatar Jul 12 '17 13:07 ambv

Ok, so you no longer enable the B9* checks when ignore=E501 is used, understandable, I also find using ignore to enable the optional rules strange behaviour.. So understandable you require the user to explicitly chose the rules, but is that not exactly what enable-extensions is for? Or do not have access to the list of enabled extensions? Forcing explicit selection of ALL (i.e. normally default) rules just to use some B9 rules seems strange.

153957 avatar Jul 12 '17 14:07 153957

I haven't really looked too long for why enabled extensions don't work. I'd accept a pull request with a fix.

ambv avatar Jul 12 '17 15:07 ambv

I'm also running into this. I have a lot of flake8 plugins that implicitly enable a bunch of different codes, all of which get lost when I specify an explicit select in my config (unless I duplicate the list, but I do not really care much for that).

Looking at the code, it seems that enabled-extensions causes the plugin manager to enable these plugins: https://github.com/PyCQA/flake8/blob/52210149474a876c06922ae2c296445af5bdb108/src/flake8/plugins/manager.py#L214-L215

Enabling a plugin, causes its "name" (which is really a prefix for codes) to be added to the extended select list (which causes the code to be implicitly selected). https://github.com/PyCQA/flake8/blob/52210149474a876c06922ae2c296445af5bdb108/src/flake8/plugins/manager.py#L188-L191

The "name" for bugbear is "B": https://github.com/PyCQA/flake8-bugbear/blob/6bf40eafe99bb569296c460b691a6c0bebd27ea5/setup.py#L60

AFAICS, the bugbear plugin is enabled by default, so enable_extensions is essentially a no-op.

One way to fix this would be to let bugbear specify multiple entrypoints: One for B0 and one for B3, both of which are enabled by default (like now), and one for B9 which is disabled by default: https://github.com/PyCQA/flake8/blob/52210149474a876c06922ae2c296445af5bdb108/src/flake8/plugins/manager.py#L516-L517

AFAICS only one of these three plugins actually has to do work, the others can be empty and just serve to prefill the list of included codes. If you do this, you can use enable_extensions to enable the B9 plugin, without having to specify select.

However, I'm not exactly sure that this is really reliable, since I'm not sure if this empty plugin approach is really future-proof (or that it works at all...).

In the end, I suspect this is really something that flake8 might need to solve, except that its select/ignore handling seems quite complex already, as well as its plugin handling (probably because it supports pep8 and pyflakes plugins as well, dunno).

matthijskooijman avatar May 19 '18 22:05 matthijskooijman