-
Notifications
You must be signed in to change notification settings - Fork 69
Enabling typescript-eslint typed linting #499
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
Comments
While i do agree that due to performance reasons this feature can/maybe should remain disabled by default, having the option to enable it is essential, especially so when even something like this: "@typescript-eslint/strict-boolean-expressions": [
"warn",
{
allowString: false,
allowNumber: false,
allowNullableObject: false,
},
] requires it. I couldn't find a way to enable it currently so if there is, i would appreciate it. |
I was able to manually enable typed linting with the following configuration: // @ts-check
import eslint from '@eslint/js'
import pluginTs from '@typescript-eslint/eslint-plugin'
import parserTs from '@typescript-eslint/parser'
import vueParser from 'vue-eslint-parser'
import tseslint from 'typescript-eslint'
import withNuxt from './.nuxt/eslint.config.mjs'
export default withNuxt()
// @ts-ignore
.replace('nuxt/typescript/setup', {
name: 'nuxt/typescript/setup',
plugins: { '@typescript-eslint': pluginTs },
})
.replace('nuxt/typescript/rules', {
name: 'nuxt/typescript/rules',
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.vue'],
languageOptions: {
parser: vueParser,
parserOptions: {
parser: parserTs,
sourceType: 'module',
extraFileExtensions: ['.vue'],
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
...tseslint.config(eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked)
.map(c => c.rules).reduce((a, b) => ({ ...a, ...b }), {}),
// add your custom rules here
'no-console': 'warn',
'@typescript-eslint/consistent-type-imports': ['error', {
disallowTypeAnnotations: false,
prefer: 'type-imports',
}],
'@typescript-eslint/no-import-type-side-effects': 'error',
},
}) I hope this helps anyone looking to enable typed linting manually. |
@sumomo015 do you know how to enable parsing of jsx withing script tags as well with your configuration? |
Hi @zachnicoll, I'm not very familiar with using JSX, so I'm not quite sure how to enable parsing within script tags. However, this configuration might be useful: https://eslint.vuejs.org/user-guide/#using-jsx |
@sumomo015 There is a much simpler way. You can use import {
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'
import { withNuxt } from './.nuxt/eslint.config.mjs'
const config = defineConfigWithVueTs([
// Any other config
vueTsConfigs.recommendedTypeChecked,
])
export default withNuxt().prepend(...config) |
@aparajita Thanks for the example! UPDATE: Figured it out.. Needed to have this in
However, this has the unfortunate side effect of disabling much of what I used it exactly, but I'm getting an error (using the latest 1.3.0):
I don't have Any ideas? |
Describe the feature
Currently,
@nuxt/eslint
only enables rules of non-typechecked configs (recommended
/strict
) fromtypescript-eslint
. In addition to these,typescript-eslint
also provides advanced rules that depend on TypeScript's type checking API-s which are available viarecommended-type-checked
andstrict-type-checked
configs (see https://typescript-eslint.io/getting-started/typed-linting and https://typescript-eslint.io/rules/?=typeInformation).There are some performance concerns when it comes to naively enabling these configs, namely specifying
project
orprojectService
inparserOptions
, a prerequisite, can slow down linting speed of a medium sized project from few seconds to several minutes. It is uncertain at the moment whether these slowdowns are unique to this project, Vue or caused by something else.I think the main question I have is whether
@nuxt/eslint
would be willing to adopt these configs by default provided that the linting performance bottlenecks are identified. If they deem unsolvable to a satisfactory level, could optionally opting into them made easier for cases such as a CI step, where we can typically afford to spend more time?Additional information
Final checks
The text was updated successfully, but these errors were encountered: