-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[eslint-plugin-mobx] mobx/exhaustive-make-observable
autofix behavior should be inversed
#3876
Comments
The biggest problem with
It' suspposed to say: Hey, you probably forgot to annotate a field, but if this is actually intended and you don't want to make this field observable, you don't have to disable this rule, you can just use If you're |
I agree the eslint rule solves the problem it sets out to solve. I disagree with the autofix. You have no way of knowing what the intent of the missing field is, just that the user probably didn't mean it. But they very well might have! In general, it feels bad to me to suggest an autofix that might lead the person to just change what was just fixed again, because you made a bad assumption about their intents. It seems to me like in these cases an autofix just shouldn't exist. Make them fix it themselves or turn it off (with the consequences that come with it). From what I can tell this is generally how autofixes are implemented -- they only apply in scenarios that are indisputably wrong AND it doesn't change the meaning of the code. I scrolled through all of the stock ESLint rules briefly and I don't think there is a rule where an autofix is present in an unambiguous situation like this. To be clear, I do realize my fix (defaulting to false) only deals with one of those branches -- it didn't change the meaning of the code but it still might not be what the user expects. There may be a partial solution in keeping the autofix with some addditional configuration as to what the autofix does (the default value it fills out), but that's also not entirely free from ambiguity. Does that seem reasonable (in lieu of just not having an autofix)? -- This is an aside, but if it's so easy to make a mistake with the current |
I understand the concern. I think
It's not technically possible (for similar reasons the
I am ok with making the autofix configurable. |
Ah, okay. When I was thinking about this I was more thinking about having this enforced with TypeScript only, but that does neglect anyone not using it.
Sounds good! I will close off my existing PR and get an updated one ready soon.
This was my experience as well. I'll investigate and see if it's doable.
✅ |
Intended outcome:
As per the documentation of
makeObservable
, it is expected that if you do not currently have an annotation for a member, it is not affected.I would expect that an autofix for
mobx/exhaustive-make-observable
would put a value for all missing members that should be listed, but have the annotation set tofalse
to maintain the behaviour from before. This seems especially weird because the warning message itself tells you to mark fields as false: "Missing annotation for <members>. To exclude a field, usefalse
as annotation"Actual outcome:
The
mobx/exhaustive-make-observable
autofix annotates all missing members withtrue
, changing the behaviour of those members.How to reproduce the issue:
You can fork this Devbox, run
pnpm lint
to see the warning with an autofix option, andpnpm lint:fix
to see what the autofix does.https://codesandbox.io/p/devbox/h7st47?file=%2Findex.js%3A14%2C20
Versions
eslint-plugin-mobx
v0.0.9.The text was updated successfully, but these errors were encountered: