Skip to content
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

🚀 Feature: Compatibility layer for ESLint plugins #17

Closed
JoshuaKGoldberg opened this issue Jul 15, 2024 · 4 comments
Closed

🚀 Feature: Compatibility layer for ESLint plugins #17

JoshuaKGoldberg opened this issue Jul 15, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@JoshuaKGoldberg
Copy link

JoshuaKGoldberg commented Jul 15, 2024

👋 again! This and https://github.com/Quramy/typescript-eslint-language-service are two really exciting avenues of being able to run ideally much faster typed linting as a part of the TypeScript language service. Ideally we'd be able to run all of a project's linting through this one - including existing ESLint plugins.

One issue that plagued TSLint back in the day was that it didn't support ESLint plugins natively. Everything had to be rewritten from ESTree to TypeScript's AST format.

Would you be interested in some kind of compatibility layer that lets folks natively use ESLint rules and plugins in TSSLint?

Vaguely guessing at an initial API design:

import { defineConfig, eslintPluginCompat } from '@tsslint/config';
import example from 'eslint-plugin-example';

export default defineConfig({
	rules: {
		// ...
		eslintPluginCompat(example.recommended),
	},
});

It looks like ./packages/eslint already has a convertRule that does a lot of this work - so maybe this is already planned? 🙂

@johnsoncodehk johnsoncodehk added the enhancement New feature or request label Jul 15, 2024
@johnsoncodehk
Copy link
Owner

Hey 👋 Thanks for the suggestion, I did plan to add this API but I'm very new to ESLint hence the delay. (I would appreciate it if you could share a repo suitable for testing this API.)

@JoshuaKGoldberg
Copy link
Author

JoshuaKGoldberg commented Jul 15, 2024

Swell! I've got a couple on my personal account that exercise some edge cases:

eslint/eslint#18093 is a good tracking issue to see plugins that support ESLint's new flat config format.

johnsoncodehk added a commit that referenced this issue Jul 15, 2024
@johnsoncodehk
Copy link
Owner

johnsoncodehk commented Jul 15, 2024

1.0.14 1.2.0 added the loadPluginRules convertConfig API in @tsslint/eslint, which is not a complete compatibility layer yet.

Example

import { defineConfig } from '@tsslint/config';
import { loadPluginRules } from '@tsslint/eslint';

export default defineConfig({
	rules: {
		...convertConfig(((await import('eslint-plugin-expect-type')).configs).recommended.rules),
		...convertConfig(((await import('@typescript-eslint/eslint-plugin')).default.configs).recommended.rules ?? {}),
	},
});

Or:

import { defineConfig } from '@tsslint/config'
import { convertConfig } from '@tsslint/eslint'

export default defineConfig({
  rules: convertConfig({
    '@typescript-eslint/no-misused-promises': 'warn',
    '@typescript-eslint/no-unsafe-argument': 'warn',
    '@typescript-eslint/no-unsafe-assignment': 'warn',
    '@typescript-eslint/no-unsafe-member-access': 'warn',
    '@typescript-eslint/no-unsafe-return': 'warn',
    '@typescript-eslint/no-unsafe-enum-comparison': 'warn',
    '@typescript-eslint/no-floating-promises': 'warn',
  }),
});

Since some plugin config has the extends option, implementing the eslintPluginCompat API need more considerations.

@johnsoncodehk
Copy link
Owner

I find that the convertConfig API is sufficient to cover current use cases, since people mainly use TSSLint to add type-aware rules, full compatibility with ESLint config doesn't make much sense to people, instead it may make TSLint config lose clarity.

If you need to completely convert a ESLint config, you can refer to vuejs/core#12497.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants