best-doctor / flake8-functions Goto Github PK
View Code? Open in Web Editor NEWflake8 plugin for validation of function parameters (length, complexity, etc)
License: MIT License
flake8 plugin for validation of function parameters (length, complexity, etc)
License: MIT License
At the moment, there is no example in the README of how to change the maximum number of arguments of the function (which is used for the CFQ002 error). It is necessary to add.
If function has pure
in it's name, it should be pure. Use mr_proper
to check that.
If function has more that n returns in it's body, the plugin should raise error.
Max number of returns should be flake8 parameter.
I set my max-function-length
really low, 25
, to put some real pressure on writing short functions. But the problem I’m running into is that Docstrings are inflating the function’s length.
I was thinking, around this line, we could calculate the length of the docstring:
https://github.com/best-doctor/flake8-functions/blob/master/flake8_functions/checker.py#L29
docstring_rows = len(func_def.__doc__.strip().split("\n"))
And subtract that when calculating the length on this line:
https://github.com/best-doctor/flake8-functions/blob/master/flake8_functions/checker.py#L36
Something like this:
'length': function_last_statement.lineno - function_start_row - docstring_rows + 1,
Describe the bug
After update to version 0.0.5, library seems to not being able to locate typing related dependencies.
To Reproduce
Steps to reproduce the behavior(reproduced on Python 3.6, 3.8):
Expected behavior
Expected regular flake launch.
Additional context
flake recreate: /home/zaysevkun/PycharmProjects/deigmata/.tox/flake
flake installdeps: flake8, flake8-bugbear, flake8-import-order, flake8-functions, flake8-executable, flake8-django, flake8-comprehensions, flake8-commas
flake installed: attrs==20.3.0,flake8==3.8.4,flake8-bugbear==20.11.1,flake8-commas==2.0.0,flake8-comprehensions==3.3.1,flake8-django==1.1.1,flake8-executable==2.1.1,flake8-functions==0.0.5,flake8-import-order==0.18.1,iniconfig==1.1.1,mccabe==0.6.1,mr-proper==0.0.6,packaging==20.8,pluggy==0.13.1,py==1.10.0,pycodestyle==2.6.0,pyflakes==2.2.0,pyparsing==2.4.7,pytest==6.2.1,stdlib-list==0.8.0,toml==0.10.2
flake run-test-pre: PYTHONHASHSEED='2815784988'
flake run-test: commands[0] | flake8 --config=.pep8 deigmata deigmata_backoffice deigmata_frontapi
Traceback (most recent call last):
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 157, in load_plugin
self._load()
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 134, in _load
self._plugin = self.entry_point.load()
File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8_functions/checker.py", line 6, in <module>
from flake8_functions.function_purity import check_purity_of_functions
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8_functions/function_purity.py", line 5, in <module>
from mr_proper.public_api import is_function_pure
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/mr_proper/public_api.py", line 5, in <module>
from typing_extensions import Literal
ModuleNotFoundError: No module named 'typing_extensions'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/bin/flake8", line 8, in <module>
sys.exit(main())
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/main/cli.py", line 22, in main
app.run(argv)
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/main/application.py", line 363, in run
self._run(argv)
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/main/application.py", line 350, in _run
self.initialize(argv)
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/main/application.py", line 330, in initialize
self.find_plugins(config_finder)
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/main/application.py", line 159, in find_plugins
self.check_plugins.load_plugins()
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 415, in load_plugins
plugins = list(self.manager.map(load_plugin))
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 302, in map
yield func(self.plugins[name], *args, **kwargs)
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 413, in load_plugin
return plugin.load_plugin()
File "/home/zaysevkun/PycharmProjects/deigmata/.tox/flake/lib/python3.8/site-packages/flake8/plugins/manager.py", line 164, in load_plugin
raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "CFQ" due to No module named 'typing_extensions'.
ERROR: InvocationError for command /home/zaysevkun/PycharmProjects/deigmata/.tox/flake/bin/flake8 --config=.pep8 deigmata deigmata_backoffice deigmata_frontapi (exited with code 1)
Bug description:
CFQ001 takes into account empty lines and comment lines when counting number of lines inside a function.
To Reproduce:
Steps to reproduce the behavior:
--max-function-length=N
where N is the number of line of your function (without counting the empty line and comment line)Expected behavior:
CFQ001 should only count lines of actual code. Taking into account empty lines and comment lines may lead to developers removing some comments or empty lines to fix CFQ001 linting error. Thus, making the code less readable.
Desktop:
Now pytest in install_requires
. It should not be there.
Good day!I really liked your library and wanted to add it to my CI.
But it completely slipped my mind that I'm working with a pretty old version of Python3.5
It was easy to install the package and I already started adding it to my master, but after that no CI was successful.
This is because this package uses some features of newer versions of Python that aren't available in 3.5, like types in variable declaration.
Unfortunately, I didn't realize this right away and wasted a lot of time researching it.
I suggest adding the python_requires directive to setup.py/setup.cfg so that I and other users of older versions of Python run into the problem already at the installation stage of the package
I understand that this is stated in both the project badges and the description, but sometimes we all make mistakes, and this clarification could save a little time)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.