-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
Using volar
together with @typescript-eslint/parser
for type checking rules to understand SFC component types
#2189
Comments
Can you provide this project? It can help me quickly understand, thanks! |
Yeah sure!
It would be awesome if it would work with Volar! |
Is integrating .eslintrc.cjs: require('@rushstack/eslint-patch/modern-module-resolution')
const parser = require('@typescript-eslint/parser')
const ts = require('typescript')
const vueTsc = require('vue-tsc/out/proxy')
const tsProgram = parser.createProgram('./tsconfig.json', __dirname)
module.exports = {
root: true,
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'@vue/eslint-config-typescript/recommended',
'@vue/eslint-config-prettier',
],
parser: 'vue-eslint-parser',
parserOptions: {
tsconfigRootDir: __dirname,
},
overrides: [
...
{
files: ['*.ts', '*.mts'],
extends: [
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
],
parserOptions: {
// project: ['./tsconfig.json'],
program: vueTsc.createProgramProxy({ // <-- it would be so cool, if this would work!
rootNames: ['./src/main.ts'], // tsProgram.getSourceFiles().map((sf) => sf.fileName) ?
options: compilerOptions,
host: ts.createCompilerHost(compilerOptions),
}),
},
},
],
} |
It seems that ESLint TypeScript document incorrect, you should use const { createComponentMetaChecker } = require('vue-component-meta')
const tsConfig = require.resolve('./tsconfig.json')
const checker = createComponentMetaChecker(tsConfig)
const program = checker.__internal__.tsLs.getProgram()
// ...
parserOptions: {
programs: [program]
}, |
Now you can use https://github.com/johnsoncodehk/volar-plugins/tree/master/packages/eslint with takeover mode, I will write more information in Discussions for it. Please note that you need to remove |
Thanks for getting back with this elegant solution! I have tried it with https://github.com/DrJume/vue-volar-eslint and it seems to work (
I dug around in the code with the help of debug output (
Inside but it returns
But running So it seems to work, and I think the error is caused by Volar for having an incompatible interface with |
It still doesn't work completely. The issue stated above still exists. Can you reopen this issue? |
That issue cannot be solved here. It belongs to eslint-plugin-vue. For progress updates, please follow DrJume/vue-volar-eslint#1. |
I'm using @typescript-eslint in a TS project with type checking enabled (https://typescript-eslint.io/linting/configs#recommended-requiring-type-checking).
This allows eslint to understand typescript types and make suggestions.
Sadly Vue SFC files are interpreted with type
any
, they are not correctly loaded.I found an option for @typescript-eslint/parser to specify a TS
program
in the options: (https://typescript-eslint.io/architecture/parser/#program). So it should be possible to pass the Volar proxy into @typescript-eslint/parser. This should allow eslint to also run type linting for Vue SFCs.But sadly I didn't get it to work.
This is my eslint config override for '*.vue' files:
I also tried to add the
typescript-vue-plugin
as a typescript plugin, to get SFCs to work with eslint type checking, but it also didn't work...The text was updated successfully, but these errors were encountered: