diff --git a/docs/.eslintrc.js b/docs/.eslintrc.js deleted file mode 100644 index 1ec3b7eae..000000000 --- a/docs/.eslintrc.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -module.exports = { - parserOptions: { - sourceType: 'module' - } -} diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 7d198d588..20ac9bff5 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -10,6 +10,7 @@ import './build-system/build.mjs' const dirname = path.dirname(fileURLToPath(import.meta.url)) +// eslint-disable-next-line unicorn/no-anonymous-default-export export default async () => { const rulesPath = '../../tools/lib/rules.js' // Avoid bundle const rules: typeof import('../../tools/lib/rules.js') = await import( @@ -87,12 +88,10 @@ export default async () => { ) return !exists }) - .map(({ ruleId, name }) => { - return { - text: ruleId, - link: `/rules/${name}` - } - }) + .map(({ ruleId, name }) => ({ + text: ruleId, + link: `/rules/${name}` + })) if (children.length === 0) { continue diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 757e63cab..34f6ee9b0 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -1,12 +1,10 @@ // @ts-expect-error -- Browser -if (typeof window !== 'undefined') { - if (typeof require === 'undefined') { - // @ts-expect-error -- Browser - ;(window as any).require = () => { - const e = new Error('require is not defined') - ;(e as any).code = 'MODULE_NOT_FOUND' - throw e - } +if (typeof window !== 'undefined' && typeof require === 'undefined') { + // @ts-expect-error -- Browser + ;(window as any).require = () => { + const e = new Error('require is not defined') + ;(e as any).code = 'MODULE_NOT_FOUND' + throw e } } // @ts-expect-error -- Cannot change `module` option diff --git a/docs/.vitepress/vite-plugin.mts b/docs/.vitepress/vite-plugin.mts index cd6811cb6..bd9c9090b 100644 --- a/docs/.vitepress/vite-plugin.mts +++ b/docs/.vitepress/vite-plugin.mts @@ -11,7 +11,7 @@ const libRoot = path.join(fileURLToPath(import.meta.url), '../../../lib') export function vitePluginRequireResolve(): Plugin { return { name: 'vite-plugin-require.resolve', - transform(code, id, _options) { + transform(code, id) { if (id.startsWith(libRoot)) { return code.replace(/require\.resolve/gu, '(function(){return 0})') } @@ -34,8 +34,9 @@ export function viteCommonjs(): Plugin { format: 'esm' }) return transformed.code - } catch (e) { - console.error('Transform error. base code:\n' + base, e) + } catch (error) { + // eslint-disable-next-line no-console + console.error(`Transform error. base code:\n${base}`, error) } return undefined } @@ -58,24 +59,26 @@ function transformRequire(code: string) { } let id = + // eslint-disable-next-line prefer-template '__' + moduleString.replace(/[^a-zA-Z0-9_$]+/gu, '_') + - Math.random().toString(32).substring(2) + Math.random().toString(32).slice(2) while (code.includes(id) || modules.has(id)) { - id += Math.random().toString(32).substring(2) + id += Math.random().toString(32).slice(2) } modules.set(id, moduleString) - return id + '()' + return `${id}()` } ) return ( + // eslint-disable-next-line prefer-template [...modules] - .map(([id, moduleString]) => { - return `import * as __temp_${id} from ${moduleString}; + .map( + ([id, moduleString]) => `import * as __temp_${id} from ${moduleString}; const ${id} = () => __temp_${id}.default || __temp_${id}; ` - }) + ) .join('') + ';\n' + replaced diff --git a/eslint.config.mjs b/eslint.config.mjs index 0fe41f792..044005f23 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,6 +7,8 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended' import eslintPluginUnicorn from 'eslint-plugin-unicorn' import eslintMarkdown from '@eslint/markdown' import eslintPluginMarkdownPreferences from 'eslint-plugin-markdown-preferences' +import eslintPluginTs from '@typescript-eslint/eslint-plugin' +import tsEslintParser from '@typescript-eslint/parser' import vueEslintParser from 'vue-eslint-parser' import noInvalidMeta from './eslint-internal-rules/no-invalid-meta.js' import noInvalidMetaDocsCategories from './eslint-internal-rules/no-invalid-meta-docs-categories.js' @@ -50,6 +52,7 @@ export default typegen([ { ignores: [ '.nyc_output', + 'eslint-typegen.d.ts', 'coverage', 'node_modules', '.changeset/**/*.md', @@ -78,7 +81,7 @@ export default typegen([ } }, ...defineConfig({ - files: ['**/*.js'], + files: ['**/*.{js,mjs,ts,mts}'], extends: [ eslintPluginEslintPlugin, eslintPluginUnicorn.configs['flat/recommended'] @@ -105,7 +108,21 @@ export default typegen([ }), { - files: ['**/*.js'], + name: 'typescript/setup', + files: ['**/*.{ts,mts}'], + languageOptions: { + parser: tsEslintParser, + parserOptions: { + sourceType: 'module' + } + }, + plugins: { + '@typescript-eslint': eslintPluginTs + } + }, + + { + files: ['**/*.{js,mjs,ts,mts}'], languageOptions: { ecmaVersion: 'latest', sourceType: 'commonjs', @@ -249,6 +266,35 @@ export default typegen([ 'internal/require-eslint-community': ['error'] } }, + + { + files: ['**/*.{mjs,ts,mts}'], + languageOptions: { + sourceType: 'module' + } + }, + + { + files: ['**/*.{ts,mts}'], + rules: { + ...eslintPluginTs.configs.strict.rules, + ...eslintPluginTs.configs['flat/eslint-recommended'].rules, + 'no-redeclare': 'off', + '@typescript-eslint/no-redeclare': 'error', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/triple-slash-reference': 'off', + '@typescript-eslint/unified-signatures': 'off', + '@typescript-eslint/ban-ts-comment': [ + 'error', + { + minimumDescriptionLength: 3 + } + ] + } + }, + { files: ['./**/*.vue'], languageOptions: { diff --git a/package.json b/package.json index 78a103cdf..4eccdd8e9 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@types/node": "^24.0.8", "@types/semver": "^7.5.8", "@types/xml-name-validator": "^4.0.3", + "@typescript-eslint/eslint-plugin": "^8.35.1", "@typescript-eslint/parser": "^8.35.1", "@typescript-eslint/types": "^8.35.1", "@vitest/coverage-v8": "^3.2.4", 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 3205dc74e..4297d3d56 100644 --- a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts @@ -351,7 +351,7 @@ export interface PrivateIdentifier extends HasParentNode { } export interface Literal extends HasParentNode { type: 'Literal' - value: string | boolean | null | number | RegExp | BigInt + value: string | boolean | null | number | RegExp | bigint raw: string regex?: { pattern: string diff --git a/vitest.config.mts b/vitest.config.mts index eeef751d6..be1e63448 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -1,11 +1,8 @@ +import { defineConfig } from 'vitest/config' -import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { - include: [ - 'tests/lib/**/*.js', - 'tests/integrations/**/*.js' - ], + include: ['tests/lib/**/*.js', 'tests/integrations/**/*.js'], exclude: [ '**/node_modules/**', '**/dist/**', @@ -18,15 +15,10 @@ export default defineConfig({ coverage: { provider: 'v8', include: ['lib/**/*.js'], - exclude: [ - 'tests/**', - 'dist/**', - 'tools/**', - 'node_modules/**' - ], + exclude: ['tests/**', 'dist/**', 'tools/**', 'node_modules/**'], reporter: ['text', 'lcov', 'json-summary', 'html'], all: true, reportsDirectory: './coverage' - }, - }, -}); + } + } +})