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
[object-shorthand] autofix breaks arrow functions with function types #124
Comments
Seems this could be fixed upstream (i.e., in the core ESLint rule) if we are careful to look for and remove arrow tokens after the full range of the arguments section of the node, instead of just getting the first arrow token. What happens if you have multiple arguments that are function types? Does it only remove the arrow for the first argument? If so, that supports my hypothesis. All of this assumes the parser is returning the correct range info-- we should check that first. 😄 |
/* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */
const test = {
key: (arg: () => any, arg2: () => any) => {}
} becomes /* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */
const test = {
key(arg: () any, arg2: () => any) => {}
} Following your logic, I tried with a default parameter in a js file and it bugs out as well: /* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */
const test = {
key: (arg = () => {}) => {}
} becomes /* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */
const test = {
key(arg = () {}) => {}
}; I'll open up an issue in the ESLint repo. I don't know if we should close this one yet, maybe once it's fixed in ESLint, it might still be broken with TS types. |
Thanks @MayhemYDG for your tests, this all seems to point to my hypothesis as you noted. @JamesHenry We don't have any labels related to the issue being blocked, or that this might be solvable in ESLint core. How do you want to handle the labeling of this issue? I agree with @MayhemYDG that it could be worthwhile to leave this open. |
Let’s close this for now since the issue is with ESLint. If the upstream fix doesn’t fix our case, please comment and we’ll reopen this. |
@MayhemYDG Once you've opened the ESLint issue, please CC me-- I have some thoughts on how to fix. Thanks! |
Upstream issue: eslint/eslint#11305 |
For what it's worth: I used AST Explorer to check the parser output (although this was with |
@platinumazure @j-f1 /* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */
const test = {
key: (arg: any): any => {}
} becomes const test = {
key((arg: any): any) {}
} instead of const test = {
key(arg: any): any {}
} |
I put up a fix for this in the eslint repo: I'll close this, feel free to track the fix via the above PR. If that PR gets rejected, I'll reopen this issue and we can bring the rule into the plugin. |
What code were you trying to parse?
What did you expect to happen?
Autofix result should be
What actually happened?
Autofix gives
Versions
@typescript-eslint/parser
1.0.0
TypeScript
3.2.4
ESLint
5.12.1
node
11.7.0
npm
6.5.0
The text was updated successfully, but these errors were encountered: