Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ yarn-error.log
/docs/.vitepress/cache
typings/eslint/lib/rules
eslint-typegen.d.ts
dist
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/components/eslint-code-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const MD_LINKS_FOR_DOCS = {
export default typegen([
{
ignores: [
'dist',
'.nyc_output',
'coverage',
'node_modules',
Expand Down
3 changes: 0 additions & 3 deletions lib/meta.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { name, version } from '../package.json' with { type: 'json' }

export { name, version }
72 changes: 28 additions & 44 deletions lib/processor.js → lib/processor.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
*/
'use strict'
import type { Linter } from 'eslint'

/**
* @typedef {import('eslint').Linter.LintMessage} LintMessage
*/
/**
* @typedef {object} GroupState
* @property {Set<string>} GroupState.disableAllKeys
* @property {Map<string, string[]>} GroupState.disableRuleKeys
*/
type LintMessage = Linter.LintMessage

interface GroupState {
disableAllKeys: Set<string>
disableRuleKeys: Map<string, string[]>
}

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<string>(),
disableRuleKeys: new Map<string, string[]>()
} satisfies GroupState,
line: {
disableAllKeys: new Set(),
disableRuleKeys: new Map()
}
disableAllKeys: new Set<string>(),
disableRuleKeys: new Map<string, string[]>()
} satisfies GroupState
}
/** @type {string[]} */
const usedDisableDirectiveKeys = []
/** @type {Map<string,LintMessage>} */
const unusedDisableDirectiveReports = new Map()
const usedDisableDirectiveKeys: string[] = []
const unusedDisableDirectiveReports = new Map<string, LintMessage>()

// Filter messages which are in disabled area.
const filteredMessages = messages[0].filter((message) => {
Expand Down Expand Up @@ -139,12 +128,11 @@ module.exports = {
meta: require('./meta')
}

/**
* @param {Map<string, string[]>} 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)
Expand All @@ -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
Expand All @@ -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
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "node16",
"moduleResolution": "Node16",
"target": "esnext",
"module": "preserve",
"moduleResolution": "bundler",
"lib": ["es2020"],
"allowJs": true,
"checkJs": true,
Expand All @@ -17,6 +17,8 @@
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"baseUrl": ".",
"paths": {
"*": ["typings/*"]
Expand Down
11 changes: 11 additions & 0 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -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
})
Loading