Implement `flake8-functions`
- [ ]
CFQ001: Function ... has length {function_length} that exceeds max allowed length {max_function_length}- This is an alternative to complexity checkers and is just purely the number of lines in the function
- Unlike
too-many-statements(PLR0915) frompylint, this counts the literal number of lines that the function takes up on the page, rather than the number of statements in the function.
- [x]
CFQ002: Function ... has {arguments_amount} arguments that exceeds max allowed {max_parameters_amount}- Already implemented as
too-many-arguments(PLR0913) frompylint
- Already implemented as
- [ ]
CFQ003: Function ... is not pure- Uses
mr-properunder the hood to check that a function is "pure" - That library says it's very experimental and it looks a bit too magic, so can probably skip this rule.
- Uses
- [x]
CFQ004: Function ... has {returns_amount} returns that exceeds max allowed {max_returns_amount}- Already implemented as
too-many-return-statements(PLR0911) frompylint
- Already implemented as
Configuration options:
- [ ]
max-function-lengthimplemented aspylint:max-statements - [x]
max-parameters-amountimplemented aspylint:max-args - [x]
max-returns-amountto be implemented aspylint:max-returns
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.
CFQ003 would be truly awesome to have
Sounds like "challenge accepted"? 😂
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!
You mind if I implement too-many-return-statements?
Go ahead! 🙂
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.)