Giter VIP home page Giter VIP logo

Comments (6)

fregante avatar fregante commented on June 3, 2024 1

Worth an update of docs and config everywhere? typescript-eslint/typescript-eslint#3824 (comment)

from eslint-config-xo-typescript.

fregante avatar fregante commented on June 3, 2024

This enables XO’s config on TS files as well:

  "extends": [
    "plugin:@typescript-eslint/eslint-recommended",
    "xo",
    "xo-typescript"
  ],

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

from eslint-config-xo-typescript.

sindresorhus avatar sindresorhus commented on June 3, 2024

That's weird. I don't see anything regarding extensions in the typescript-eslint config.

from eslint-config-xo-typescript.

fregante avatar fregante commented on June 3, 2024

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:

Oops! Something went wrong! :(

ESLint: 7.30.0

No files matching the pattern "." were found.
Please check for typing mistakes in the pattern.

Add that the plugin and run again:

echo '{"extends":["plugin:@typescript-eslint/recommended","xo","xo-typescript"]}' > .eslintrc
npx eslint .
./index.ts
  1:1  error  Use "@ts-expect-error" to ensure an error is actually being suppressed  @typescript-eslint/prefer-ts-expect-error
  1:1  error  Do not use "@ts-ignore" because it alters compilation errors            @typescript-eslint/ban-ts-comment

✖ 2 problems (2 errors, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Then remove XO’s config:

echo '{"extends":["plugin:@typescript-eslint/recommended"]}' > .eslintrc
npx eslint .
./index.ts
  1:1  error  Do not use "@ts-ignore" because it alters compilation errors  @typescript-eslint/ban-ts-comment

✖ 1 problem (1 error, 0 warnings)

from eslint-config-xo-typescript.

sindresorhus avatar sindresorhus commented on June 3, 2024

Sure

from eslint-config-xo-typescript.

fregante avatar fregante commented on June 3, 2024

I think I know why, and I think this config should follow suit:

https://github.com/typescript-eslint/typescript-eslint/blob/a8830c681f53af4e23a2cda231b3300159b18e7d/packages/eslint-plugin/src/configs/eslint-recommended.ts#L9

The rules are defined in an override for .ts files, specifying those extensions, whereas eslint-config-xo-typescript just loads all rules in the top level.

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"
			],
		}]
	}
}

from eslint-config-xo-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.