GithubHelp home page GithubHelp logo

best-doctor / flake8-functions Goto Github PK

View Code? Open in Web Editor NEW
50.0 3.0 7.0 40 KB

flake8 plugin for validation of function parameters (length, complexity, etc)

License: MIT License

Makefile 1.61% Python 98.16% Ruby 0.23%
flake8 styleguide flake8-plugin code-standards

flake8-functions's People

Contributors

arondit avatar dodgyturtle avatar korneevm avatar mcproger avatar melevir avatar sampearl avatar tripcher avatar vquadx avatar wwuck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flake8-functions's Issues

CFQ001 counts too many lines

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:

  1. Create a function that contains some empty lines and/or comments lines
  2. Run flake8 with the --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:

  • OS:Manjaro Linux x86_64
  • Python : 3.9.7
  • Flake8: 4.0.1
  • Flake8-functions : 0.0.6

Add number of returns validator

If function has more that n returns in it's body, the plugin should raise error.
Max number of returns should be flake8 parameter.

Ignore docstrings when calculating function length

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,

Set a minimal version of Python to work with

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)

Typing dependencies error

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):

  1. Create empty django project
  2. pip install flake and flake8-functions>=0.0.5
  3. Run flake
  4. See error

Expected behavior
Expected regular flake launch.

Additional context

Logs:
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)

Add documentation

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.