From c368e18b5c5d73f7439f94d196e9bd199fe5181f Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 29 Jul 2023 21:49:55 +0900 Subject: [PATCH 1/4] Fix incompatibility with typescript-eslint v6 in `vue/script-indent` rule --- .github/workflows/CI.yml | 26 ++++++++++-- docs/.vitepress/config.ts | 2 + docs/.vitepress/theme/index.ts | 2 + docs/.vitepress/vite-plugin.ts | 1 + lib/utils/indent-ts.js | 14 +++++-- package.json | 3 +- .../script-indent/ts-class-declaration-04.vue | 10 ++--- .../script-indent/ts-class-declaration-05.vue | 4 +- .../script-indent/ts-class-declaration-06.vue | 2 +- .../ts-interface-declaration-05.vue | 10 ++--- .../rules/no-required-prop-with-default.js | 41 ------------------- tsconfig.json | 1 + .../util-types/ast/es-ast.ts | 3 ++ 13 files changed, 57 insertions(+), 62 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 910d33c70..b47c4e3d4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,8 +17,6 @@ jobs: uses: actions/checkout@v3 - name: Install Node.js uses: actions/setup-node@v3 - with: - node-version: 16 - name: Install Packages run: npm install --legacy-peer-deps - name: Lint @@ -28,7 +26,27 @@ jobs: name: Test strategy: matrix: - node: [17, 18] + node: [17, 18, 20] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Node.js v${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - name: Install Packages + run: npm install --legacy-peer-deps + - name: Test + run: npm test + + test-for-ts-eslint-v5: + name: Test + strategy: + matrix: + node: [18] os: [ubuntu-latest] runs-on: ${{ matrix.os }} @@ -41,5 +59,7 @@ jobs: node-version: ${{ matrix.node }} - name: Install Packages run: npm install --legacy-peer-deps + - name: Install typescript-eslint v5 + run: npm install -D @typescript-eslint/parser - name: Test run: npm test diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 5b2d65516..baa74d471 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,4 +1,6 @@ +// @ts-expect-error -- Cannot change `module` option import type { DefaultTheme } from 'vitepress' +// @ts-expect-error -- Cannot change `module` option import { defineConfig } from 'vitepress' import { BUNDLED_LANGUAGES } from 'shiki' import path from 'path' diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 8afcf4054..757e63cab 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -9,7 +9,9 @@ if (typeof window !== 'undefined') { } } } +// @ts-expect-error -- Cannot change `module` option import type { Theme } from 'vitepress' +// @ts-expect-error -- Cannot change `module` option import DefaultTheme from 'vitepress/theme' // @ts-expect-error -- ignore import Layout from './Layout.vue' diff --git a/docs/.vitepress/vite-plugin.ts b/docs/.vitepress/vite-plugin.ts index 2a044ced1..4b5b2a619 100644 --- a/docs/.vitepress/vite-plugin.ts +++ b/docs/.vitepress/vite-plugin.ts @@ -1,3 +1,4 @@ +// @ts-expect-error -- Cannot change `module` option import type { UserConfig } from 'vitepress' import path from 'path' import { fileURLToPath } from 'url' diff --git a/lib/utils/indent-ts.js b/lib/utils/indent-ts.js index 5ab3df993..c6f146f66 100644 --- a/lib/utils/indent-ts.js +++ b/lib/utils/indent-ts.js @@ -1168,18 +1168,24 @@ function defineVisitor({ isOpeningParenToken ) setOffset(leftParenToken, 1, firstToken) + const argument = + node.argument || + /** @type {any} typescript-eslint v5 */ (node).parameter const rightParenToken = tokenStore.getTokenAfter( - node.parameter, + argument, isClosingParenToken ) - processNodeList([node.parameter], leftParenToken, rightParenToken, 1) + processNodeList([argument], leftParenToken, rightParenToken, 1) if (node.qualifier) { const dotToken = tokenStore.getTokenBefore(node.qualifier) const propertyToken = tokenStore.getTokenAfter(dotToken) setOffset([dotToken, propertyToken], 1, firstToken) } - if (node.typeParameters) { - setOffset(tokenStore.getFirstToken(node.typeParameters), 1, firstToken) + const typeArguments = + node.typeArguments || + /** @type {any} typescript-eslint v5 */ (node).typeParameters + if (typeArguments) { + setOffset(tokenStore.getFirstToken(typeArguments), 1, firstToken) } }, TSParameterProperty(node) { diff --git a/package.json b/package.json index d23aca8c7..a13f8f854 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,8 @@ "@types/node": "^14.18.54", "@types/semver": "^7.5.0", "@types/xml-name-validator": "^4.0.1", - "@typescript-eslint/parser": "^5.45.0", + "@typescript-eslint/parser": "^6.2.0", + "@typescript-eslint/types": "^6.2.0", "assert": "^2.0.0", "env-cmd": "^10.1.0", "esbuild": "^0.18.17", diff --git a/tests/fixtures/script-indent/ts-class-declaration-04.vue b/tests/fixtures/script-indent/ts-class-declaration-04.vue index 1b7e09fdb..206c64347 100644 --- a/tests/fixtures/script-indent/ts-class-declaration-04.vue +++ b/tests/fixtures/script-indent/ts-class-declaration-04.vue @@ -5,6 +5,11 @@ class < T > + extends + Bar + < + T + > implements Baz1 < @@ -15,11 +20,6 @@ class < T > - extends - Bar - < - T - > { prop:string } diff --git a/tests/fixtures/script-indent/ts-class-declaration-05.vue b/tests/fixtures/script-indent/ts-class-declaration-05.vue index 69bff1cc1..4f0796e35 100644 --- a/tests/fixtures/script-indent/ts-class-declaration-05.vue +++ b/tests/fixtures/script-indent/ts-class-declaration-05.vue @@ -2,12 +2,12 @@ diff --git a/tests/fixtures/script-indent/ts-interface-declaration-05.vue b/tests/fixtures/script-indent/ts-interface-declaration-05.vue index 2e14604b6..9b59a53dd 100644 --- a/tests/fixtures/script-indent/ts-interface-declaration-05.vue +++ b/tests/fixtures/script-indent/ts-interface-declaration-05.vue @@ -4,10 +4,10 @@ interface Foo < T > -implements // visitor key is not provided -Bar -< -T -> +// implements // parsing error +// Bar +// < +// T +// > { } diff --git a/tests/lib/rules/no-required-prop-with-default.js b/tests/lib/rules/no-required-prop-with-default.js index ec1e749cc..f1f5b655a 100644 --- a/tests/lib/rules/no-required-prop-with-default.js +++ b/tests/lib/rules/no-required-prop-with-default.js @@ -508,47 +508,6 @@ tester.run('no-required-prop-with-default', rule, { } ] }, - { - filename: 'test.vue', - code: ` - - `, - output: ` - - `, - options: [{ autofix: true }], - parserOptions: { - parser: require.resolve('@typescript-eslint/parser') - }, - errors: [ - { - message: 'Prop "foo" should be optional.', - line: 4 - } - ] - }, { filename: 'test.vue', code: ` diff --git a/tsconfig.json b/tsconfig.json index d64b99e1c..ac4ab815a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "ES2019", "module": "commonjs", + "moduleResolution": "Node16", "lib": ["es2020"], "allowJs": true, "checkJs": true, diff --git a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts index 800943419..944246411 100644 --- a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts @@ -341,6 +341,9 @@ export type Expression = export interface Identifier extends HasParentNode { type: 'Identifier' name: string + + // for typescript-eslint + typeAnnotation?: any } export interface PrivateIdentifier extends HasParentNode { type: 'PrivateIdentifier' From 22803ecffc910fd38cb1f577981454f953984751 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 29 Jul 2023 21:56:59 +0900 Subject: [PATCH 2/4] update --- .circleci/config.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d9b4f0204..ad2a1ff01 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: - run: name: Install eslint@6 command: | - npm install --save-exact eslint@6.8.0 + npm install --save-exact eslint@6.8.0 @typescript-eslint/parser@5 - run: name: Install dependencies command: npm install @@ -62,7 +62,7 @@ jobs: - run: name: Install eslint@7 command: | - npm install eslint@7 + npm install eslint@7 @typescript-eslint/parser@5 - run: name: Install dependencies command: npm install @@ -88,9 +88,23 @@ jobs: name: Test command: npm test node-v14: - <<: *node-base docker: - image: node:14 + steps: + - run: + name: Versions + command: npm version + - checkout + - run: + name: Install @typescript-eslint/parser@5 + command: | + npm install @typescript-eslint/parser@5 --save-exact + - run: + name: Install dependencies + command: npm install + - run: + name: Test + command: npm tests node-v16: <<: *node-base docker: From fc4ab61cdb3258ff6d076069b95a93da21379c5c Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 29 Jul 2023 22:00:21 +0900 Subject: [PATCH 3/4] fix typo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ad2a1ff01..cd2a71931 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -104,7 +104,7 @@ jobs: command: npm install - run: name: Test - command: npm tests + command: npm test node-v16: <<: *node-base docker: From d3852388a150cc1f8741212bb6aed73dd97bfc2c Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 30 Jul 2023 05:41:44 +0900 Subject: [PATCH 4/4] chore: refactor ci --- .github/workflows/CI.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b47c4e3d4..afb8b9ad4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -44,19 +44,14 @@ jobs: test-for-ts-eslint-v5: name: Test - strategy: - matrix: - node: [18] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Install Node.js v${{ matrix.node }} uses: actions/setup-node@v3 with: - node-version: ${{ matrix.node }} + node-version: 18 - name: Install Packages run: npm install --legacy-peer-deps - name: Install typescript-eslint v5