flake8 max-complexity per file

百般思念 提交于 2020-01-26 03:52:05

问题


I have a legacy project using flake8 to check code quality and complexity, but the project has some very complicated (terrible) services which are returning complexity WARNING messages:

./service1.py:127:1: C901 'some_method' is too complex (50)

We are slowly transitioning into making them better, but we need to make jenkins (which is running tests and flake8) pass.

Is there a way to specify ignoring a code error or complexity per file, or even per method?


回答1:


You can use flake8-per-file-ignores:

pip install flake8-per-file-ignores

And then in your config file:

[flake8]
per-file-ignores =
    your/legacy/path/*.py: C901,E402

If you want a per-method/function solution you can use the in-source # noqa: ignore=C901 syntax.




回答2:


If you have Flake8 3.7.0+, you can use the --per-file-ignores option to ignore the warning for a specific file:

flake8 --per-file-ignores='service1.py:C901'

This can also be specified in a config file:

[flake8]
per-file-ignores =
    service1.py: C901



回答3:


In your flake config add:

[flake8]
ignore = C901
max-complexity = <some_number>

Try to experiment with the value for max-complexity to get more relevant number for your project.

Edit: You can also ignore a line of your code or a file.

After you are done with the refactoring don't forget to change these settings.



来源:https://stackoverflow.com/questions/44704775/flake8-max-complexity-per-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!