N
Nuxt2mo ago
Mike

Using type aware `typescript-eslint` rules with nuxt eslint module

I'm trying to use the rule @typescript-eslint/no-unnecessary-condition. However when I add it to my eslint config, i get this error:
Oops! Something went wrong! :(

ESLint: 9.11.1

Error: Error while loading rule '@typescript-eslint/no-unnecessary-condition': You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://typescript-eslint.io/getting-started/typed-linting for enabling linting with type information.
Parser: (unknown)
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
Oops! Something went wrong! :(

ESLint: 9.11.1

Error: Error while loading rule '@typescript-eslint/no-unnecessary-condition': You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://typescript-eslint.io/getting-started/typed-linting for enabling linting with type information.
Parser: (unknown)
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
My eslint config looks like this:
import { createConfigForNuxt } from "@nuxt/eslint-config/flat"

export default createConfigForNuxt().append({
rules: {
"vue/multi-word-component-names": "off",
"vue/html-self-closing": "off", // Prettier handles this
"prefer-template": "error",
"vue/prefer-template": "error",
"vue/require-typed-ref": "error", // like noImplicitAny but for refs
"vue/prefer-true-attribute-shorthand": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"vue/v-bind-style": [
"error",
"shorthand",
{
sameNameShorthand: "always",
},
],
},
})
import { createConfigForNuxt } from "@nuxt/eslint-config/flat"

export default createConfigForNuxt().append({
rules: {
"vue/multi-word-component-names": "off",
"vue/html-self-closing": "off", // Prettier handles this
"prefer-template": "error",
"vue/prefer-template": "error",
"vue/require-typed-ref": "error", // like noImplicitAny but for refs
"vue/prefer-true-attribute-shorthand": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"vue/v-bind-style": [
"error",
"shorthand",
{
sameNameShorthand: "always",
},
],
},
})
I have tried prepending parserOptions like this:
import { createConfigForNuxt } from "@nuxt/eslint-config/flat"

export default createConfigForNuxt()
.prepend({
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
})
.append({
// same as before
})
import { createConfigForNuxt } from "@nuxt/eslint-config/flat"

export default createConfigForNuxt()
.prepend({
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
})
.append({
// same as before
})
So basically: How do I forward parserOptions to typescript-eslint/parser?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server