Skip to content

Commit f407b64

Browse files
committed
Hopefuly the proper way to export now
1 parent c3b8a59 commit f407b64

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Linter } from "eslint";
2+
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
3+
import { rules } from "../rules";
4+
5+
// 🔁 Dynamically generate rule names with prefix
6+
const pluginName = "dnn-elements";
7+
8+
const prefixedRules: Linter.RulesRecord = Object.fromEntries(
9+
Object.keys(rules).map(ruleName => [
10+
`${pluginName}/${ruleName}`,
11+
"error" as const,
12+
])
13+
);
14+
15+
// ✅ Classic config (extends-based)
16+
export const recommended: Linter.Config = {
17+
plugins: [pluginName],
18+
rules: prefixedRules,
19+
};
20+
21+
// ✅ Flat config (for modern eslint.config.js)
22+
export const flatRecommended: FlatConfig.Config[] = [
23+
{
24+
plugins: {
25+
[pluginName]: {
26+
rules,
27+
},
28+
},
29+
rules: prefixedRules,
30+
},
31+
];
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import { rules } from "./rules";
2+
import { recommended, flatRecommended } from "./configs/recommended";
3+
import type { Plugin } from "./types/plugin";
4+
const { name, version } = require("../../package.json") as {
5+
name: string;
6+
version: string;
7+
};
28

3-
const { name, version } =
4-
// `import`ing here would bypass the TSConfig's `"rootDir": "src"`
5-
// eslint-disable-next-line @typescript-eslint/no-require-imports
6-
require("../../package.json") as typeof import("../../package.json");
7-
8-
const plugin = {
9-
configs: {
10-
get recommended() {
11-
return recommended;
12-
},
13-
},
14-
meta: { name, version },
15-
rules,
16-
};
17-
18-
const recommended = {
19-
plugins: {
20-
"dnn-elements": plugin,
9+
const plugin: Plugin = {
10+
meta: { name, version },
11+
rules,
12+
configs: {
13+
recommended,
14+
flat: {
15+
recommended: flatRecommended,
2116
},
22-
rules,
17+
},
2318
};
2419

25-
export default plugin;
20+
export default plugin;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { Linter } from "eslint";
2+
import type { RuleModule } from "@typescript-eslint/utils/ts-eslint";
3+
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
4+
5+
type RulesRecord = Record<string, RuleModule<string, readonly unknown[]>>;
6+
7+
type FlatConfigs = {
8+
flat?: {
9+
recommended?: FlatConfig.Config[];
10+
[key: string]: FlatConfig.Config[] | undefined;
11+
};
12+
};
13+
14+
export type Plugin = {
15+
meta?: {
16+
name: string;
17+
version: string;
18+
};
19+
rules: RulesRecord;
20+
configs?: {
21+
recommended?: Linter.Config;
22+
} & FlatConfigs;
23+
};

0 commit comments

Comments
 (0)