Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-inferrable] fix optional param to valid code#5342
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -156,7 +156,54 @@ class Foo { | ||
invalid: [ | ||
...invalidTestCases, | ||
{ | ||
// This is invalid TS semantic, but it's trivial to make valid anyway | ||
code: 'const fn = (a?: number = 5) => {};', | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. not sure if we want to handle this in here, but there is one more use case that is broken. classTest{x!:number=5abstracty!:number=5} maybe something like this could be better: if(node.type===AST_NODE_TYPES.AssignmentPattern&&node.left.optional){yieldfixer.remove(sourceCode.getTokenBefore(typeNode)!);}elseif((node.type===AST_NODE_TYPES.TSAbstractPropertyDefinition||node.type===AST_NODE_TYPES.PropertyDefinition)&&node.definite){yieldfixer.remove(sourceCode.getTokenBefore(typeNode)!);} we can make separate ticket for this, if you like there is also classTest2{constructor(privatea:number=5){}} witch is currently not reported MemberAuthor
| ||
output: 'const fn = (a = 5) => {};', | ||
options: [ | ||
{ | ||
ignoreParameters: false, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'noInferrableType', | ||
data: { | ||
type: 'number', | ||
}, | ||
line: 1, | ||
column: 13, | ||
}, | ||
], | ||
}, | ||
{ | ||
// This is invalid TS semantic, but it's trivial to make valid anyway | ||
code: ` | ||
class A { | ||
a!: number = 1; | ||
} | ||
`, | ||
output: ` | ||
class A { | ||
a = 1; | ||
} | ||
`, | ||
options: [ | ||
{ | ||
ignoreProperties: false, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'noInferrableType', | ||
data: { | ||
type: 'number', | ||
}, | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "const fn = (a: number = 5, b: boolean = true, c: string = 'foo') => {};", | ||
output: "const fn = (a = 5, b = true, c = 'foo') => {};", | ||