Skip to content

Commit 6531988

Browse files
authored
Fix incompatibility with typescript-eslint v6 in vue/script-indent rule (#2256)
1 parent 56180e3 commit 6531988

File tree

14 files changed

+69
-65
lines changed

14 files changed

+69
-65
lines changed

.circleci/config.yml

+17-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- run:
4545
name: Install eslint@6
4646
command: |
47-
npm install --save-exact eslint@6.8.0
47+
npm install --save-exact eslint@6.8.0 @typescript-eslint/parser@5
4848
- run:
4949
name: Install dependencies
5050
command: npm install
@@ -62,7 +62,7 @@ jobs:
6262
- run:
6363
name: Install eslint@7
6464
command: |
65-
npm install eslint@7
65+
npm install eslint@7 @typescript-eslint/parser@5
6666
- run:
6767
name: Install dependencies
6868
command: npm install
@@ -88,9 +88,23 @@ jobs:
8888
name: Test
8989
command: npm test
9090
node-v14:
91-
<<: *node-base
9291
docker:
9392
- image: node:14
93+
steps:
94+
- run:
95+
name: Versions
96+
command: npm version
97+
- checkout
98+
- run:
99+
name: Install @typescript-eslint/parser@5
100+
command: |
101+
npm install @typescript-eslint/parser@5 --save-exact
102+
- run:
103+
name: Install dependencies
104+
command: npm install
105+
- run:
106+
name: Test
107+
command: npm test
94108
node-v16:
95109
<<: *node-base
96110
docker:

.github/workflows/CI.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
uses: actions/checkout@v3
1818
- name: Install Node.js
1919
uses: actions/setup-node@v3
20-
with:
21-
node-version: 16
2220
- name: Install Packages
2321
run: npm install --legacy-peer-deps
2422
- name: Lint
@@ -28,7 +26,7 @@ jobs:
2826
name: Test
2927
strategy:
3028
matrix:
31-
node: [17, 18]
29+
node: [17, 18, 20]
3230
os: [ubuntu-latest]
3331

3432
runs-on: ${{ matrix.os }}
@@ -43,3 +41,20 @@ jobs:
4341
run: npm install --legacy-peer-deps
4442
- name: Test
4543
run: npm test
44+
45+
test-for-ts-eslint-v5:
46+
name: Test
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v3
51+
- name: Install Node.js v${{ matrix.node }}
52+
uses: actions/setup-node@v3
53+
with:
54+
node-version: 18
55+
- name: Install Packages
56+
run: npm install --legacy-peer-deps
57+
- name: Install typescript-eslint v5
58+
run: npm install -D @typescript-eslint/parser
59+
- name: Test
60+
run: npm test

docs/.vitepress/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// @ts-expect-error -- Cannot change `module` option
12
import type { DefaultTheme } from 'vitepress'
3+
// @ts-expect-error -- Cannot change `module` option
24
import { defineConfig } from 'vitepress'
35
import { BUNDLED_LANGUAGES } from 'shiki'
46
import path from 'path'

docs/.vitepress/theme/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ if (typeof window !== 'undefined') {
99
}
1010
}
1111
}
12+
// @ts-expect-error -- Cannot change `module` option
1213
import type { Theme } from 'vitepress'
14+
// @ts-expect-error -- Cannot change `module` option
1315
import DefaultTheme from 'vitepress/theme'
1416
// @ts-expect-error -- ignore
1517
import Layout from './Layout.vue'

docs/.vitepress/vite-plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-expect-error -- Cannot change `module` option
12
import type { UserConfig } from 'vitepress'
23
import path from 'path'
34
import { fileURLToPath } from 'url'

lib/utils/indent-ts.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1168,18 +1168,24 @@ function defineVisitor({
11681168
isOpeningParenToken
11691169
)
11701170
setOffset(leftParenToken, 1, firstToken)
1171+
const argument =
1172+
node.argument ||
1173+
/** @type {any} typescript-eslint v5 */ (node).parameter
11711174
const rightParenToken = tokenStore.getTokenAfter(
1172-
node.parameter,
1175+
argument,
11731176
isClosingParenToken
11741177
)
1175-
processNodeList([node.parameter], leftParenToken, rightParenToken, 1)
1178+
processNodeList([argument], leftParenToken, rightParenToken, 1)
11761179
if (node.qualifier) {
11771180
const dotToken = tokenStore.getTokenBefore(node.qualifier)
11781181
const propertyToken = tokenStore.getTokenAfter(dotToken)
11791182
setOffset([dotToken, propertyToken], 1, firstToken)
11801183
}
1181-
if (node.typeParameters) {
1182-
setOffset(tokenStore.getFirstToken(node.typeParameters), 1, firstToken)
1184+
const typeArguments =
1185+
node.typeArguments ||
1186+
/** @type {any} typescript-eslint v5 */ (node).typeParameters
1187+
if (typeArguments) {
1188+
setOffset(tokenStore.getFirstToken(typeArguments), 1, firstToken)
11831189
}
11841190
},
11851191
TSParameterProperty(node) {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
"@types/node": "^14.18.54",
7171
"@types/semver": "^7.5.0",
7272
"@types/xml-name-validator": "^4.0.1",
73-
"@typescript-eslint/parser": "^5.45.0",
73+
"@typescript-eslint/parser": "^6.2.0",
74+
"@typescript-eslint/types": "^6.2.0",
7475
"assert": "^2.0.0",
7576
"env-cmd": "^10.1.0",
7677
"esbuild": "^0.18.17",

tests/fixtures/script-indent/ts-class-declaration-04.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ class
55
<
66
T
77
>
8+
extends
9+
Bar
10+
<
11+
T
12+
>
813
implements
914
Baz1
1015
<
@@ -15,11 +20,6 @@ class
1520
<
1621
T
1722
>
18-
extends
19-
Bar
20-
<
21-
T
22-
>
2323
{
2424
prop:string
2525
}

tests/fixtures/script-indent/ts-class-declaration-05.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<script lang="ts">
33
class
44
Foo
5+
extends
6+
Bar
57
implements
68
Baz1
79
,
810
Baz2
9-
extends
10-
Bar
1111
{
1212
prop:string
1313
}

tests/fixtures/script-indent/ts-class-declaration-06.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ class
2323
boolean
2424
=
2525
false
26-
)
26+
) {}
2727
}
2828
</script>

tests/fixtures/script-indent/ts-interface-declaration-05.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ interface Foo
44
<
55
T
66
>
7-
implements // visitor key is not provided
8-
Bar
9-
<
10-
T
11-
>
7+
// implements // parsing error
8+
// Bar
9+
// <
10+
// T
11+
// >
1212
{ }
1313
</script>

tests/lib/rules/no-required-prop-with-default.js

-41
Original file line numberDiff line numberDiff line change
@@ -508,47 +508,6 @@ tester.run('no-required-prop-with-default', rule, {
508508
}
509509
]
510510
},
511-
{
512-
filename: 'test.vue',
513-
code: `
514-
<script setup lang="ts">
515-
interface TestPropType {
516-
readonly foo(): void
517-
age?: number
518-
}
519-
const props = withDefaults(
520-
defineProps<TestPropType>(),
521-
{
522-
foo() {console.log(123)},
523-
}
524-
);
525-
</script>
526-
`,
527-
output: `
528-
<script setup lang="ts">
529-
interface TestPropType {
530-
readonly foo?(): void
531-
age?: number
532-
}
533-
const props = withDefaults(
534-
defineProps<TestPropType>(),
535-
{
536-
foo() {console.log(123)},
537-
}
538-
);
539-
</script>
540-
`,
541-
options: [{ autofix: true }],
542-
parserOptions: {
543-
parser: require.resolve('@typescript-eslint/parser')
544-
},
545-
errors: [
546-
{
547-
message: 'Prop "foo" should be optional.',
548-
line: 4
549-
}
550-
]
551-
},
552511
{
553512
filename: 'test.vue',
554513
code: `

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2019",
44
"module": "commonjs",
5+
"moduleResolution": "Node16",
56
"lib": ["es2020"],
67
"allowJs": true,
78
"checkJs": true,

typings/eslint-plugin-vue/util-types/ast/es-ast.ts

+3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ export type Expression =
341341
export interface Identifier extends HasParentNode {
342342
type: 'Identifier'
343343
name: string
344+
345+
// for typescript-eslint
346+
typeAnnotation?: any
344347
}
345348
export interface PrivateIdentifier extends HasParentNode {
346349
type: 'PrivateIdentifier'

0 commit comments

Comments
 (0)