-
Notifications
You must be signed in to change notification settings - Fork 445
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
eslint: @typescript-eslint error when add some rules #123
Comments
This is kinda complicated… I've got a working configuration:
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript/recommended",
"@vue/eslint-config-prettier",
],
rules: {
"@typescript-eslint/prefer-optional-chain": "error",
},
parserOptions: {
parser: "@typescript-eslint/parser",
project: "./tsconfig.json",
},
overrides: [
{
files: ["vite.config.ts", ".eslintrc.cjs"],
parserOptions: {
parser: "@typescript-eslint/parser",
project: "./tsconfig.config.json",
},
},
],
}; And add The trick here is that we can only have a single And since we use solution-style tsconfigs in the project, some files in the project aren't covered by the root |
It works, thanks! |
It seems <script lang="tsx">
import { defineComponent } from "vue";
export default defineComponent({
render() {
return <div></div>; // Parsing error: Type expected.
},
});
</script> |
Yeah, currently it seems not possible to use
|
So it's impossible to make everything works for now? |
I'm afraid so 🙁 |
It was the limitation of "parserOptions": {
"parser": {
"ts": "@typescript-eslint/parser",
"<template>": "espree"
}
} |
I'm not sure. Because TypeScript never supports custom file extensions well. For example, to make TypeScript work well with Maybe |
What a pity, disable rule Should I leave this issue open? |
Yeah, let's leave it open until I find a better place to document this limitation. |
Oh I forgot to mention that I used to use the old version /* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/essential',
'eslint:recommended',
'@vue/typescript/recommended', // this line was changed
'@vue/eslint-config-prettier',
],
rules: {
'@typescript-eslint/prefer-optional-chain': 'error',
},
} |
It might be caused by typescript-eslint/typescript-eslint#4430 that triggers an undefined behavior in |
FYI, I just created a By default it only supports I plan to do similar refactors in |
There are many other rules require |
This isn't an exact solution for vue.js, but for anyone coming here from search looking to solve this problem for ts-node or node based typescript, I was able to solve the "You have used a rule which requires parserServices to be generated" error as follows (local setup: node 18-lts): Add Then in your {
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:eslint-comments/recommended",
"plugin:jsonc/recommended-with-jsonc"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["unicorn","@typescript-eslint"],
"settings": {
"import/resolver": {
"node": { "extensions": [".js", ".mjs", ".ts", ".d.ts"] },
"typescript": {
"project": "./tsconfig.json"
}
}
},
"rules" : { ... }
} This does not follow any instructions or guides I have found via Google, and yet it is the only solution I've found that actually works. Your mileage may vary, but this worked for me. Also, remember to restart eslint after making this change ( |
just another fyi, if you have this working but the error crops up anyway, make sure that you have a |
Create vue 2 project using following config
npm install
add rules inside
.eslintrc.cjs
npm run lint
terminal error
FYI.
Adding
parserOptions: { project: ["tsconfig.json"] }
to.eslintrc.cjs
won't help.Maybe caused by
eslint-plugin-vue
or@typescript-eslint
The text was updated successfully, but these errors were encountered: