-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Add prevent-abbreviations
rule
#237
Add prevent-abbreviations
rule
#237
Conversation
d9ed772
to
8b24418
Compare
8b24418
to
566b035
Compare
I tried running this on the AVA codebase.
|
06d5048
to
aeddd2a
Compare
I wonder why this did not come up in the integration tests run (the error itself is not fixed yet). |
6245a0b
to
28d5360
Compare
Fixed the integration test and the error. @sindresorhus Should I cherry-pick the integration test fix into a separate PR? |
In AVA:
|
I would recommend running |
Should we also report on properties (obviously not auto-fix them)? For example, Hmm, or maybe we should only report when creating objects and not using them? const foo = {
err: new Error();
}; |
Instead of converting, for example, |
949ab8e
to
2d361f7
Compare
Unlike variable, property names can be a part of an interface, so users may be forced to use certain property names by third party code. We could add another rule for property/method names and set it to
I prefer What should the new general renaming scheme be?
Also, if we go with eslint-plugin-unicorn/test/catch-error-name.js Lines 76 to 80 in 6f78698
|
5cc58e0
to
de6dabd
Compare
You could argue the same about the |
👍 I can't imagine more than one
👍 |
bd8d9d6
to
7cd9aac
Compare
I'm really not sure about any of this. Default import does not seem much different from named import. This renaming is equally weird to me: -import { prop } from 'ramda';
+import { prop as property } from 'ramda'; Which is analogous to an object destructuring -const { prop } = require('ramda');
+const { prop: property } = require('ramda'); or -const { prop } = foo;
+const { prop: property } = foo; So I think if abbreviated default import is to be allowed, abbreviated named imports and variable names that are defined in object destructuring should be allowed too. In case abbreviated property name came from the same project that is being linted, it will be reported wherever the object is created (or property assigned, or name exported). I'm not sure which way it should be, but I think rules should be the same for all cases I mentioned (default import, named import and object destructuring). |
I agree it should be the same for all kinds of imports/requires. Since we already have the logic for handling imports, it would be too bad to throw it away, but I also don't really think it's a good default. So how about we put it behind an option that is off by default? |
Do you agree about destructuring in general? That is that by default these should pass too: const {prop} = foo; const f = ({prop}) => prop; |
Yes, they should instead be renamed at the source, if possible. |
@sindresorhus I'd like to change the rules around |
👍 |
Done, once again 😆 |
And now it's perfect! 👌 Thanks for your very hard work and perseverance on this one, @futpib. The result is fantastic. |
@futpib You have to submit the PR URL to https://issuehunt.io/r/sindresorhus/eslint-plugin-unicorn/issues/169 to claim the bounty ;) |
Fixes #169