Skip to content

Commit 4cf87be

Browse files
2nofa11ota-meshiFloEdelmann
authored
feat: add TypeScript IntelliSense support with eslint-typegen (#2770)
Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com> Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent ebf6cb5 commit 4cf87be

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

.changeset/neat-swans-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": minor
3+
---
4+
5+
Add TypeScript IntelliSense support via [eslint-typegen](https://github.com/antfu/eslint-typegen)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ yarn-error.log
1313
/docs/.vitepress/.temp
1414
/docs/.vitepress/cache
1515
typings/eslint/lib/rules
16+
eslint-typegen.d.ts

eslint.config.js renamed to eslint.config.mjs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
'use strict'
1+
import globals from 'globals'
2+
import eslintPluginEslintPlugin from 'eslint-plugin-eslint-plugin/configs/all'
3+
import eslintPluginJsonc from 'eslint-plugin-jsonc'
4+
import eslintPluginNodeDependencies from 'eslint-plugin-node-dependencies'
5+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
6+
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
7+
import vueEslintParser from 'vue-eslint-parser'
8+
import noInvalidMeta from './eslint-internal-rules/no-invalid-meta.js'
9+
import noInvalidMetaDocsCategories from './eslint-internal-rules/no-invalid-meta-docs-categories.js'
10+
import requireEslintCommunity from './eslint-internal-rules/require-eslint-community.js'
211

3-
const globals = require('globals')
4-
const eslintPluginEslintPlugin = require('eslint-plugin-eslint-plugin/configs/all')
5-
const eslintPluginJsonc = require('eslint-plugin-jsonc')
6-
const eslintPluginNodeDependencies = require('eslint-plugin-node-dependencies')
7-
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended')
8-
const eslintPluginUnicorn = require('eslint-plugin-unicorn')
12+
// @ts-check
13+
/// <reference path="./eslint-typegen.d.ts" />
14+
import typegen from 'eslint-typegen'
915

10-
module.exports = [
16+
export default typegen([
1117
{
1218
ignores: [
1319
'.nyc_output',
@@ -33,9 +39,9 @@ module.exports = [
3339
plugins: {
3440
internal: {
3541
rules: {
36-
'no-invalid-meta': require('./eslint-internal-rules/no-invalid-meta'),
37-
'no-invalid-meta-docs-categories': require('./eslint-internal-rules/no-invalid-meta-docs-categories'),
38-
'require-eslint-community': require('./eslint-internal-rules/require-eslint-community')
42+
'no-invalid-meta': noInvalidMeta,
43+
'no-invalid-meta-docs-categories': noInvalidMetaDocsCategories,
44+
'require-eslint-community': requireEslintCommunity
3945
}
4046
}
4147
}
@@ -213,7 +219,7 @@ module.exports = [
213219
languageOptions: {
214220
ecmaVersion: 'latest',
215221
sourceType: 'module',
216-
parser: require('vue-eslint-parser')
222+
parser: vueEslintParser
217223
}
218224
},
219225
{
@@ -241,4 +247,4 @@ module.exports = [
241247
'prettier/prettier': 'off'
242248
}
243249
}
244-
]
250+
])

lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference path="./eslint-typegen.d.ts" />
12
import type { Linter } from 'eslint'
23

34
declare const vue: {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
"version": "npm run generate:version && git add .",
2222
"update": "node ./tools/update.js",
2323
"update-resources": "node ./tools/update-resources.js",
24+
"typegen": "node ./tools/generate-typegen.mjs",
2425
"docs:watch": "vitepress dev docs",
2526
"predocs:build": "npm run update",
2627
"docs:build": "vitepress build docs",
2728
"generate:version": "env-cmd -e version npm run update && npm run lint -- --fix",
2829
"changeset:version": "changeset version && npm run generate:version && git add --all",
29-
"changeset:publish": "changeset publish"
30+
"changeset:publish": "npm run typegen && changeset publish"
3031
},
3132
"files": [
3233
"lib"
@@ -98,6 +99,7 @@
9899
"eslint-plugin-prettier": "^5.2.1",
99100
"eslint-plugin-unicorn": "^56.0.0",
100101
"eslint-plugin-vue": "file:.",
102+
"eslint-typegen": "^2.2.0",
101103
"eslint-visitor-keys": "^4.2.0",
102104
"espree": "^10.4.0",
103105
"events": "^3.3.0",

tools/generate-typegen.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fs from 'node:fs/promises'
2+
import { pluginsToRulesDTS } from 'eslint-typegen/core'
3+
import plugin from '../lib/index.js'
4+
5+
const dts = await pluginsToRulesDTS({
6+
vue: plugin
7+
})
8+
9+
await fs.writeFile('lib/eslint-typegen.d.ts', dts)

0 commit comments

Comments
 (0)