Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.9k
fix(eslint-plugin): fix crash and false positives inno-useless-default-assignment#11845
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
Changes fromall commits
93642444d5189f1908ae6755c0321cfcf21148ca956921a1a5bf124784419dff25f541File 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 |
|---|---|---|
| @@ -184,6 +184,46 @@ ruleTester.run('no-useless-default-assignment', rule, { | ||
| }, | ||
| }, | ||
| }, | ||
| ` | ||
| declare const g: Array<string>; | ||
| const [foo = ''] = g; | ||
| `, | ||
| ` | ||
| declare const g: Record<string, string>; | ||
| const { foo = '' } = g; | ||
| `, | ||
| ` | ||
| declare const h: { [key: string]: string }; | ||
| const { bar = '' } = h; | ||
| `, | ||
| // https://github.com/typescript-eslint/typescript-eslint/issues/11849 | ||
| ` | ||
| type Merge = boolean | ((incoming: string[]) => void); | ||
| const policy: { merge: Merge } = { | ||
| merge: (incoming: string[] = []) => { | ||
| incoming; | ||
| }, | ||
| }; | ||
| `, | ||
| // https://github.com/typescript-eslint/typescript-eslint/issues/11846 | ||
| ` | ||
| const [a, b = ''] = 'somestr'.split('.'); | ||
| `, | ||
| // https://github.com/typescript-eslint/typescript-eslint/issues/11846 | ||
| ` | ||
| declare const params: string[]; | ||
| const [c = '123'] = params; | ||
| `, | ||
| // https://github.com/typescript-eslint/typescript-eslint/issues/11846 | ||
| ` | ||
| declare function useCallback<T>(callback: T); | ||
| useCallback((value: number[] = []) => {}); | ||
| `, | ||
| ` | ||
| declare const tuple: [string]; | ||
| const [a, b = 'default'] = tuple; | ||
Member 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. (praise) TIL that TS allows out-of-bounds tuple destructuring if a default value is present. Comically it means that const[a,outOfBounds=undefined]=["foo"]asconst; iskind of a false positive if you really squint, but I think let's completely ignore that edge case as niche and unimportant. | ||
| `, | ||
| ], | ||
| invalid: [ | ||
| { | ||
| @@ -459,62 +499,5 @@ ruleTester.run('no-useless-default-assignment', rule, { | ||
| function foo({ a }) {} | ||
| `, | ||
| }, | ||
| ], | ||
| }); | ||