astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
30.94k stars 1.02k forks source link

Implement `flake8-functions` #2414

Open ngnpope opened 1 year ago

ngnpope commented 1 year ago

GitHub, PyPI.

Configuration options:

Other than CFQ003 which is dubious, these will all be covered by pylint rules... So this can be closed if desired, but this will be useful to refer to when aliases are implemented.

sbrugman commented 1 year ago

CFQ003 would be truly awesome to have

ngnpope commented 1 year ago

Sounds like "challenge accepted"? 😂

sbrugman commented 1 year ago

The features of Mr. Proper should be useable attributes to discover violations:

  • that function has no blacklisted calls (like print) and blacklisted attributes access (like smth.count);
  • that function not uses global objects (only local vars and function arguments);
  • that function has al least one return;
  • that function not mutates it's arguments;
  • that function has no local imports;
  • that function has no arguments of forbidden types (like ORM objects);
  • that function not uses self, class or super;
  • that function has calls of only pure functions.

Mostly this requires no type checking!

chanman3388 commented 1 year ago

You mind if I implement too-many-return-statements?

ngnpope commented 1 year ago

Go ahead! 🙂

mirecl commented 1 year ago

Why CFQ001 and CFQ004 is done? PLR0915/PLR0911 is not equal rule for CFQ001/CFQ004!

AlexWaygood commented 5 months ago

Why CFQ001 and CFQ004 is done? PLR0915/PLR0911 is not equal rule for CFQ001/CFQ004!

I've unticked CFQ001 -- you're right, that does seem distinct from PLR0915 to me. CFQ004 does look basically the same as PLR0911 to me, though -- would you mind explaining to me how they are different, @mirecl?

(N.B. Just because I've "unticked" the rule doesn't necessarily mean that we'll accept a PR. CFQ001 is a very opinionated rule, so we probably wouldn't accept this rule until https://github.com/astral-sh/ruff/issues/1774 is completed and we have a better way of marking rules as disabled by default.)