-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[indent] behavior changed for multiline generic type parameters #455
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
Comments
This issue is still occurring and prevent us to update |
The short answer is - it's not getting worked on right now. The long answer.... The current indent rule extension fudges things majorly by making typescript specific AST nodes "look like" standard JS nodes so that the base eslint logic can apply its logic to it. This approach works okay for some things (like treating However there are a number of things that have no standard JS nodes that even remotely look like it (such as generics). On top of that, the base rule logic does some things where it essentially zeros out the indentation if it encounters an unexpected node. This causes issues with things like type casts because they often sit inside member expressions. So we need a better solution. We can't access the existing logic from within our rule, so we have to copy the code into this plugin. So far, I've forked the base indent rule code + tests from eslint core into this rule, and added types to them. Unfortunately though, the rule is HUGE (rule's logic alone is ~1700 lines). This means that it's a pretty huge task to add support for all of the typescript features because there's so much code to read through and understand. I unfortunately don't have the time to tackle that right now. Happy for anyone to pick it up and give it a go. |
Damn, this is rough. |
What about changing the generics to function calls? I ran a quick test. I started with this code: export class WhatALongComponent extends React.Component<
WhatALongComponentProps,
WhatALongComponentState
> {}
const longVariablae = longFunction<
LongGeneric,
LongerGeneric,
LongestGeneric,
>(); Then I replaced both sets of generics export class WhatALongComponent extends React.Component(
WhatALongComponentProps,
WhatALongComponentState
) {}
const longVariablae = longFunction(
LongGeneric,
LongerGeneric,
LongestGeneric,
)(); The I ran export class WhatALongComponent extends React.Component(
WhatALongComponentProps,
WhatALongComponentState,
) {}
const longVariablae = longFunction(
LongGeneric,
LongerGeneric,
LongestGeneric,
)(); Success! |
I got the same issue with indenting using generics, both of this is valid using indent of 4; let list = [1, 2, 3]
.map(value => {
return String(value)
})
let list = [1, 2, 3]
.map<string>(value => {
return String(value)
}) |
Would it be possible to disable this behaviour using the
|
any updates on this? This issue is getting really annoying for us |
Happy to accept a PR |
As a workaround (like @juliendargelos mentions) we'll ignore |
add a custom `ignoreNodes` specification on `@typescript-eslint/indent` to avoid errors related to multiline parametrized type instantiation. cf. typescript-eslint/typescript-eslint#455
add a custom `ignoreNodes` specification on `@typescript-eslint/indent` to avoid errors related to multiline parametrized type instantiation. cf. typescript-eslint/typescript-eslint#455
add a custom `ignoreNodes` specification on `@typescript-eslint/indent` to avoid errors related to multiline parametrized type instantiation. cf. typescript-eslint/typescript-eslint#455
@juliendargelos How do you use the option I'm new to eslint and the IDE (JetBrain IDEA) cannot provide hints on .eslintrc.js, just treat it as a js file. Used to have hints like options suggestion and auto-complete on tslint.json |
@beenotung I guess you could use it this way (doc here): module.exports = {
rules: {
'@typescript-eslint/indent': ['error', 2, {
ignoredNodes: ['TSTypeParameterInstantiation']
}]
}
} |
@juliendargelos I can confirm that I did it like this and it worked. |
I just tried above settings on indentation, it's still giving errors when I run |
@beenotung you definitely should disable all styling rules if you use prettier There's no point having prettier and styling rules like indent on at the same time. Best bet is to do the same thing we do in this repo - run prettier as a CI check to help enforce formatting. |
@bradzacher I saw there are two conflicting setting recommended online. |
@juliendargelos yes, we have pretty much exactly the same config Fwiw, we're using |
The problem with As for what you should use - IMO you should not use Using |
Merging into #1824 |
Repro
Expected Result
No indent error, should keep indentation of 2 spaces.
Actual Result
Additional Info
Versions
@typescript-eslint/eslint-plugin
1.7.0
@typescript-eslint/parser
1.7.0
TypeScript
3.3.4000
ESLint
5.16.0
node
11.11.0
npm
6.9.0
The text was updated successfully, but these errors were encountered: