Skip to content

Commit c413c94

Browse files
primitive rule + single config
1 parent fb1415e commit c413c94

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

src/index.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
import 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
1417
const 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
2536
const 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`
4656
const 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-
5764
export default plugin;

src/rules/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)