Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c368e18

Browse files
committedJul 29, 2023
Fix incompatibility with typescript-eslint v6 in vue/script-indent rule
1 parent 56180e3 commit c368e18

File tree

13 files changed

+57
-62
lines changed

13 files changed

+57
-62
lines changed
 

‎.github/workflows/CI.yml

Lines changed: 23 additions & 3 deletions
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,27 @@ jobs:
2826
name: Test
2927
strategy:
3028
matrix:
31-
node: [17, 18]
29+
node: [17, 18, 20]
30+
os: [ubuntu-latest]
31+
32+
runs-on: ${{ matrix.os }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
- name: Install Node.js v${{ matrix.node }}
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: ${{ matrix.node }}
40+
- name: Install Packages
41+
run: npm install --legacy-peer-deps
42+
- name: Test
43+
run: npm test
44+
45+
test-for-ts-eslint-v5:
46+
name: Test
47+
strategy:
48+
matrix:
49+
node: [18]
3250
os: [ubuntu-latest]
3351

3452
runs-on: ${{ matrix.os }}
@@ -41,5 +59,7 @@ jobs:
4159
node-version: ${{ matrix.node }}
4260
- name: Install Packages
4361
run: npm install --legacy-peer-deps
62+
- name: Install typescript-eslint v5
63+
run: npm install -D @typescript-eslint/parser
4464
- name: Test
4565
run: npm test

‎docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 4 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 0 additions & 41 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)
Please sign in to comment.