diff --git a/.changeset/fast-penguins-reflect.md b/.changeset/fast-penguins-reflect.md new file mode 100644 index 000000000..bbc3004ba --- /dev/null +++ b/.changeset/fast-penguins-reflect.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-vue": minor +--- + +Added `@typescript-eslint/parser` as an optional peer dependency. diff --git a/.changeset/gentle-glasses-tie.md b/.changeset/gentle-glasses-tie.md new file mode 100644 index 000000000..815a2ced6 --- /dev/null +++ b/.changeset/gentle-glasses-tie.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-vue": patch +--- + +Fixed false negatives when using typescript-eslint v8 in [`vue/script-indent`](https://eslint.vuejs.org/rules/script-indent.html) rule diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 57aa5876d..90bd33ad5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -46,7 +46,7 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install Packages - run: npm install -f + run: npm install - name: Install ESLint v${{ matrix.eslint }} run: npm install --save-dev eslint@${{ matrix.eslint }} -f - name: Test @@ -61,8 +61,23 @@ jobs: - name: Install Node.js uses: actions/setup-node@v4 - name: Install Packages - run: npm install -f + run: npm install - name: Uninstall @stylistic/eslint-plugin run: npm uninstall -D @stylistic/eslint-plugin - name: Test run: npm test + + test-with-typescript-eslint-v7: + name: Test with typescript-eslint v7 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node.js + uses: actions/setup-node@v4 + - name: Install Packages + run: npm install + - name: Install @typescript-eslint/parser@7 + run: npm install -D @typescript-eslint/parser@7 -f + - name: Test + run: npm test diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 260b73582..3653780d5 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -22,7 +22,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 - name: Install Dependencies - run: npm install -f + run: npm install - name: Create Release Pull Request or Publish to npm id: changesets diff --git a/.gitignore b/.gitignore index 797d0cbcd..0458765cd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,8 @@ yarn.lock yarn-error.log /docs/.vitepress/dist -/docs/.vitepress/build-system/shim/eslint.mjs -/docs/.vitepress/build-system/shim/assert.mjs +/docs/.vitepress/build-system/shim/vue-eslint-parser.mjs +/docs/.vitepress/build-system/shim/@typescript-eslint/parser.mjs /docs/.vitepress/.temp /docs/.vitepress/cache typings/eslint/lib/rules diff --git a/docs/.vitepress/build-system/build.mts b/docs/.vitepress/build-system/build.mts index 9dce53faf..edda69143 100644 --- a/docs/.vitepress/build-system/build.mts +++ b/docs/.vitepress/build-system/build.mts @@ -9,14 +9,38 @@ import { fileURLToPath } from 'url' const dirname = path.dirname(fileURLToPath(import.meta.url)) build( - path.join(dirname, './src/eslint.mjs'), - path.join(dirname, './shim/eslint.mjs'), - ['path', 'assert', 'util', 'esquery'] + path.join( + dirname, + '../../../node_modules/@typescript-eslint/parser/dist/index.js' + ), + path.join(dirname, './shim/@typescript-eslint/parser.mjs'), + [ + 'util', + 'node:util', + 'path', + 'node:path', + 'fs', + 'node:fs', + 'semver', + 'fast-glob', + 'debug' + ] ) + build( - path.join(dirname, '../../../node_modules/assert'), - path.join(dirname, './shim/assert.mjs'), - ['path'] + path.join(dirname, '../../../node_modules/vue-eslint-parser/index.js'), + path.join(dirname, './shim/vue-eslint-parser.mjs'), + [ + 'path', + 'debug', + 'semver', + 'assert', + 'module', + 'events', + 'esquery', + 'fs', + 'eslint' + ] ) function build(input: string, out: string, injects: string[] = []) { @@ -42,16 +66,22 @@ function bundle(entryPoint: string, externals: string[]) { } function transform(code: string, injects: string[]) { + const normalizeInjects = [ + ...new Set(injects.map((inject) => inject.replace(/^node:/u, ''))) + ] const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, '') return ` -${injects +${normalizeInjects .map( (inject) => - `import $inject_${inject.replace(/-/gu, '_')}$ from '${inject}';` + `import $inject_${inject.replace(/[\-:]/gu, '_')}$ from '${inject}';` ) .join('\n')} const $_injects_$ = {${injects - .map((inject) => `${inject.replace(/-/gu, '_')}:$inject_${inject}$`) + .map( + (inject) => + `"${inject}":$inject_${inject.replace(/^node:/u, '').replace(/[\-:]/gu, '_')}$` + ) .join(',\n')}}; function require(module, ...args) { return $_injects_$[module] || {} diff --git a/docs/.vitepress/build-system/shim/globby.mjs b/docs/.vitepress/build-system/shim/empty.mjs similarity index 100% rename from docs/.vitepress/build-system/shim/globby.mjs rename to docs/.vitepress/build-system/shim/empty.mjs diff --git a/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs b/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs deleted file mode 100644 index 0db0b01c2..000000000 --- a/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs +++ /dev/null @@ -1,3 +0,0 @@ -export default { - /* empty */ -} diff --git a/docs/.vitepress/build-system/shim/esquery.mjs b/docs/.vitepress/build-system/shim/esquery.mjs deleted file mode 100644 index 5652b09f1..000000000 --- a/docs/.vitepress/build-system/shim/esquery.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import esquery from '../../../../node_modules/esquery/dist/esquery.esm.js' - -export const { parse, match, traverse, matches, query } = esquery - -export { default } from '../../../../node_modules/esquery/dist/esquery.esm.js' diff --git a/docs/.vitepress/build-system/shim/path.mjs b/docs/.vitepress/build-system/shim/path.mjs deleted file mode 100644 index 544792b00..000000000 --- a/docs/.vitepress/build-system/shim/path.mjs +++ /dev/null @@ -1,38 +0,0 @@ -// @ts-nocheck -export const sep = '/' -export function basename(path, ext) { - const b = (/[^\/]*$/u.exec(path) || [''])[0] - return ext && b.endsWith(ext) ? b.slice(0, -ext.length) : b -} -export function extname(path) { - return (/[^.\/]*$/u.exec(path) || [''])[0] -} -export function isAbsolute() { - return false -} -export function join(...args) { - return args.length > 0 ? normalize(args.join('/')) : '.' -} - -function normalize(path) { - const result = [] - for (const part of path.replace(/\/+/gu, '/').split('/')) { - if (part === '..') { - if (result[0] && result[0] !== '..' && result[0] !== '.') result.shift() - } else if (part === '.' && result.length > 0) { - // noop - } else { - result.unshift(part) - } - } - return result.reverse().join('/') -} -const posix = { - sep, - basename, - extname, - isAbsolute, - join -} -posix.posix = posix -export default posix diff --git a/docs/.vitepress/build-system/src/eslint.mjs b/docs/.vitepress/build-system/src/eslint.mjs deleted file mode 100644 index ed193b58b..000000000 --- a/docs/.vitepress/build-system/src/eslint.mjs +++ /dev/null @@ -1,8 +0,0 @@ -// @ts-nocheck -/* eslint-disable unicorn/prefer-export-from -- exporting as named and default is less duplication without `export…from` */ - -import { Linter } from '../../../../node_modules/eslint/lib/linter/linter.js' -import SourceCode from '../../../../node_modules/eslint/lib/source-code/source-code.js' - -export { Linter, SourceCode } -export default { Linter, SourceCode } diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index afa635d7e..7d198d588 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -3,6 +3,7 @@ import { defineConfig } from 'vitepress' import path from 'pathe' import { fileURLToPath } from 'url' import { viteCommonjs, vitePluginRequireResolve } from './vite-plugin.mjs' +import eslint4b, { requireESLintUseAtYourOwnRisk4b } from 'vite-plugin-eslint4b' // Pre-build cjs packages that cannot be bundled well. import './build-system/build.mjs' @@ -142,24 +143,30 @@ export default async () => { vite: { publicDir: path.resolve(dirname, './public'), - plugins: [vitePluginRequireResolve(), viteCommonjs()], + plugins: [ + vitePluginRequireResolve(), + viteCommonjs(), + eslint4b() as any, + requireESLintUseAtYourOwnRisk4b() + ], resolve: { alias: { - 'eslint/use-at-your-own-risk': path.join( + 'vue-eslint-parser': path.join( + dirname, + './build-system/shim/vue-eslint-parser.mjs' + ), + '@typescript-eslint/parser': path.join( dirname, - './build-system/shim/eslint/use-at-your-own-risk.mjs' + './build-system/shim/@typescript-eslint/parser.mjs' ), - eslint: path.join(dirname, './build-system/shim/eslint.mjs'), - assert: path.join(dirname, './build-system/shim/assert.mjs'), - path: path.join(dirname, './build-system/shim/path.mjs'), tslib: path.join(dirname, '../../node_modules/tslib/tslib.es6.js'), - esquery: path.join(dirname, './build-system/shim/esquery.mjs'), - globby: path.join(dirname, './build-system/shim/globby.mjs') + globby: path.join(dirname, './build-system/shim/empty.mjs'), + 'fast-glob': path.join(dirname, './build-system/shim/empty.mjs'), + module: path.join(dirname, './build-system/shim/empty.mjs') } }, define: { - 'process.env.NODE_DEBUG': 'false', 'require.cache': '{}' } }, diff --git a/docs/.vitepress/theme/components/eslint-code-block.vue b/docs/.vitepress/theme/components/eslint-code-block.vue index 77d4fd7cf..12cd1ff8b 100644 --- a/docs/.vitepress/theme/components/eslint-code-block.vue +++ b/docs/.vitepress/theme/components/eslint-code-block.vue @@ -8,8 +8,6 @@ class="eslint-code-block" :filename="filename" :language="language" - :preprocess="preprocess" - :postprocess="postprocess" dark :format="format" :fix="fix" @@ -20,8 +18,6 @@