11import type { FlatConfig , Linter } from "@typescript-eslint/utils/ts-eslint" ;
22
3- import packageJson from ' ../package.json' with { type : ' json' } ;
4- import { recommendedRulesConfig , rules } from "./rules/index " ;
3+ import packageJson from " ../package.json" with { type : " json" } ;
4+ import { myRule , RULE_NAME as MY_RULE } from "./rules/my-rule " ;
55
6- /**
7- * TODO: Add configs (recommended, etc.)
8- * @see https://github.com/typescript-eslint/examples/blob/main/packages/eslint-plugin-example-typed-linting/src/index.ts
9- * @see eslint-plugin-vitest/src/index.ts
10- */
6+ const createConfig = < R extends Linter . RulesRecord > ( rules : R ) => {
7+ const result = { } as {
8+ [ K in keyof R as `tailwindcss/${Extract < K , string > } `] : R [ K ] ;
9+ } ;
10+ for ( const ruleName of Object . keys ( rules ) ) {
11+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12+ ( result as any ) [ `tailwindcss/${ ruleName } ` ] = rules [ ruleName ] ;
13+ }
14+ return result ;
15+ } ;
1116
12- // Plugin not fully initialized yet.
13- // See https://eslint.org/docs/latest/extend/plugins#configs-in-plugins
1417const plugin = {
1518 meta : {
1619 name : packageJson . name ,
1720 version : packageJson . version ,
1821 } ,
19- // `configs`, assigned later
20- configs : { } ,
21- rules : rules ,
22- } satisfies Linter . Plugin ;
22+ configs : {
23+ get recommended ( ) {
24+ return sharedConfigs . recommended ;
25+ } ,
26+ } ,
27+ rules : {
28+ [ MY_RULE ] : myRule ,
29+ } ,
30+ } satisfies FlatConfig . Plugin ;
31+
32+ const recommended = {
33+ [ MY_RULE ] : "warn" ,
34+ } as const ;
2335
24- // Config base for all configurations
2536const configBase : FlatConfig . Config = {
2637 name : "tailwindcss/base" ,
2738 plugins : {
@@ -42,16 +53,12 @@ const configBase: FlatConfig.Config = {
4253 } ,
4354} ;
4455
45- // Prepare configs here so we can reference `plugin`
4656const sharedConfigs : FlatConfig . SharedConfigs = {
4757 recommended : {
4858 ...configBase ,
4959 name : "tailwindcss/recommended" ,
50- rules : recommendedRulesConfig ,
60+ rules : createConfig ( recommended ) ,
5161 } ,
5262} ;
5363
54- // Inject shared configs into the plugin
55- Object . assign ( plugin . configs , sharedConfigs ) ;
56-
5764export default plugin ;
0 commit comments