-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Limit TS rules to TS files #39
Comments
This enables XO’s config on TS files as well:
I don't see anything special about it here: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/eslint-recommended.ts |
That's weird. I don't see anything regarding extensions in the |
Weird indeed. Also confirmed with this repro: npm init -y
npm install eslint eslint-config-xo eslint-config-xo-typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
echo '// @ts-ignore' > index.ts
echo '{}' > tsconfig.json
echo '{"extends":["xo","xo-typescript"]}' > .eslintrc
npx eslint . Then this config produces:
Add that the plugin and run again: echo '{"extends":["plugin:@typescript-eslint/recommended","xo","xo-typescript"]}' > .eslintrc
npx eslint .
Then remove XO’s config: echo '{"extends":["plugin:@typescript-eslint/recommended"]}' > .eslintrc
npx eslint .
|
Worth an update of docs and config everywhere? typescript-eslint/typescript-eslint#3824 (comment) |
Sure |
I think I know why, and I think this config should follow suit: The rules are defined in an override for .ts files, specifying those extensions, whereas If the change isn't made here, I think the user should set up the config as: {
"name": "my-awesome-project",
"eslintConfig": {
"extends": [
"xo",
],
overrides: [{
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
"extends": [
"xo-typescript"
]
}]
}
} Note that this means users will also need to specify TypeScript-related rule changes in an override, if they have any. For example this won't work: {
"name": "my-awesome-project",
"eslintConfig": {
"extends": [
"xo",
],
+ "rules": {
+ "@typescript-eslint/no-unsafe-assignment": "warn" // Must be in overrides too
+ },
overrides: [{
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
"extends": [
"xo-typescript"
],
}]
}
} |
I think the fix is to only apply TS rules to TS files, that's how typescript-eslint's recommended config does it. Here: eslint-config-xo-typescript/index.js Line 724 in 9791a06
Add |
I haven't tested fully, but it seems that this is not enough to enable the configuration on TS/TSX files. I had to call
eslint src --ext ts
to have the errors show up. This was not required when I was extendingplugin:@typescript-eslint/*
directlyThe text was updated successfully, but these errors were encountered: