-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vue-eslint-parser and typescript-eslint problems #104
Comments
Thank you for organizing information.
If this method solves the problem, I think it's the simplest change.
I don't think we can use the ESLint processors. |
My English is poor. If you don't understand what do I talk about, maybe I can ask for help. 😅
I will try again about this solution, and send a PR.
In the long run, we hope that the template can get the type information and rules. |
Are there any information, progress or ideas for the problem with the |
@ota-meshi Even after #116, there is no way to only enable typescript rules for |
I know it. |
I changed {
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": {
"ts": "@typescript-eslint/parser",
"<template>": "espree"
}
}
} If performance improves, I think it's a useful workaround for many. |
@ota-meshi I tried your patch and it made a huge difference! Before (~10 seconds): $ npx eslint --debug --fix frontend-next/src/components/connection/filters/app-filter.vue
...
eslint:cli-engine Lint .../frontend-next/src/components/connection/filters/app-filter.vue +0ms
eslint:linter Linting code for .../frontend-next/src/components/connection/filters/app-filter.vue (pass 1) +0ms
eslint:linter Verify +0ms
eslint:linter With ConfigArray: .../frontend-next/src/components/connection/filters/app-filter.vue +0ms
eslint:linter Apply the processor: 'vue/.vue' +0ms
eslint:linter A code block was found: '(unnamed)' +1ms
eslint:linter Generating fixed text for .../frontend-next/src/components/connection/filters/app-filter.vue (pass 1) +9s
...
.../frontend-next/src/components/connection/filters/app-filter.vue
108:22 warning The "update:value" event has been triggered but not declared on `emits` option vue/require-explicit-emits After (~instant): $ npx eslint --debug --fix frontend-next/src/components/connection/filters/app-filter.vue
...
eslint:cli-engine Lint .../frontend-next/src/components/connection/filters/app-filter.vue +0ms
eslint:linter Linting code for .../frontend-next/src/components/connection/filters/app-filter.vue (pass 1) +0ms
eslint:linter Verify +0ms
eslint:linter With ConfigArray: .../frontend-next/src/components/connection/filters/app-filter.vue +1ms
eslint:linter Apply the processor: 'vue/.vue' +0ms
eslint:linter A code block was found: '(unnamed)' +0ms
eslint:traverser Unknown node type "ChainExpression": Estimated visitor keys ["type","start","end","loc","range","expression"] +0ms
eslint:linter Generating fixed text for .../frontend-next/src/components/connection/filters/app-filter.vue (pass 1) +135ms
...
.../frontend-next/src/components/connection/filters/app-filter.vue
108:22 warning The "update:value" event has been triggered but not declared on `emits` option vue/require-explicit-emits Produced same lint warning both times so reassuring. Is |
how to set different parser options for each parserOptions.parser ? @ota-meshi |
There is no way to do that. |
@ota-meshi Thank you for the help. Test result: Project 1
Project 2
The effect is remarkable. |
No method other than hacking |
I have an issue with this, if a vue file does not contain at least one TS script, the following error occurs:
Vue file: <template>
<div class="view" />
</template> Adding Reproduction repo: https://github.com/MatthiasKunnen/eslint-plugin-vue-ts-script |
Then you have to set |
I did. The first code block in my comment is a quote, not my actual config. My config is: {
parser: 'vue-eslint-parser',
parserOptions: {
parser: {
'<template>': 'espree',
js: 'espree',
ts: '@typescript-eslint/parser',
},
project: ['./tsconfig.json'],
extraFileExtensions: ['.vue'],
},
} |
In fact,
|
I already tried that before. The problem is not with the js parser setting. With or without it, set to Try out this repository: https://github.com/MatthiasKunnen/eslint-plugin-vue-ts-script. |
of course you have to set the lang attribute. If it is omitted, the build tool also can not process your vue sfc written with ts. |
@lovetingyuan, have you even looked at the linked repository? Please refrain from further replies with irrelevant information which cause unnecessary notifications and time waste for subscribers to this issue. |
This config also works on our project (even if we had to keep that under an override for |
that's exactly what I have, but still need to override it for .ts files to get it working correctly. |
I'm currently struggling to get linting to work on my Laravel - Vue2 project with JavaScript and TypeScript. For debugging I created this small project, but I stumble from one issue to another. First it seemed like I can't get the fragmented parser option, introduced in typescript-eslint/typescript-eslint#1180 to work, then I find typescript-eslint @TYPED_LINTING.md and now I'm stuck at:
I've added those files to the It it not at all clear to me, how |
Scratch that. It is probably the missing |
trash for vue3 ts lint。。。 |
I got |
…s/vue-eslint-parser#104 (comment) @ .eslintrc.cjs * re-order `overrides` to specify `settings.import/resolver.vite` over `*.vue`, `settings.import/resolver.typescript` over `*.ts` & rules over `.eslintrc.cjs`, * `eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call` @ main.ts * `eslint-disable` @ stats.js * fix the return type of `_.defaultsDeep()` is `any` @ `useQueryForm.fillParamDefaultValue()` - `shims-vue.d.ts` following vuejs/vue-eslint-parser#104 (comment) $ yarn add -D typescript-eslint-parser-for-extra-files @ fe
I dont know if this issue is the right place, but I want to make it popular because I sinked in around 2h of try and error for this.
|
One additional hurdle that I haven't seen mentioned yet: |
The docs are also wrong/outdated when it comes to flat config, it does not allow a "parser" key in language options, i.e. languageOptions: {
ecmaVersion: 5,
sourceType: "script",
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: [".vue"],
projectService: true,
},
}, fails with ConfigError: Config (unnamed): Key "languageOptions": Key "parser": Expected object with parse() or parseForESLint() method. |
@Stanzilla use imports instead of strings. import tsParser from '@typescript-eslint/parser';
import vueParser from 'vue-eslint-parser';
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
parser: vueParser,
parserOptions: {
parser: tsParser,
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: [".vue"],
projectService: true,
},
}, |
that gives me
|
@Stanzilla @ehoogeveen-medweb maybe this issue I opened is relevant? typescript-eslint/typescript-eslint#9205 I (re)discovered a bug in v7 where extra file extensions aren't forwarded to tsserver. It was already fixed in rc-v8 when I reported. This was the main headache for me with vue files not working with project services. Vue files were assigned to an inferred project with default compiler options instead of whats in my tsconfigs. Also, depending, on the complexity of your tsconfigs, extends may not be getting processed. If your default project extends from a base tsconfig with the compiler options needed to resolve types, they are never read. I have a v7 example showing an imported png resolving to any (not reading compilerOptions.types due to inferred program) that I was able to fix with a patch. The other issue still exists in v8. My v8 example is slightly different but could result in the same problem. By keeping enough options in the default tsconfig to build and moving only the types option to the base tsconfig, the png should also fail to resolve to anything but any. So depending on your setup it may be one or both of these bugs causing issues. v7 https://github.com/higherorderfunctor/example-typescript-eslint-bug/blob/main/eslint.config.js v8 https://github.com/higherorderfunctor/example-typescript-eslint-bug/blob/rc-v8/eslint.config.js |
@Stanzilla try run eslint with env var since passing languageOptions: {
parser: vueParser,
parserOptions: {
parser: tsParser,
+ allowAutomaticSingleRunInference: false,
+ disallowAutomaticSingleRunInference: true,
}
} won't work as it's not going to forward them as vue-eslint-parser/src/common/parser-options.ts Lines 49 to 50 in b0e0ccc
|
…@typescript-eslint/parser. The file was not found in any of the provided program instance(s):` by vuejs/vue-eslint-parser#104 (comment) * reset `languageOptions.parserOptions.ecmaVersion` to `latest` as it's set to `2018` by `pluginImportX.configs.recommended` - rules from `@typescript-eslint` for file `eslint.config.js` * simplify the importing of `vite.config.ts` * ignore files generated by yarn - rule `@typescript-eslint/no-throw-literal`: typescript-eslint/typescript-eslint#9083 @ eslint.config.js $ yarn eslint --fix @ fe
…@typescript-eslint/parser. The file was not found in any of the provided program instance(s):` by vuejs/vue-eslint-parser#104 (comment) * reset `languageOptions.parserOptions.ecmaVersion` to `latest` as it's set to `2018` by `pluginImportX.configs.recommended` - rules from `@typescript-eslint` for file `eslint.config.js` * simplify the importing of `vite.config.ts` * ignore files generated by yarn - rule `@typescript-eslint/no-throw-literal`: typescript-eslint/typescript-eslint#9083 @ eslint.config.js $ yarn eslint --fix @ fe
…@typescript-eslint/parser. The file was not found in any of the provided program instance(s):` by vuejs/vue-eslint-parser#104 (comment) * reset `languageOptions.parserOptions.ecmaVersion` to `latest` as it's set to `2018` by `pluginImportX.configs.recommended` - rules from `@typescript-eslint` for file `eslint.config.js` * simplify the importing of `vite.config.ts` * ignore files generated by yarn - rule `@typescript-eslint/no-throw-literal`: typescript-eslint/typescript-eslint#9083 @ eslint.config.js $ yarn eslint --fix @ fe
Thanks, that helps a bit! |
1 similar comment
Thanks, that helps a bit! |
I have this now which works fairly well: import pluginVue from "eslint-plugin-vue";
import unocss from "@unocss/eslint-config/flat";
import eslint from "@eslint/js";
import tsEslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";
import vueParser from "vue-eslint-parser";
export default [
eslint.configs.recommended,
...tsEslint.configs.recommendedTypeChecked,
...pluginVue.configs["flat/recommended"],
unocss,
{
languageOptions: {
parser: vueParser,
parserOptions: {
parser: tsParser,
sourceType: "module",
extraFileExtensions: [".vue"],
project: true,
},
},
},
{
ignores: [
"dist",
"node_modules",
"dist_electron",
"dist-electron",
"release",
"index.html",
"tools/**/*.js",
"uno.config.ts",
"vite.config.ts",
"*.d.ts",
],
rules: {
"no-console": "off",
"no-undef": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-implicit-any": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/require-await": "off",
"vue/multi-word-component-names": "off",
"vue/component-tags-order": [
"error",
{
order: [["script", "template"], "style"],
},
],
"vue/html-self-closing": "off",
"vue/html-indent": "off",
"vue/html-closing-bracket-newline": "off",
"vue/singleline-html-element-content-newline": "off",
},
},
]; |
I use a vuetify or quasar starter with typescript and script setup. It just works. |
Thanks. While this workaround works, it significantly impacts performance, increasing the time from 2 minutes to 16 minutes. |
typescript-eslint/typescript-eslint#8138 |
running into this problem myself (over 1k |
Reason: typescript-eslint/typescript-eslint#2865 (comment)
Hi, I'm using
vue-eslint-parser
andtypescript-eslint
in company project.At the same time, I also help to contribute
typescript-eslint
project for fixing vue problems.This problems are only happens when using type rules in
typescript-eslint
.You need to add
parserOptions.project
in project to enable it.https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md
There are two main issues:
performance issue
issues: #65, typescript-eslint/typescript-eslint#1180
The problem is that
vue-eslint-parser
is designed with the AST not type information.The
vue-eslint-parser
will split code frame from template to@typescript-eslint/parser
.typescript-eslint/typescript-eslint#1180 (comment)
Typescript program need to parse full project for generate type information.
When parsing code frame, typescript program will reparse file AST and rebuild type information in project.
The
vue-eslint-parser
will pass more code frames and same file path in single Vue SFC.Possible solutions:
parserOptions.project
to close get type information when pass code frame.Ref: Add fragment options to lint code fragment for Vue SFC performance typescript-eslint/typescript-eslint#1180 (comment)
[no-unsafe-*] rules
issues: typescript-eslint/typescript-eslint#2865
Strictly speaking, it isn't a problem with this project.
The typescript program can't parse Vue SFC file directly.
You may think it's strange, but why is it working now?
Because
@typescript-eslint/parser
will prioritize the content delivered from ESLint.Typescript program will update by ESLint content not same as typescript program read.
But this problem is happens when ESLint not send file content and content from typescript program reading.
Example:
This problem will also have in
<script setup>
RFC.Possible solutions:
HelloWorld.vue
content.HelloWorld.vue.ts
file.Maybe we need a common project for hacking typescript program.
Thanks for watching. Have a good day!
The text was updated successfully, but these errors were encountered: