Skip to content

Commit 3fbbc46

Browse files
committed
feat: use @vue/eslint-config-typescript 14.3 API & eslint.config.ts
`eslint.config.ts` support is unflagged in ESLint 9.18 and requires jiti https://eslint.org/blog/2025/01/eslint-v9.18.0-released/#stable-typescript-configuration-file-support
1 parent 193923a commit 3fbbc46

File tree

6 files changed

+107
-68
lines changed

6 files changed

+107
-68
lines changed

bin/create-eslint-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const lintCommand =
234234

235235
console.info(
236236
'\n' +
237-
`${bold(yellow('package.json'))} and ${bold(blue('eslint.config.js'))} have been updated.\n` +
237+
`${bold(yellow('package.json'))} and ${bold(blue(`eslint.config.${hasTypeScript ? 'ts' : 'js'}`))} have been updated.\n` +
238238
`Now please run ${bold(green(installCommand))} to re-install the dependencies.\n` +
239239
`Then you can run ${bold(green(lintCommand))} to lint your files.`,
240240
)

index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,13 @@ export default function createConfig({
2828
if (hasTypeScript) {
2929
// TODO: allowJs option
3030
fileExtensions.unshift('ts', 'mts', 'tsx')
31-
3231
additionalConfigs.unshift({
33-
devDependencies: pickDependencies(['@vue/eslint-config-typescript']),
34-
afterVuePlugin: [
35-
{
36-
importer:
37-
"import vueTsEslintConfig from '@vue/eslint-config-typescript'",
38-
// TODO: supportedScriptLangs
39-
content: '...vueTsEslintConfig(),',
40-
},
41-
],
32+
devDependencies: pickDependencies(['@vue/eslint-config-typescript', 'jiti']),
4233
})
4334
} else {
4435
fileExtensions.unshift('js', 'mjs', 'jsx')
4536
additionalConfigs.unshift({
4637
devDependencies: pickDependencies(['@eslint/js']),
47-
beforeVuePlugin: [
48-
{
49-
importer: "import js from '@eslint/js'",
50-
content: 'js.configs.recommended,',
51-
},
52-
],
5338
})
5439
}
5540

@@ -113,16 +98,24 @@ export default function createConfig({
11398
}
11499

115100
const files = {
116-
'eslint.config.js': renderEjsFile(
117-
'./templates/eslint.config.js.ejs',
118-
templateData,
119-
),
120101
'.editorconfig': renderEjsFile(
121102
'./templates/_editorconfig.ejs',
122103
templateData,
123104
),
124105
}
125106

107+
if (hasTypeScript) {
108+
files['eslint.config.ts'] = renderEjsFile(
109+
'./templates/eslint.config.ts.ejs',
110+
templateData,
111+
)
112+
} else {
113+
files['eslint.config.js'] = renderEjsFile(
114+
'./templates/eslint.config.js.ejs',
115+
templateData,
116+
)
117+
}
118+
126119
// .editorconfig & .prettierrc.json
127120
if (needsPrettier) {
128121
// Prettier recommends an explicit configuration file to let the editor know that it's used.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"eslint": "^9.18.0",
4747
"eslint-plugin-oxlint": "^0.15.6",
4848
"eslint-plugin-vue": "^9.32.0",
49+
"jiti": "^2.4.2",
4950
"npm-run-all2": "^7.0.2",
5051
"oxlint": "^0.15.6",
5152
"prettier": "^3.4.2",

pnpm-lock.yaml

Lines changed: 58 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/eslint.config.js.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<%_ for (const { importer } of configsBeforeVuePlugin) { _%>
22
<%- importer %>
33
<%_ } _%>
4+
import js from '@eslint/js'
45
import pluginVue from 'eslint-plugin-vue'
56
<%_ for (const { importer } of configsAfterVuePlugin) { _%>
67
<%- importer %>
@@ -20,6 +21,7 @@ export default [
2021
<%_ for (const { content } of configsBeforeVuePlugin) { _%>
2122
<%- content %><%# TODO: auto-indent if content's multi-line %>
2223
<%_ } _%>
24+
js.configs.recommended,
2325
...pluginVue.configs['flat/essential'],
2426
<%_ for (const { content } of configsAfterVuePlugin) { _%>
2527
<%- content %><%# TODO: auto-indent if content's multi-line %>

templates/eslint.config.ts.ejs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<%_ for (const { importer } of configsBeforeVuePlugin) { _%>
2+
<%- importer %>
3+
<%_ } _%>
4+
import pluginVue from 'eslint-plugin-vue'
5+
import {
6+
defineConfigWithVueTs,
7+
vueTsConfigs,
8+
} from '@vue/eslint-config-typescript'
9+
<%_ for (const { importer } of configsAfterVuePlugin) { _%>
10+
<%- importer %>
11+
<%_ } _%>
12+
13+
export default defineConfigWithVueTs(
14+
{
15+
name: 'app/files-to-lint',
16+
files: ['**/*.{<%= fileExtensions.join(',') %>}'],
17+
},
18+
19+
{
20+
name: 'app/files-to-ignore',
21+
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
22+
},
23+
24+
<%_ for (const { content } of configsBeforeVuePlugin) { _%>
25+
<%- content %><%# TODO: auto-indent if content's multi-line %>
26+
<%_ } _%>
27+
pluginVue.configs['flat/essential'],
28+
vueTsConfigs.recommended,
29+
<%_ for (const { content } of configsAfterVuePlugin) { _%>
30+
<%- content %><%# TODO: auto-indent if content's multi-line %>
31+
<%_ } _%>
32+
)

0 commit comments

Comments
 (0)