@vp-tw/eslint-config 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ ViPro's ESLint configuration.
5
5
  - Built on top of [antfu/eslint-config](https://github.com/antfu/eslint-config).
6
6
  - Integrates with:
7
7
  - [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier)
8
- - [eslint-mdx](https://github.com/mdx-js/eslint-mdx).
8
+ - [eslint-mdx](https://github.com/mdx-js/eslint-mdx)
9
9
  - [eslint-plugin-storybook](https://github.com/storybookjs/eslint-plugin-storybook)
10
10
  - [eslint-plugin-react-compiler](https://www.npmjs.com/package/eslint-plugin-react-compiler)
11
11
  - Fine-tuned to provide an opinionated, optimal DX. Please copy the VSCode settings from [eslint-config.code-workspace](https://github.com/VdustR/eslint-config/blob/main/eslint-config.code-workspace).
@@ -7,5 +7,5 @@ declare namespace mdx {
7
7
  flatCodeBlocks?: boolean | TypedFlatConfigItem;
8
8
  }
9
9
  }
10
- declare const mdx: ({ flatCodeBlocks, processorOptions, ...options }?: mdx.Options) => TypedFlatConfigItem[];
10
+ declare const mdx: ({ flatCodeBlocks, processorOptions, ...options }?: mdx.Options) => Promise<Array<TypedFlatConfigItem>>;
11
11
  export { mdx };
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mdx = void 0;
7
+ var _eslintConfig = require("@antfu/eslint-config");
7
8
  var mdxPlugin = _interopRequireWildcard(require("eslint-plugin-mdx"));
8
9
  var _renameRules = require("../utils/renameRules");
9
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- const mdx = ({
12
+ const mdx = async ({
12
13
  flatCodeBlocks = true,
13
14
  processorOptions,
14
15
  ...options
15
16
  } = {}) => {
17
+ await (0, _eslintConfig.ensurePackages)(["eslint-plugin-mdx"]);
16
18
  const flatCodeBlocksOptions = typeof flatCodeBlocks !== "object" ? {} : flatCodeBlocks;
17
19
  const configs = [{
18
20
  name: "vdustr/mdx",
@@ -1,2 +1,3 @@
1
- declare const prettier: any;
1
+ import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ declare const prettier: () => Promise<TypedFlatConfigItem>;
2
3
  export { prettier };
@@ -4,11 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.prettier = void 0;
7
+ var _eslintConfig = require("@antfu/eslint-config");
7
8
  var _eslintConfigPrettier = _interopRequireDefault(require("eslint-config-prettier"));
8
9
  var _renameRules = require("../utils/renameRules");
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const prettier = exports.prettier = {
11
- name: "vdustr/prettier",
12
- ..._eslintConfigPrettier.default,
13
- rules: (0, _renameRules.renameRules)(_eslintConfigPrettier.default.rules)
14
- };
11
+ const prettier = async () => {
12
+ await (0, _eslintConfig.ensurePackages)(["eslint-config-prettier"]);
13
+ return {
14
+ name: "vdustr/prettier",
15
+ ..._eslintConfigPrettier.default,
16
+ rules: (0, _renameRules.renameRules)(_eslintConfigPrettier.default.rules)
17
+ };
18
+ };
19
+ exports.prettier = prettier;
@@ -1,2 +1,3 @@
1
- declare const storybook: any;
1
+ import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ declare const storybook: () => Promise<Array<TypedFlatConfigItem>>;
2
3
  export { storybook };
@@ -4,27 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.storybook = void 0;
7
+ var _eslintConfig = require("@antfu/eslint-config");
7
8
  var _eslintPluginStorybook = _interopRequireDefault(require("eslint-plugin-storybook"));
8
9
  var _renameRules = require("../utils/renameRules");
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const storybook = exports.storybook = _eslintPluginStorybook.default.configs["flat/csf-strict"].map(config => {
11
- const allConfig = config;
12
- const {
13
- rules,
14
- files,
15
- plugins,
16
- ...rest
17
- } = allConfig;
18
- return {
19
- ...rest,
20
- ...(!rules ? null : {
21
- rules: (0, _renameRules.renameRules)(rules)
22
- }),
23
- ...(!files ? null : {
24
- files
25
- }),
26
- ...(!plugins ? null : {
27
- plugins
28
- })
29
- };
30
- });
11
+ const storybook = async () => {
12
+ await (0, _eslintConfig.ensurePackages)(["eslint-plugin-storybook"]);
13
+ return _eslintPluginStorybook.default.configs["flat/csf-strict"].map(config => {
14
+ const allConfig = config;
15
+ const {
16
+ rules,
17
+ files,
18
+ plugins,
19
+ ...rest
20
+ } = allConfig;
21
+ return {
22
+ ...rest,
23
+ ...(!rules ? null : {
24
+ rules: (0, _renameRules.renameRules)(rules)
25
+ }),
26
+ ...(!files ? null : {
27
+ files
28
+ }),
29
+ ...(!plugins ? null : {
30
+ plugins
31
+ })
32
+ };
33
+ });
34
+ };
35
+ exports.storybook = storybook;
@@ -7,5 +7,5 @@ declare namespace mdx {
7
7
  flatCodeBlocks?: boolean | TypedFlatConfigItem;
8
8
  }
9
9
  }
10
- declare const mdx: ({ flatCodeBlocks, processorOptions, ...options }?: mdx.Options) => TypedFlatConfigItem[];
10
+ declare const mdx: ({ flatCodeBlocks, processorOptions, ...options }?: mdx.Options) => Promise<Array<TypedFlatConfigItem>>;
11
11
  export { mdx };
@@ -1,10 +1,12 @@
1
+ import { ensurePackages } from "@antfu/eslint-config";
1
2
  import * as mdxPlugin from "eslint-plugin-mdx";
2
3
  import { renameRules } from "../utils/renameRules.mjs";
3
- const mdx = ({
4
+ const mdx = async ({
4
5
  flatCodeBlocks = true,
5
6
  processorOptions,
6
7
  ...options
7
8
  } = {}) => {
9
+ await ensurePackages(["eslint-plugin-mdx"]);
8
10
  const flatCodeBlocksOptions = typeof flatCodeBlocks !== "object" ? {} : flatCodeBlocks;
9
11
  const configs = [
10
12
  {
@@ -1,2 +1,3 @@
1
- declare const prettier: any;
1
+ import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ declare const prettier: () => Promise<TypedFlatConfigItem>;
2
3
  export { prettier };
@@ -1,8 +1,12 @@
1
+ import { ensurePackages } from "@antfu/eslint-config";
1
2
  import eslintConfigPrettier from "eslint-config-prettier";
2
3
  import { renameRules } from "../utils/renameRules.mjs";
3
- const prettier = {
4
- name: "vdustr/prettier",
5
- ...eslintConfigPrettier,
6
- rules: renameRules(eslintConfigPrettier.rules)
4
+ const prettier = async () => {
5
+ await ensurePackages(["eslint-config-prettier"]);
6
+ return {
7
+ name: "vdustr/prettier",
8
+ ...eslintConfigPrettier,
9
+ rules: renameRules(eslintConfigPrettier.rules)
10
+ };
7
11
  };
8
12
  export { prettier };
@@ -1,2 +1,3 @@
1
- declare const storybook: any;
1
+ import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ declare const storybook: () => Promise<Array<TypedFlatConfigItem>>;
2
3
  export { storybook };
@@ -1,15 +1,19 @@
1
+ import { ensurePackages } from "@antfu/eslint-config";
1
2
  import storybookPlugin from "eslint-plugin-storybook";
2
3
  import { renameRules } from "../utils/renameRules.mjs";
3
- const storybook = storybookPlugin.configs["flat/csf-strict"].map((config) => {
4
- const allConfig = config;
5
- const { rules, files, plugins, ...rest } = allConfig;
6
- return {
7
- ...rest,
8
- ...!rules ? null : {
9
- rules: renameRules(rules)
10
- },
11
- ...!files ? null : { files },
12
- ...!plugins ? null : { plugins }
13
- };
14
- });
4
+ const storybook = async () => {
5
+ await ensurePackages(["eslint-plugin-storybook"]);
6
+ return storybookPlugin.configs["flat/csf-strict"].map((config) => {
7
+ const allConfig = config;
8
+ const { rules, files, plugins, ...rest } = allConfig;
9
+ return {
10
+ ...rest,
11
+ ...!rules ? null : {
12
+ rules: renameRules(rules)
13
+ },
14
+ ...!files ? null : { files },
15
+ ...!plugins ? null : { plugins }
16
+ };
17
+ });
18
+ };
15
19
  export { storybook };
@@ -5,5 +5,5 @@ interface ReactCompiler extends ESLint.Plugin {
5
5
  recommended: Linter.LegacyConfig;
6
6
  };
7
7
  }
8
- declare const reactCompilerInternal: ReactCompiler;
8
+ declare const reactCompilerInternal: () => Promise<ReactCompiler>;
9
9
  export { reactCompilerInternal as reactCompiler };
@@ -1,3 +1,7 @@
1
+ import { ensurePackages } from "@antfu/eslint-config";
1
2
  import * as reactCompiler from "eslint-plugin-react-compiler";
2
- const reactCompilerInternal = reactCompiler.default ?? reactCompiler;
3
+ const reactCompilerInternal = async () => {
4
+ await ensurePackages(["eslint-plugin-react-compiler"]);
5
+ return reactCompiler.default ?? reactCompiler;
6
+ };
3
7
  export { reactCompilerInternal as reactCompiler };
@@ -1,6 +1,7 @@
1
1
  import type { Config } from "./types";
2
2
  import antfu from "@antfu/eslint-config";
3
3
  import { mdx } from "./configs/mdx";
4
+ import "./eslint-typegen";
4
5
  type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
5
6
  mdx?: boolean | mdx.Options;
6
7
  storybook?: boolean;
@@ -1,10 +1,17 @@
1
- import antfu from "@antfu/eslint-config";
1
+ import antfu, {
2
+ GLOB_ASTRO_TS,
3
+ GLOB_JS,
4
+ GLOB_JSX,
5
+ GLOB_TS,
6
+ GLOB_TSX
7
+ } from "@antfu/eslint-config";
2
8
  import packageJson from "eslint-plugin-package-json/configs/recommended";
3
9
  import { isPackageExists } from "local-pkg";
4
10
  import { mdx } from "./configs/mdx.mjs";
5
11
  import { prettier } from "./configs/prettier.mjs";
6
12
  import { storybook } from "./configs/storybook.mjs";
7
13
  import { reactCompiler } from "./lib/eslint-plugin-react-compiler.mjs";
14
+ import "./eslint-typegen";
8
15
  const vdustr = (options, ...userConfigs) => {
9
16
  const typescriptEnabled = isPackageExists("typescript");
10
17
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
@@ -20,28 +27,12 @@ const vdustr = (options, ...userConfigs) => {
20
27
  const mdxFlatCodeBlocksOptions = {
21
28
  ...typeof mdxOptions?.flatCodeBlocks !== "object" ? null : mdxOptions.flatCodeBlocks
22
29
  };
23
- const defaultConfigs = [
24
- ...!jsoncEnabled ? [] : [packageJson],
25
- ...!mdxEnabled ? [] : mdx({
26
- ...mdxOptions,
27
- flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
28
- ...mdxFlatCodeBlocksOptions,
29
- rules: {
30
- "import/no-default-export": "off",
31
- ...mdxFlatCodeBlocksOptions?.rules
32
- }
33
- }
34
- }),
35
- ...!storybookEnabled ? [] : storybook,
36
- prettier
37
- ];
38
30
  let config = antfu(
39
31
  {
40
32
  // We use `prettier`.
41
33
  stylistic: false,
42
34
  ...options
43
35
  },
44
- ...defaultConfigs,
45
36
  ...userConfigs
46
37
  );
47
38
  config = config.override("antfu/javascript/rules", (config2) => ({
@@ -74,24 +65,23 @@ const vdustr = (options, ...userConfigs) => {
74
65
  * Wildcard imports can prevent tree shaking and cause name conflicts.
75
66
  * Consider using named imports instead.
76
67
  */
77
- "import/no-namespace": "error",
68
+ "import/no-namespace": "error"
69
+ }
70
+ })).insertAfter("antfu/imports/rules", {
71
+ name: "vdustr/no-default-export",
72
+ rules: {
78
73
  /**
79
74
  * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
80
75
  * with default export renaming. Additionally, default exports might lead to different behavior when transformed
81
76
  * to CJS.
82
77
  */
83
78
  "import/no-default-export": "error"
84
- }
85
- })).insertAfter("antfu/imports/rules", {
86
- name: "vdustr/allow-default-export",
87
- rules: {
88
- "import/no-default-export": "off"
89
79
  },
90
- files: [
80
+ files: [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX],
81
+ ignores: [
82
+ // Configuration files
91
83
  "**/*.config.*",
92
- // Single file components
93
- "**/*.vue",
94
- "**/*.svelte"
84
+ GLOB_ASTRO_TS
95
85
  ]
96
86
  });
97
87
  if (typescriptEnabled) {
@@ -131,27 +121,29 @@ const vdustr = (options, ...userConfigs) => {
131
121
  */
132
122
  "**/package.json"
133
123
  ]
134
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
124
+ })).insertAfter("antfu/jsonc/rules", packageJson).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
135
125
  }
136
126
  if (reactEnabled) {
137
- config = config.override("antfu/react/rules", (config2) => ({
138
- ...config2,
139
- plugins: {
140
- ...config2.plugins,
141
- "react-compiler": reactCompiler
142
- },
143
- rules: {
144
- ...config2.rules,
145
- "react-compiler/react-compiler": "error",
146
- /**
147
- * Not all destructuring assignments are more readable than their alternatives.
148
- */
149
- "react/prefer-destructuring-assignment": "off"
150
- }
151
- }));
127
+ config = config.override("antfu/react/rules", async (config2) => {
128
+ return {
129
+ ...config2,
130
+ plugins: {
131
+ ...config2.plugins,
132
+ "react-compiler": await reactCompiler()
133
+ },
134
+ rules: {
135
+ ...config2.rules,
136
+ "react-compiler/react-compiler": "error",
137
+ /**
138
+ * Not all destructuring assignments are more readable than their alternatives.
139
+ */
140
+ "react/prefer-destructuring-assignment": "off"
141
+ }
142
+ };
143
+ });
152
144
  }
153
145
  if (storybookEnabled) {
154
- config = config.override("storybook:csf:stories-rules", (config2) => ({
146
+ config = config.append(storybook()).override("storybook:csf:stories-rules", (config2) => ({
155
147
  ...config2,
156
148
  rules: {
157
149
  ...config2.rules,
@@ -159,6 +151,21 @@ const vdustr = (options, ...userConfigs) => {
159
151
  }
160
152
  }));
161
153
  }
154
+ if (mdxEnabled) {
155
+ config = config.append(
156
+ mdx({
157
+ ...mdxOptions,
158
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
159
+ ...mdxFlatCodeBlocksOptions,
160
+ rules: {
161
+ "import/no-default-export": "off",
162
+ ...mdxFlatCodeBlocksOptions?.rules
163
+ }
164
+ }
165
+ })
166
+ );
167
+ }
168
+ config = config.append(prettier());
162
169
  return config;
163
170
  };
164
171
  export { vdustr };
@@ -5,5 +5,5 @@ interface ReactCompiler extends ESLint.Plugin {
5
5
  recommended: Linter.LegacyConfig;
6
6
  };
7
7
  }
8
- declare const reactCompilerInternal: ReactCompiler;
8
+ declare const reactCompilerInternal: () => Promise<ReactCompiler>;
9
9
  export { reactCompilerInternal as reactCompiler };
@@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.reactCompiler = void 0;
7
+ var _eslintConfig = require("@antfu/eslint-config");
7
8
  var reactCompiler = _interopRequireWildcard(require("eslint-plugin-react-compiler"));
8
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
- const reactCompilerInternal = exports.reactCompiler = reactCompiler.default ?? reactCompiler;
11
+ const reactCompilerInternal = async () => {
12
+ await (0, _eslintConfig.ensurePackages)(["eslint-plugin-react-compiler"]);
13
+ return reactCompiler.default ?? reactCompiler;
14
+ };
15
+ exports.reactCompiler = reactCompilerInternal;
package/dist/vdustr.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Config } from "./types";
2
2
  import antfu from "@antfu/eslint-config";
3
3
  import { mdx } from "./configs/mdx";
4
+ import "./eslint-typegen";
4
5
  type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
5
6
  mdx?: boolean | mdx.Options;
6
7
  storybook?: boolean;
package/dist/vdustr.js CHANGED
@@ -4,14 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.vdustr = void 0;
7
- var _eslintConfig = _interopRequireDefault(require("@antfu/eslint-config"));
7
+ var _eslintConfig = _interopRequireWildcard(require("@antfu/eslint-config"));
8
8
  var _recommended = _interopRequireDefault(require("eslint-plugin-package-json/configs/recommended"));
9
9
  var _localPkg = require("local-pkg");
10
10
  var _mdx = require("./configs/mdx");
11
11
  var _prettier = require("./configs/prettier");
12
12
  var _storybook = require("./configs/storybook");
13
13
  var _eslintPluginReactCompiler = require("./lib/eslint-plugin-react-compiler");
14
+ require("./eslint-typegen");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
18
  const vdustr = (options, ...userConfigs) => {
16
19
  const typescriptEnabled = (0, _localPkg.isPackageExists)("typescript");
17
20
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
@@ -25,21 +28,11 @@ const vdustr = (options, ...userConfigs) => {
25
28
  const mdxFlatCodeBlocksOptions = {
26
29
  ...(typeof mdxOptions?.flatCodeBlocks !== "object" ? null : mdxOptions.flatCodeBlocks)
27
30
  };
28
- const defaultConfigs = [...(!jsoncEnabled ? [] : [_recommended.default]), ...(!mdxEnabled ? [] : (0, _mdx.mdx)({
29
- ...mdxOptions,
30
- flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
31
- ...mdxFlatCodeBlocksOptions,
32
- rules: {
33
- "import/no-default-export": "off",
34
- ...mdxFlatCodeBlocksOptions?.rules
35
- }
36
- }
37
- })), ...(!storybookEnabled ? [] : _storybook.storybook), _prettier.prettier];
38
31
  let config = (0, _eslintConfig.default)({
39
32
  // We use `prettier`.
40
33
  stylistic: false,
41
34
  ...options
42
- }, ...defaultConfigs, ...userConfigs);
35
+ }, ...userConfigs);
43
36
  config = config.override("antfu/javascript/rules", config2 => ({
44
37
  ...config2,
45
38
  rules: {
@@ -70,22 +63,22 @@ const vdustr = (options, ...userConfigs) => {
70
63
  * Wildcard imports can prevent tree shaking and cause name conflicts.
71
64
  * Consider using named imports instead.
72
65
  */
73
- "import/no-namespace": "error",
66
+ "import/no-namespace": "error"
67
+ }
68
+ })).insertAfter("antfu/imports/rules", {
69
+ name: "vdustr/no-default-export",
70
+ rules: {
74
71
  /**
75
72
  * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
76
73
  * with default export renaming. Additionally, default exports might lead to different behavior when transformed
77
74
  * to CJS.
78
75
  */
79
76
  "import/no-default-export": "error"
80
- }
81
- })).insertAfter("antfu/imports/rules", {
82
- name: "vdustr/allow-default-export",
83
- rules: {
84
- "import/no-default-export": "off"
85
77
  },
86
- files: ["**/*.config.*",
87
- // Single file components
88
- "**/*.vue", "**/*.svelte"]
78
+ files: [_eslintConfig.GLOB_JS, _eslintConfig.GLOB_JSX, _eslintConfig.GLOB_TS, _eslintConfig.GLOB_TSX],
79
+ ignores: [
80
+ // Configuration files
81
+ "**/*.config.*", _eslintConfig.GLOB_ASTRO_TS]
89
82
  });
90
83
  if (typescriptEnabled) {
91
84
  config = config.override("antfu/typescript/rules", config2 => ({
@@ -124,27 +117,29 @@ const vdustr = (options, ...userConfigs) => {
124
117
  * Lint `package.json` files with `eslint-plugin-package-json` instead.
125
118
  */
126
119
  "**/package.json"]
127
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
120
+ })).insertAfter("antfu/jsonc/rules", _recommended.default).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
128
121
  }
129
122
  if (reactEnabled) {
130
- config = config.override("antfu/react/rules", config2 => ({
131
- ...config2,
132
- plugins: {
133
- ...config2.plugins,
134
- "react-compiler": _eslintPluginReactCompiler.reactCompiler
135
- },
136
- rules: {
137
- ...config2.rules,
138
- "react-compiler/react-compiler": "error",
139
- /**
140
- * Not all destructuring assignments are more readable than their alternatives.
141
- */
142
- "react/prefer-destructuring-assignment": "off"
143
- }
144
- }));
123
+ config = config.override("antfu/react/rules", async config2 => {
124
+ return {
125
+ ...config2,
126
+ plugins: {
127
+ ...config2.plugins,
128
+ "react-compiler": await (0, _eslintPluginReactCompiler.reactCompiler)()
129
+ },
130
+ rules: {
131
+ ...config2.rules,
132
+ "react-compiler/react-compiler": "error",
133
+ /**
134
+ * Not all destructuring assignments are more readable than their alternatives.
135
+ */
136
+ "react/prefer-destructuring-assignment": "off"
137
+ }
138
+ };
139
+ });
145
140
  }
146
141
  if (storybookEnabled) {
147
- config = config.override("storybook:csf:stories-rules", config2 => ({
142
+ config = config.append((0, _storybook.storybook)()).override("storybook:csf:stories-rules", config2 => ({
148
143
  ...config2,
149
144
  rules: {
150
145
  ...config2.rules,
@@ -152,6 +147,19 @@ const vdustr = (options, ...userConfigs) => {
152
147
  }
153
148
  }));
154
149
  }
150
+ if (mdxEnabled) {
151
+ config = config.append((0, _mdx.mdx)({
152
+ ...mdxOptions,
153
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
154
+ ...mdxFlatCodeBlocksOptions,
155
+ rules: {
156
+ "import/no-default-export": "off",
157
+ ...mdxFlatCodeBlocksOptions?.rules
158
+ }
159
+ }
160
+ }));
161
+ }
162
+ config = config.append((0, _prettier.prettier)());
155
163
  return config;
156
164
  };
157
165
  exports.vdustr = vdustr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vp-tw/eslint-config",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "ViPro's ESLint configuration",
5
5
  "homepage": "https://github.com/vdustr/eslint-config",
6
6
  "author": {
@@ -37,17 +37,11 @@
37
37
  "types": "./dist/index.d.ts",
38
38
  "dependencies": {
39
39
  "@antfu/eslint-config": "^4.1.0",
40
- "@eslint-react/eslint-plugin": "^1.25.0",
41
- "@eslint/compat": "^1.2.5",
42
40
  "@mui/types": "^7.2.21",
43
41
  "@types/eslint-config-prettier": "^6.11.3",
44
- "@types/eslint__eslintrc": "^2.1.2",
45
42
  "eslint-config-prettier": "^10.0.1",
46
43
  "eslint-flat-config-utils": "^2.0.0",
47
- "eslint-plugin-mdx": "^3.1.5",
48
44
  "eslint-plugin-package-json": "^0.21.1",
49
- "eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124",
50
- "eslint-plugin-storybook": "^0.11.2",
51
45
  "local-pkg": "^1.0.0"
52
46
  },
53
47
  "devDependencies": {
@@ -24,7 +24,7 @@ import { reactCompiler } from "../src/lib/eslint-plugin-react-compiler";
24
24
  }
25
25
 
26
26
  const plugins: Plugins = {
27
- ...definePlugins({ "react-compiler": reactCompiler }),
27
+ ...definePlugins({ "react-compiler": await reactCompiler() }),
28
28
  ...definePlugins({
29
29
  mdx: {
30
30
  rules: mdxRules,
@@ -1,5 +1,6 @@
1
1
  import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
2
  import type { DistributiveOmit } from "@mui/types";
3
+ import { ensurePackages } from "@antfu/eslint-config";
3
4
 
4
5
  // eslint-disable-next-line import/no-namespace -- `mdx` exports the plugin as a namespace.
5
6
  import * as mdxPlugin from "eslint-plugin-mdx";
@@ -13,11 +14,12 @@ namespace mdx {
13
14
  }
14
15
  }
15
16
 
16
- const mdx = ({
17
+ const mdx = async ({
17
18
  flatCodeBlocks = true,
18
19
  processorOptions,
19
20
  ...options
20
- }: mdx.Options = {}) => {
21
+ }: mdx.Options = {}): Promise<Array<TypedFlatConfigItem>> => {
22
+ await ensurePackages(["eslint-plugin-mdx"]);
21
23
  const flatCodeBlocksOptions: TypedFlatConfigItem =
22
24
  typeof flatCodeBlocks !== "object" ? {} : flatCodeBlocks;
23
25
  const configs: Array<TypedFlatConfigItem> = [
@@ -1,12 +1,16 @@
1
1
  import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ import { ensurePackages } from "@antfu/eslint-config";
2
3
 
3
4
  import eslintConfigPrettier from "eslint-config-prettier";
4
5
  import { renameRules } from "../utils/renameRules";
5
6
 
6
- const prettier = {
7
- name: "vdustr/prettier",
8
- ...eslintConfigPrettier,
9
- rules: renameRules(eslintConfigPrettier.rules),
10
- } satisfies TypedFlatConfigItem;
7
+ const prettier = async (): Promise<TypedFlatConfigItem> => {
8
+ await ensurePackages(["eslint-config-prettier"]);
9
+ return {
10
+ name: "vdustr/prettier",
11
+ ...eslintConfigPrettier,
12
+ rules: renameRules(eslintConfigPrettier.rules),
13
+ };
14
+ };
11
15
 
12
16
  export { prettier };
@@ -1,20 +1,24 @@
1
1
  import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
+ import { ensurePackages } from "@antfu/eslint-config";
2
3
  import storybookPlugin from "eslint-plugin-storybook";
3
4
  import { renameRules } from "../utils/renameRules";
4
5
 
5
- const storybook = storybookPlugin.configs["flat/csf-strict"].map((config) => {
6
- const allConfig = config as TypedFlatConfigItem;
7
- const { rules, files, plugins, ...rest } = allConfig;
8
- return {
9
- ...rest,
10
- ...(!rules
11
- ? null
12
- : {
13
- rules: renameRules(rules),
14
- }),
15
- ...(!files ? null : { files }),
16
- ...(!plugins ? null : { plugins }),
17
- } satisfies TypedFlatConfigItem;
18
- });
6
+ const storybook = async (): Promise<Array<TypedFlatConfigItem>> => {
7
+ await ensurePackages(["eslint-plugin-storybook"]);
8
+ return storybookPlugin.configs["flat/csf-strict"].map((config) => {
9
+ const allConfig = config as TypedFlatConfigItem;
10
+ const { rules, files, plugins, ...rest } = allConfig;
11
+ return {
12
+ ...rest,
13
+ ...(!rules
14
+ ? null
15
+ : {
16
+ rules: renameRules(rules),
17
+ }),
18
+ ...(!files ? null : { files }),
19
+ ...(!plugins ? null : { plugins }),
20
+ } satisfies TypedFlatConfigItem;
21
+ });
22
+ };
19
23
 
20
24
  export { storybook };
@@ -0,0 +1 @@
1
+ // This is a placeholder for `eslint-typegen.d.ts`.
@@ -1,4 +1,5 @@
1
1
  import type { ESLint, Linter } from "eslint";
2
+ import { ensurePackages } from "@antfu/eslint-config";
2
3
  // @ts-expect-error -- Untyped library.
3
4
  // eslint-disable-next-line import/no-namespace -- `react-compiler` exports the plugin as a namespace.
4
5
  import * as reactCompiler from "eslint-plugin-react-compiler";
@@ -10,7 +11,9 @@ interface ReactCompiler extends ESLint.Plugin {
10
11
  };
11
12
  }
12
13
 
13
- const reactCompilerInternal: ReactCompiler =
14
- reactCompiler.default ?? reactCompiler;
14
+ const reactCompilerInternal = async (): Promise<ReactCompiler> => {
15
+ await ensurePackages(["eslint-plugin-react-compiler"]);
16
+ return reactCompiler.default ?? reactCompiler;
17
+ };
15
18
 
16
19
  export { reactCompilerInternal as reactCompiler };
package/src/vdustr.ts CHANGED
@@ -1,15 +1,20 @@
1
- // eslint-disable-next-line import/no-empty-named-blocks -- Type only import.
2
- import type {} from "./eslint-typegen";
3
1
  import type { Config } from "./types";
4
- import antfu from "@antfu/eslint-config";
2
+ import antfu, {
3
+ GLOB_ASTRO_TS,
4
+ GLOB_JS,
5
+ GLOB_JSX,
6
+ GLOB_TS,
7
+ GLOB_TSX,
8
+ } from "@antfu/eslint-config";
5
9
 
6
10
  import packageJson from "eslint-plugin-package-json/configs/recommended";
7
-
8
11
  import { isPackageExists } from "local-pkg";
12
+
9
13
  import { mdx } from "./configs/mdx";
10
14
  import { prettier } from "./configs/prettier";
11
15
  import { storybook } from "./configs/storybook";
12
16
  import { reactCompiler } from "./lib/eslint-plugin-react-compiler";
17
+ import "./eslint-typegen";
13
18
 
14
19
  type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
15
20
  mdx?: boolean | mdx.Options;
@@ -36,33 +41,12 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
36
41
  ? null
37
42
  : mdxOptions.flatCodeBlocks),
38
43
  };
39
- type Config = NonNullable<Parameters<typeof antfu>[1]>;
40
- const defaultConfigs: Array<Config> = [
41
- ...(!jsoncEnabled ? [] : [packageJson]),
42
- ...(!mdxEnabled
43
- ? []
44
- : mdx({
45
- ...mdxOptions,
46
- flatCodeBlocks: !mdxFlatCodeBlocksEnabled
47
- ? false
48
- : {
49
- ...mdxFlatCodeBlocksOptions,
50
- rules: {
51
- "import/no-default-export": "off",
52
- ...mdxFlatCodeBlocksOptions?.rules,
53
- },
54
- },
55
- })),
56
- ...(!storybookEnabled ? [] : storybook),
57
- prettier,
58
- ];
59
44
  let config = antfu(
60
45
  {
61
46
  // We use `prettier`.
62
47
  stylistic: false,
63
48
  ...options,
64
49
  },
65
- ...defaultConfigs,
66
50
  ...userConfigs,
67
51
  );
68
52
 
@@ -101,13 +85,6 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
101
85
  * Consider using named imports instead.
102
86
  */
103
87
  "import/no-namespace": "error",
104
-
105
- /**
106
- * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
107
- * with default export renaming. Additionally, default exports might lead to different behavior when transformed
108
- * to CJS.
109
- */
110
- "import/no-default-export": "error",
111
88
  },
112
89
  }))
113
90
 
@@ -115,15 +92,20 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
115
92
  * Allow default exports in certain files.
116
93
  */
117
94
  .insertAfter("antfu/imports/rules", {
118
- name: "vdustr/allow-default-export",
95
+ name: "vdustr/no-default-export",
119
96
  rules: {
120
- "import/no-default-export": "off",
97
+ /**
98
+ * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
99
+ * with default export renaming. Additionally, default exports might lead to different behavior when transformed
100
+ * to CJS.
101
+ */
102
+ "import/no-default-export": "error",
121
103
  },
122
- files: [
104
+ files: [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX],
105
+ ignores: [
106
+ // Configuration files
123
107
  "**/*.config.*",
124
- // Single file components
125
- "**/*.vue",
126
- "**/*.svelte",
108
+ GLOB_ASTRO_TS,
127
109
  ],
128
110
  });
129
111
 
@@ -169,39 +151,63 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
169
151
  "**/package.json",
170
152
  ],
171
153
  }))
154
+ .insertAfter("antfu/jsonc/rules", packageJson)
172
155
  .remove("antfu/sort/package-json")
173
156
  .remove("antfu/sort/tsconfig-json");
174
157
  }
175
158
 
176
159
  if (reactEnabled) {
177
- config = config.override("antfu/react/rules", (config) => ({
178
- ...config,
179
- plugins: {
180
- ...config.plugins,
181
- "react-compiler": reactCompiler,
182
- },
183
- rules: {
184
- ...config.rules,
185
- "react-compiler/react-compiler": "error",
160
+ config = config.override("antfu/react/rules", async (config) => {
161
+ return {
162
+ ...config,
163
+ plugins: {
164
+ ...config.plugins,
165
+ "react-compiler": await reactCompiler(),
166
+ },
167
+ rules: {
168
+ ...config.rules,
169
+ "react-compiler/react-compiler": "error",
186
170
 
187
- /**
188
- * Not all destructuring assignments are more readable than their alternatives.
189
- */
190
- "react/prefer-destructuring-assignment": "off",
191
- },
192
- }));
171
+ /**
172
+ * Not all destructuring assignments are more readable than their alternatives.
173
+ */
174
+ "react/prefer-destructuring-assignment": "off",
175
+ },
176
+ };
177
+ });
193
178
  }
194
179
 
195
180
  if (storybookEnabled) {
196
- config = config.override("storybook:csf:stories-rules", (config) => ({
197
- ...config,
198
- rules: {
199
- ...config.rules,
200
- "import/no-default-export": "off",
201
- },
202
- }));
181
+ config = config
182
+ .append(storybook())
183
+ .override("storybook:csf:stories-rules", (config) => ({
184
+ ...config,
185
+ rules: {
186
+ ...config.rules,
187
+ "import/no-default-export": "off",
188
+ },
189
+ }));
203
190
  }
204
191
 
192
+ if (mdxEnabled) {
193
+ config = config.append(
194
+ mdx({
195
+ ...mdxOptions,
196
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled
197
+ ? false
198
+ : {
199
+ ...mdxFlatCodeBlocksOptions,
200
+ rules: {
201
+ "import/no-default-export": "off",
202
+ ...mdxFlatCodeBlocksOptions?.rules,
203
+ },
204
+ },
205
+ }),
206
+ );
207
+ }
208
+
209
+ config = config.append(prettier());
210
+
205
211
  return config;
206
212
  };
207
213