Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 73 additions & 24 deletions
97
packages/eslint-plugin-antfu/src/rules/named-tuple-spacing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,95 @@ | ||
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint' | ||
import { it } from 'vitest' | ||
import type { MessageIds } from './named-tuple-spacing' | ||
import rule, { RULE_NAME } from './named-tuple-spacing' | ||
|
||
const valids = [ | ||
'type T = [i: number]', | ||
'type T = [i: number]', // passes since it will be handled by eslint's no-multi-spaces | ||
'type T = [i?: number]', | ||
'type T = [i: number, j: number]', | ||
`const emit = defineEmits<{ | ||
change: [id: number] | ||
update: [value: string] | ||
}>()`, | ||
] | ||
|
||
const invalids = [ | ||
['type T = [i:number]', 'type T = [i: number]'], | ||
['type T = [i : number]', 'type T = [i: number]', 1, 'unexpectedSpaceBefore'], | ||
['type T = [i:number, j:number]', 'type T = [i: number, j: number]', 2], | ||
[ | ||
`const emit = defineEmits<{ | ||
change: [id:number] | ||
update: [value:string] | ||
}>()`, | ||
`const emit = defineEmits<{ | ||
change: [id: number] | ||
update: [value: string] | ||
}>()`, | ||
2, | ||
], | ||
] as [error: string, correct: string, errorNumber: number | undefined, errorMsg: MessageIds | undefined][] | ||
|
||
it('runs', () => { | ||
const ruleTester: RuleTester = new RuleTester({ | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
}) | ||
|
||
ruleTester.run(RULE_NAME, rule, { | ||
valid: valids, | ||
invalid: invalids.map(i => ({ | ||
code: i[0], | ||
output: i[1].trim(), | ||
errors: Array.from({ length: i[2] || 1 }, () => ({ messageId: i[3] || 'expectedSpaceAfter' })), | ||
})), | ||
invalid: [ | ||
{ | ||
code: 'type T = [i:number]', | ||
output: 'type T = [i: number]', | ||
errors: [{ messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: 'type T = [i: number]', | ||
output: 'type T = [i: number]', | ||
errors: [{ messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: 'type T = [i?:number]', | ||
output: 'type T = [i?: number]', | ||
errors: [{ messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: 'type T = [i? :number]', | ||
output: 'type T = [i?: number]', | ||
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: 'type T = [i : number]', | ||
output: 'type T = [i: number]', | ||
errors: [{ messageId: 'unexpectedSpaceBefore' }], | ||
}, | ||
{ | ||
code: 'type T = [i : number]', | ||
output: 'type T = [i: number]', | ||
errors: [{ messageId: 'unexpectedSpaceBefore' }], | ||
}, | ||
{ | ||
code: 'type T = [i ? : number]', | ||
output: 'type T = [i?: number]', | ||
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'unexpectedSpaceBefore' }], | ||
}, | ||
{ | ||
code: 'type T = [i:number, j:number]', | ||
output: 'type T = [i: number, j: number]', | ||
errors: [{ messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: ` | ||
const emit = defineEmits<{ | ||
change: [id:number] | ||
update: [value:string] | ||
}>() | ||
`, | ||
output: ` | ||
const emit = defineEmits<{ | ||
change: [id: number] | ||
update: [value: string] | ||
}>() | ||
`, | ||
errors: [{ messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }], | ||
}, | ||
{ | ||
code: ` | ||
const emit = defineEmits<{ | ||
change: [id? :number] | ||
update: [value:string] | ||
}>() | ||
`, | ||
output: ` | ||
const emit = defineEmits<{ | ||
change: [id?: number] | ||
update: [value: string] | ||
}>() | ||
`, | ||
errors: [{ messageId: 'unexpectedSpaceBetween' }, { messageId: 'expectedSpaceAfter' }, { messageId: 'expectedSpaceAfter' }], | ||
}, | ||
], | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.