Skip to content

Commit

Permalink
fix: Add custom ts parser for vue projects (#136)
Browse files Browse the repository at this point in the history
This commit modifies the ESLint config generator to add a custom parser for TypeScript files when the language option is set to "typescript". This change is necessary to ensure proper linting of Vue files with TypeScript code.

refs: https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser

Signed-off-by: 唯然 <[email protected]>
  • Loading branch information
aladdin-add authored Jul 12, 2024
1 parent 916d876 commit 0098452
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
this.result.devDependencies.push("eslint-plugin-vue");
importContent += "import pluginVue from \"eslint-plugin-vue\";\n";
exportContent += " ...pluginVue.configs[\"flat/essential\"],\n";

// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
if (this.answers.language === "typescript") {
exportContent += " {files: [\"**/*.vue\"], languageOptions: {parserOptions: {parser: tseslint.parser}}},\n";
}
}

if (this.answers.framework === "react") {
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/problems-commonjs-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/problems-esm-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/problems-script-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/syntax-commonjs-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/syntax-esm-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default [
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/syntax-script-vue-typescript
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}},
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand Down

0 comments on commit 0098452

Please sign in to comment.