-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Linting a Vue SFC containing JSX throws a parsing error #150
Comments
I tried |
Thank you for posting this issue. I think it's a I think you need to stop using JSX in |
By the way, even if we change the extension virtually on the parser, parsing will fail because it is a file that does not actually exist. |
Would it be possible to do something like |
I'm not familiar with the API inside typescript so I don't know 😓 |
I'm not sure if this is a foolproof solution, but maybe it might be possible to do that at runtime using Maybe @johnsoncodehk (creator of |
I don't accept the patch approach PR because I don't think it's guaranteed. I think you'll need to ask the TypeScript team to add a guaranteed API if needed. |
You may be able to patch it personally by putting the following script in const ts = require('typescript')
const { ensureScriptKind } = ts
ts.ensureScriptKind = function (fileName, ...args) {
if (fileName.endsWith(".vue")) {
return ts.ScriptKind.TSX
}
return ensureScriptKind.call(this, fileName, ...args)
} |
You can try uses default settings
|
The following Vue SFC causes a lint error:
Repro: https://github.com/leonzalion/vue-eslint-plugin-jsx-bug
I did some debugging, and I think the problem has to do with the .vue file extension when the file is passed to
@typescript-eslint/parser
.This is the
parserOptions
configuration passed to@typescript-eslint/parser
at this line:vue-eslint-parser/src/script/index.ts
Line 555 in c476e7c
When I modified the JavaScript code and only changed the above parserOptions.filePath parameter from
app.vue
toapp.jsx
, the linter didn't throw any error.I then traced down the bug through the
@typescript-eslint/parser
code and I think it has to do with the following line: https://github.com/typescript-eslint/typescript-eslint/blob/5e794512bf124c39de76d4e2cf8a3d6cfb08f1a8/packages/typescript-estree/src/create-program/createWatchProgram.ts#L351I think this line causes TypeScript to try and infer the type of the file based on the file extension, and because the file extension in
.vue
(which TypeScript doesn't recognize), TypeScript treats the file as a.ts
file by default, causing the parsing to fail since the file is actually a JSX file.(Sidenote: when I tried changing that line to

ts.ScriptKind.TSX
, it gave me the following error:)When I modified the TypeScript compiler code and added a
case ".vue":
under this line, the lint then started working again (you can test this by runningnpx patch-package && npm lint
in the repro).As somebody who isn't really experienced with the internals of ESLint, I'm not exactly sure what the best way to fix this is, so please let me know what you think!
The text was updated successfully, but these errors were encountered: