-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore cognitive complexity in macro expanded code #3900
Comments
@felix91gr I think we had discussions about this, right? Like moving the cognitive complexity lint to a pre-expansion pass so macro invocations are just as "complex" as a single function call. |
I've added this to the list of (Nesting-Indepentend) Increments constructs, right where function calls are: #3793 (comment) :) |
Should this lint be disabled in the interim? Also, according to @hawkw Here's an egregious example of a gist that triggers cognitive complexity https://gist.github.com/jarrodldavis/c6ba356b4243b898a658e27f9042a483 |
@yaahc maybe. I'm sorry for what's happening. The plan was for the changes to be finished around April or so, but life happened and I'm on a hiatus for the moment. Since the old version (the one currently on Maybe downgrading the existing one to @Centril @oli-obk @Manishearth what do you think of that? |
And fwiw, the short version of why we want to ultimately not check the post-expansion code in the lint, is because the lint checks how hard to grasp is a piece of code. Since macros do introduce abstraction, they are not "weightless". But they are cognitively (we believe) very close to reading a function call. |
That's exactly what I would expect. A macro abstracts code in the exact way a function does, it's only the underlying implementation that is different. Downgrading to nursery sounds good 👍 |
We need to think about a case like this though : some_macro!({
// Some complex expression
} ) Because in a pre expansion pass, we can't access the macro arg expressions, since they're not parsed by that point. Maybe we could first run a pre expansion parse, but don't lint there, but calculate the CoC and mark the spans of the macros that need to be rechecked. After that, we run an early lint pass and recheck these spans. Not sure how to handle macro in macro situations though. |
If I remember correctly, @flip1995, we are walking inside all expressions, including the ones inside macro invocations. So we should be scoring whatever they have inside. What we're not scoring, however, is the post-macro-expansion code, which since it's abstracted away while a user is reading the invocation code, it's ignored in the score. That is however, a good reminder. I will probably remember to double check this before we ship it, thanks :3 |
I doubt that. We have a PR open with this exact same problem, where we're kind of stuck, since there is no good solution for this (yet?). See #4186 (comment) So if you found a way to check them, I would be really happy about it, since this would resolve a lot of problems with linting macro code. But make sure to check this. (Maybe I get to write a test for this. Your CoC PR is already a pre-expansion pass, isn't it?) |
It is! Do take a look, and feel free to make tests for it. We definitely need more tests before calling it done :3 |
Mostly ambivalent about moving it to nursery. |
The lint has been moved to the nursery a while ago. Since the macro handling case is now tracked in #3793, I'm going to go ahead and close this issue. |
Would it be possible to run the cognitive/cyclomatic complexity lints before macro expansion, or otherwise have them ignore macro output? I've got a number of macros with pretty heavy code generation, and I invariably have to turn off these lints in order to avoid triggering them even for macros that are very simple from the user's perspective.
The text was updated successfully, but these errors were encountered: