diff --git a/.gitignore b/.gitignore index d6fadf92c..5a7a63a56 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ yarn-error.log /docs/.vitepress/cache typings/eslint/lib/rules eslint-typegen.d.ts +dist diff --git a/docs/.vitepress/theme/components/eslint-code-block.vue b/docs/.vitepress/theme/components/eslint-code-block.vue index 12cd1ff8b..29d7cf0eb 100644 --- a/docs/.vitepress/theme/components/eslint-code-block.vue +++ b/docs/.vitepress/theme/components/eslint-code-block.vue @@ -142,7 +142,7 @@ export default { this.height = `${Math.max(120, 20 * (1 + lines))}px` // Load linter. const [plugin, { Linter }, vueEslintParser, globals] = await Promise.all([ - import('../../../..'), + import('../../../../lib/index'), import('eslint'), import('vue-eslint-parser'), import('globals') diff --git a/eslint.config.mjs b/eslint.config.mjs index 0fe41f792..e30b18a35 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -49,6 +49,7 @@ const MD_LINKS_FOR_DOCS = { export default typegen([ { ignores: [ + 'dist', '.nyc_output', 'coverage', 'node_modules', diff --git a/lib/meta.js b/lib/meta.js deleted file mode 100644 index d70069950..000000000 --- a/lib/meta.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' -const { name, version } = require('../package.json') -module.exports = { name, version } diff --git a/lib/meta.ts b/lib/meta.ts new file mode 100644 index 000000000..f5e106e02 --- /dev/null +++ b/lib/meta.ts @@ -0,0 +1,3 @@ +import { name, version } from '../package.json' with { type: 'json' } + +export { name, version } diff --git a/lib/processor.js b/lib/processor.ts similarity index 74% rename from lib/processor.js rename to lib/processor.ts index b7268fab9..e95e31d5d 100644 --- a/lib/processor.js +++ b/lib/processor.ts @@ -1,44 +1,33 @@ /** * @author Toru Nagashima */ -'use strict' +import type { Linter } from 'eslint' -/** - * @typedef {import('eslint').Linter.LintMessage} LintMessage - */ -/** - * @typedef {object} GroupState - * @property {Set} GroupState.disableAllKeys - * @property {Map} GroupState.disableRuleKeys - */ +type LintMessage = Linter.LintMessage + +interface GroupState { + disableAllKeys: Set + disableRuleKeys: Map +} -module.exports = { - /** @param {string} code */ - preprocess(code) { +export default { + preprocess(code: string): string[] { return [code] }, - /** - * @param {LintMessage[][]} messages - * @returns {LintMessage[]} - */ - postprocess(messages) { + postprocess(messages: LintMessage[][]): LintMessage[] { const state = { - /** @type {GroupState} */ block: { - disableAllKeys: new Set(), - disableRuleKeys: new Map() - }, - /** @type {GroupState} */ + disableAllKeys: new Set(), + disableRuleKeys: new Map() + } satisfies GroupState, line: { - disableAllKeys: new Set(), - disableRuleKeys: new Map() - } + disableAllKeys: new Set(), + disableRuleKeys: new Map() + } satisfies GroupState } - /** @type {string[]} */ - const usedDisableDirectiveKeys = [] - /** @type {Map} */ - const unusedDisableDirectiveReports = new Map() + const usedDisableDirectiveKeys: string[] = [] + const unusedDisableDirectiveReports = new Map() // Filter messages which are in disabled area. const filteredMessages = messages[0].filter((message) => { @@ -139,12 +128,11 @@ module.exports = { meta: require('./meta') } -/** - * @param {Map} disableRuleKeys - * @param {string} rule - * @param {string} key - */ -function addDisableRule(disableRuleKeys, rule, key) { +function addDisableRule( + disableRuleKeys: GroupState['disableRuleKeys'], + rule: string, + key: string +): void { let keys = disableRuleKeys.get(rule) if (keys) { keys.push(key) @@ -154,11 +142,7 @@ function addDisableRule(disableRuleKeys, rule, key) { } } -/** - * @param {LintMessage} message - * @returns {string} message key - */ -function messageToKey(message) { +function messageToKey(message: LintMessage): string { return `line:${message.line},column${ // -1 because +1 by ESLint's `report-translator`. message.column - 1 @@ -167,11 +151,11 @@ function messageToKey(message) { /** * Compares the locations of two objects in a source file - * @param {Position} itemA The first object - * @param {Position} itemB The second object - * @returns {number} A value less than 1 if itemA appears before itemB in the source file, greater than 1 if + * @param itemA The first object + * @param itemB The second object + * @returns A value less than 1 if itemA appears before itemB in the source file, greater than 1 if * itemA appears after itemB in the source file, or 0 if itemA and itemB have the same location. */ -function compareLocations(itemA, itemB) { +function compareLocations(itemA: Position, itemB: Position): number { return itemA.line - itemB.line || itemA.column - itemB.column } diff --git a/package.json b/package.json index d1e693690..f0c438917 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "eslint-plugin-vue", "version": "10.4.0", "description": "Official ESLint plugin for Vue.js", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "new": "node tools/new-rule.js", "start": "npm run test:base -- --watch --growl", @@ -22,15 +22,17 @@ "update": "node ./tools/update.js", "update-resources": "node ./tools/update-resources.js", "typegen": "node ./tools/generate-typegen.mjs", + "build": "tsdown", "docs:watch": "vitepress dev docs", "predocs:build": "npm run update", "docs:build": "vitepress build docs", "generate:version": "env-cmd -e version npm run update && npm run lint -- --fix", "changeset:version": "changeset version && npm run generate:version && git add --all", - "changeset:publish": "npm run typegen && changeset publish" + "changeset:publish": "npm run typegen && changeset publish", + "prepublishOnly": "npm run build" }, "files": [ - "lib" + "dist" ], "homepage": "https://eslint.vuejs.org", "keywords": [ @@ -115,6 +117,7 @@ "markdownlint-cli": "^0.42.0", "pathe": "^1.1.2", "prettier": "^3.3.3", + "tsdown": "^0.14.1", "typescript": "^5.7.2", "vite-plugin-eslint4b": "^0.5.1", "vitepress": "^1.4.1", diff --git a/tsconfig.json b/tsconfig.json index b488a6b93..a8517c036 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2019", - "module": "node16", - "moduleResolution": "Node16", + "target": "esnext", + "module": "preserve", + "moduleResolution": "bundler", "lib": ["es2020"], "allowJs": true, "checkJs": true, @@ -17,6 +17,8 @@ "noFallthroughCasesInSwitch": true, "esModuleInterop": true, "resolveJsonModule": true, + "isolatedModules": true, + "noUncheckedSideEffectImports": true, "baseUrl": ".", "paths": { "*": ["typings/*"] diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 000000000..06ef6e55f --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from 'tsdown' + +export default defineConfig({ + target: 'node18', + entry: ['lib/index.js'], + format: ['cjs'], + copy: ['lib/index.d.ts'], + dts: false, + external: ['typescript'], + unbundle: true +})