Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e13613fd5f | ||
|
e111029e0a |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config-monorepo",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@7.1.0",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"description": "Anthony's ESLint config",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"license": "MIT",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config-basic",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"description": "",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"license": "MIT",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eslint-plugin-antfu",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/antfu/eslint-config",
|
||||
"main": "./dist/index.cjs",
|
||||
|
@@ -4,17 +4,21 @@ import rule, { RULE_NAME } from './generic-spacing'
|
||||
|
||||
const valids = [
|
||||
'type Foo<T = true> = T',
|
||||
'type Foo<T extends true = true> = T',
|
||||
`
|
||||
type Foo<
|
||||
T = true,
|
||||
K = false
|
||||
> = T`,
|
||||
'type Foo<T extends true = true> = T',
|
||||
`function foo<
|
||||
T
|
||||
>() {}`,
|
||||
]
|
||||
const invalids = [
|
||||
['type Foo<T=true> = T', 'type Foo<T = true> = T'],
|
||||
['type Foo<T,K> = T', 'type Foo<T, K> = T'],
|
||||
['type Foo<T=false,K=1|2> = T', 'type Foo<T = false, K = 1|2> = T', 3],
|
||||
['function foo <T>() {}', 'function foo<T>() {}'],
|
||||
] as const
|
||||
|
||||
it('runs', () => {
|
||||
|
@@ -23,6 +23,20 @@ export default createEslintRule<Options, MessageIds>({
|
||||
const sourceCode = context.getSourceCode()
|
||||
return {
|
||||
TSTypeParameterDeclaration: (node) => {
|
||||
const pre = sourceCode.text.slice(0, node.range[0])
|
||||
const preSpace = pre.match(/(\s+)$/)?.[0]
|
||||
// strip space before <T>
|
||||
if (preSpace && preSpace.length) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'genericSpacingMismatch',
|
||||
*fix(fixer) {
|
||||
yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], '')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// add space between <T,K>
|
||||
const params = node.params
|
||||
for (let i = 1; i < params.length; i++) {
|
||||
const prev = params[i - 1]
|
||||
@@ -45,6 +59,7 @@ export default createEslintRule<Options, MessageIds>({
|
||||
}
|
||||
}
|
||||
},
|
||||
// add space around = in type Foo<T = true>
|
||||
TSTypeParameter: (node) => {
|
||||
if (!node.default)
|
||||
return
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config-react",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"description": "",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"license": "MIT",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config-ts",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"description": "",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"license": "MIT",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@antfu/eslint-config-vue",
|
||||
"version": "0.29.1",
|
||||
"version": "0.29.2",
|
||||
"description": "",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||
"license": "MIT",
|
||||
|
Reference in New Issue
Block a user