@vp-tw/eslint-config 0.0.2 → 0.0.3

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.
@@ -1,20 +1,25 @@
1
1
  import antfu from "@antfu/eslint-config";
2
2
  import packageJson from "eslint-plugin-package-json/configs/recommended";
3
3
  import * as reactCompilerPlugin from "eslint-plugin-react-compiler";
4
+ import { isPackageExists } from "local-pkg";
4
5
  import { mdx } from "./configs/mdx.mjs";
5
6
  import { prettier } from "./configs/prettier.mjs";
6
- import "./eslint-typegen.d";
7
+ import { storybook } from "./configs/storybook.mjs";
7
8
  const vdustr = (options, ...userConfigs) => {
8
- const mdxOptions = options?.mdx ?? true;
9
+ const typescriptEnabled = isPackageExists("typescript");
9
10
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
11
+ const reactEnabled = Boolean(options?.react ?? false);
12
+ const storybookEnabled = Boolean(options?.storybook ?? false);
13
+ const mdxOptions = options?.mdx ?? true;
10
14
  const defaultConfigs = [
11
15
  ...!jsoncEnabled ? [] : [packageJson],
12
16
  ...!mdxOptions ? [] : mdx({
13
17
  ...typeof mdxOptions !== "object" ? null : mdxOptions
14
18
  }),
19
+ ...!storybookEnabled ? [] : storybook,
15
20
  prettier
16
21
  ];
17
- return antfu(
22
+ let config = antfu(
18
23
  {
19
24
  // We use `prettier`.
20
25
  stylistic: false,
@@ -22,10 +27,11 @@ const vdustr = (options, ...userConfigs) => {
22
27
  },
23
28
  ...defaultConfigs,
24
29
  ...userConfigs
25
- ).override("antfu/javascript/rules", (config) => ({
26
- ...config,
30
+ );
31
+ config = config.override("antfu/javascript/rules", (config2) => ({
32
+ ...config2,
27
33
  rules: {
28
- ...config.rules,
34
+ ...config2.rules,
29
35
  /**
30
36
  * Some callbacks are purposefully named to make the code self-documenting.
31
37
  */
@@ -40,62 +46,103 @@ const vdustr = (options, ...userConfigs) => {
40
46
  "unused-imports/no-unused-vars-ts": "off",
41
47
  "unused-imports/no-unused-imports": "off"
42
48
  }
43
- })).override("antfu/imports/rules", (config) => ({
44
- ...config,
49
+ })).override("antfu/imports/rules", (config2) => ({
50
+ ...config2,
45
51
  rules: {
46
- ...config.rules,
52
+ ...config2.rules,
47
53
  /**
48
54
  * Forbid `import {} from "module"`.
49
55
  */
50
- "import/no-empty-named-blocks": "error"
51
- }
52
- })).override("antfu/typescript/rules", (config) => ({
53
- ...config,
54
- rules: {
55
- ...config.rules,
56
- "ts/array-type": ["error", { default: "generic" }],
56
+ "import/no-empty-named-blocks": "error",
57
57
  /**
58
- * Namespaces are useful for centralizing the management of types. Just avoid
59
- * overusing them with runtime code.
60
- *
61
- * - References:
62
- * - <https://x.com/mattpocockuk/status/1805606072167940167>
58
+ * Wildcard imports can prevent tree shaking and cause name conflicts.
59
+ * Consider using named imports instead.
63
60
  */
64
- "ts/no-namespace": "off",
65
- "ts/no-redeclare": "off",
61
+ "import/no-namespace": "error",
66
62
  /**
67
- * Check for unused variables in TypeScript.
63
+ * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
64
+ * with default export renaming. Additionally, default exports might lead to different behavior when transformed
65
+ * to CJS.
68
66
  */
69
- "ts/no-unused-vars": "off"
67
+ "import/no-default-export": "error"
70
68
  }
71
- })).override("antfu/jsonc/rules", (config) => ({
72
- ...config,
69
+ })).insertAfter("antfu/imports/rules", {
70
+ name: "vdustr/allow-default-export",
73
71
  rules: {
74
- ...config.rules,
75
- "jsonc/sort-keys": "error"
72
+ "import/no-default-export": "off"
76
73
  },
77
- files: [...config.files ?? [], "**/*.code-workspace"],
78
- ignores: [
79
- ...config.ignores ?? [],
80
- /**
81
- * Lint `package.json` files with `eslint-plugin-package-json` instead.
82
- */
83
- "**/package.json"
74
+ files: [
75
+ "**/*.config.*",
76
+ // Single file components
77
+ "**/*.vue",
78
+ "**/*.svelte"
84
79
  ]
85
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json").override("antfu/react/rules", (config) => ({
86
- ...config,
87
- plugins: {
88
- ...config.plugins,
89
- "react-compiler": reactCompilerPlugin
90
- },
91
- rules: {
92
- ...config.rules,
93
- "react-compiler/react-compiler": "error",
94
- /**
95
- * Not all destructuring assignments are more readable than their alternatives.
96
- */
97
- "react/prefer-destructuring-assignment": "off"
98
- }
99
- }));
80
+ });
81
+ if (typescriptEnabled) {
82
+ config = config.override("antfu/typescript/rules", (config2) => ({
83
+ ...config2,
84
+ rules: {
85
+ ...config2.rules,
86
+ "ts/array-type": ["error", { default: "generic" }],
87
+ /**
88
+ * Namespaces are useful for centralizing the management of types. Just avoid
89
+ * overusing them with runtime code.
90
+ *
91
+ * - References:
92
+ * - <https://x.com/mattpocockuk/status/1805606072167940167>
93
+ */
94
+ "ts/no-namespace": "off",
95
+ "ts/no-redeclare": "off",
96
+ /**
97
+ * Check for unused variables in TypeScript.
98
+ */
99
+ "ts/no-unused-vars": "off"
100
+ }
101
+ }));
102
+ }
103
+ if (jsoncEnabled) {
104
+ config = config.override("antfu/jsonc/rules", (config2) => ({
105
+ ...config2,
106
+ rules: {
107
+ ...config2.rules,
108
+ "jsonc/sort-keys": "error"
109
+ },
110
+ files: [...config2.files ?? [], "**/*.code-workspace"],
111
+ ignores: [
112
+ ...config2.ignores ?? [],
113
+ /**
114
+ * Lint `package.json` files with `eslint-plugin-package-json` instead.
115
+ */
116
+ "**/package.json"
117
+ ]
118
+ })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
119
+ }
120
+ if (reactEnabled) {
121
+ config = config.override("antfu/react/rules", (config2) => ({
122
+ ...config2,
123
+ plugins: {
124
+ ...config2.plugins,
125
+ "react-compiler": reactCompilerPlugin
126
+ },
127
+ rules: {
128
+ ...config2.rules,
129
+ "react-compiler/react-compiler": "error",
130
+ /**
131
+ * Not all destructuring assignments are more readable than their alternatives.
132
+ */
133
+ "react/prefer-destructuring-assignment": "off"
134
+ }
135
+ }));
136
+ }
137
+ if (storybookEnabled) {
138
+ config = config.override("storybook:csf:stories-rules", (config2) => ({
139
+ ...config2,
140
+ rules: {
141
+ ...config2.rules,
142
+ "import/no-default-export": "off"
143
+ }
144
+ }));
145
+ }
146
+ return config;
100
147
  };
101
148
  export { vdustr };
@@ -0,0 +1,3 @@
1
+ import { renameRules } from "@antfu/eslint-config";
2
+ declare function renameRulesInternal(rules: Parameters<typeof renameRules>[0]): Record<string, any>;
3
+ export { renameRulesInternal as renameRules };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renameRules = renameRulesInternal;
7
+ var _eslintConfig = require("@antfu/eslint-config");
8
+ function renameRulesInternal(rules) {
9
+ return (0, _eslintConfig.renameRules)(rules, _eslintConfig.defaultPluginRenaming);
10
+ }
package/dist/vdustr.d.ts CHANGED
@@ -1,9 +1,9 @@
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.d";
5
4
  type Options = NonNullable<Parameters<typeof antfu>[0]> & {
6
5
  mdx?: boolean | mdx.Options;
6
+ storybook?: boolean;
7
7
  };
8
8
  declare const vdustr: (options?: Options, ...userConfigs: Array<Config>) => import("eslint-flat-config-utils/index").FlatConfigComposer<import("@antfu/eslint-config").TypedFlatConfigItem, import("@antfu/eslint-config").ConfigNames>;
9
9
  export { vdustr };
package/dist/vdustr.js CHANGED
@@ -7,26 +7,31 @@ exports.vdustr = void 0;
7
7
  var _eslintConfig = _interopRequireDefault(require("@antfu/eslint-config"));
8
8
  var _recommended = _interopRequireDefault(require("eslint-plugin-package-json/configs/recommended"));
9
9
  var reactCompilerPlugin = _interopRequireWildcard(require("eslint-plugin-react-compiler"));
10
+ var _localPkg = require("local-pkg");
10
11
  var _mdx = require("./configs/mdx");
11
12
  var _prettier = require("./configs/prettier");
12
- require("./eslint-typegen.d");
13
+ var _storybook = require("./configs/storybook");
13
14
  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); }
14
15
  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
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  const vdustr = (options, ...userConfigs) => {
17
- const mdxOptions = options?.mdx ?? true;
18
+ const typescriptEnabled = (0, _localPkg.isPackageExists)("typescript");
18
19
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
20
+ const reactEnabled = Boolean(options?.react ?? false);
21
+ const storybookEnabled = Boolean(options?.storybook ?? false);
22
+ const mdxOptions = options?.mdx ?? true;
19
23
  const defaultConfigs = [...(!jsoncEnabled ? [] : [_recommended.default]), ...(!mdxOptions ? [] : (0, _mdx.mdx)({
20
24
  ...(typeof mdxOptions !== "object" ? null : mdxOptions)
21
- })), _prettier.prettier];
22
- return (0, _eslintConfig.default)({
25
+ })), ...(!storybookEnabled ? [] : _storybook.storybook), _prettier.prettier];
26
+ let config = (0, _eslintConfig.default)({
23
27
  // We use `prettier`.
24
28
  stylistic: false,
25
29
  ...options
26
- }, ...defaultConfigs, ...userConfigs).override("antfu/javascript/rules", config => ({
27
- ...config,
30
+ }, ...defaultConfigs, ...userConfigs);
31
+ config = config.override("antfu/javascript/rules", config2 => ({
32
+ ...config2,
28
33
  rules: {
29
- ...config.rules,
34
+ ...config2.rules,
30
35
  /**
31
36
  * Some callbacks are purposefully named to make the code self-documenting.
32
37
  */
@@ -41,62 +46,100 @@ const vdustr = (options, ...userConfigs) => {
41
46
  "unused-imports/no-unused-vars-ts": "off",
42
47
  "unused-imports/no-unused-imports": "off"
43
48
  }
44
- })).override("antfu/imports/rules", config => ({
45
- ...config,
49
+ })).override("antfu/imports/rules", config2 => ({
50
+ ...config2,
46
51
  rules: {
47
- ...config.rules,
52
+ ...config2.rules,
48
53
  /**
49
54
  * Forbid `import {} from "module"`.
50
55
  */
51
- "import/no-empty-named-blocks": "error"
52
- }
53
- })).override("antfu/typescript/rules", config => ({
54
- ...config,
55
- rules: {
56
- ...config.rules,
57
- "ts/array-type": ["error", {
58
- default: "generic"
59
- }],
56
+ "import/no-empty-named-blocks": "error",
60
57
  /**
61
- * Namespaces are useful for centralizing the management of types. Just avoid
62
- * overusing them with runtime code.
63
- *
64
- * - References:
65
- * - <https://x.com/mattpocockuk/status/1805606072167940167>
58
+ * Wildcard imports can prevent tree shaking and cause name conflicts.
59
+ * Consider using named imports instead.
66
60
  */
67
- "ts/no-namespace": "off",
68
- "ts/no-redeclare": "off",
61
+ "import/no-namespace": "error",
69
62
  /**
70
- * Check for unused variables in TypeScript.
63
+ * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
64
+ * with default export renaming. Additionally, default exports might lead to different behavior when transformed
65
+ * to CJS.
71
66
  */
72
- "ts/no-unused-vars": "off"
67
+ "import/no-default-export": "error"
73
68
  }
74
- })).override("antfu/jsonc/rules", config => ({
75
- ...config,
69
+ })).insertAfter("antfu/imports/rules", {
70
+ name: "vdustr/allow-default-export",
76
71
  rules: {
77
- ...config.rules,
78
- "jsonc/sort-keys": "error"
72
+ "import/no-default-export": "off"
79
73
  },
80
- files: [...(config.files ?? []), "**/*.code-workspace"],
81
- ignores: [...(config.ignores ?? []),
82
- /**
83
- * Lint `package.json` files with `eslint-plugin-package-json` instead.
84
- */
85
- "**/package.json"]
86
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json").override("antfu/react/rules", config => ({
87
- ...config,
88
- plugins: {
89
- ...config.plugins,
90
- "react-compiler": reactCompilerPlugin
91
- },
92
- rules: {
93
- ...config.rules,
94
- "react-compiler/react-compiler": "error",
74
+ files: ["**/*.config.*",
75
+ // Single file components
76
+ "**/*.vue", "**/*.svelte"]
77
+ });
78
+ if (typescriptEnabled) {
79
+ config = config.override("antfu/typescript/rules", config2 => ({
80
+ ...config2,
81
+ rules: {
82
+ ...config2.rules,
83
+ "ts/array-type": ["error", {
84
+ default: "generic"
85
+ }],
86
+ /**
87
+ * Namespaces are useful for centralizing the management of types. Just avoid
88
+ * overusing them with runtime code.
89
+ *
90
+ * - References:
91
+ * - <https://x.com/mattpocockuk/status/1805606072167940167>
92
+ */
93
+ "ts/no-namespace": "off",
94
+ "ts/no-redeclare": "off",
95
+ /**
96
+ * Check for unused variables in TypeScript.
97
+ */
98
+ "ts/no-unused-vars": "off"
99
+ }
100
+ }));
101
+ }
102
+ if (jsoncEnabled) {
103
+ config = config.override("antfu/jsonc/rules", config2 => ({
104
+ ...config2,
105
+ rules: {
106
+ ...config2.rules,
107
+ "jsonc/sort-keys": "error"
108
+ },
109
+ files: [...(config2.files ?? []), "**/*.code-workspace"],
110
+ ignores: [...(config2.ignores ?? []),
95
111
  /**
96
- * Not all destructuring assignments are more readable than their alternatives.
112
+ * Lint `package.json` files with `eslint-plugin-package-json` instead.
97
113
  */
98
- "react/prefer-destructuring-assignment": "off"
99
- }
100
- }));
114
+ "**/package.json"]
115
+ })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
116
+ }
117
+ if (reactEnabled) {
118
+ config = config.override("antfu/react/rules", config2 => ({
119
+ ...config2,
120
+ plugins: {
121
+ ...config2.plugins,
122
+ "react-compiler": reactCompilerPlugin
123
+ },
124
+ rules: {
125
+ ...config2.rules,
126
+ "react-compiler/react-compiler": "error",
127
+ /**
128
+ * Not all destructuring assignments are more readable than their alternatives.
129
+ */
130
+ "react/prefer-destructuring-assignment": "off"
131
+ }
132
+ }));
133
+ }
134
+ if (storybookEnabled) {
135
+ config = config.override("storybook:csf:stories-rules", config2 => ({
136
+ ...config2,
137
+ rules: {
138
+ ...config2.rules,
139
+ "import/no-default-export": "off"
140
+ }
141
+ }));
142
+ }
143
+ return config;
101
144
  };
102
145
  exports.vdustr = vdustr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vp-tw/eslint-config",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "ViPro's ESLint configuration",
5
5
  "homepage": "https://github.com/vdustr/eslint-config",
6
6
  "author": {
@@ -1,6 +1,7 @@
1
1
  import type { ESLint } from "eslint";
2
2
  import { rules as mdxRules } from "eslint-plugin-mdx/lib/rules";
3
- import reactCompiler from "eslint-plugin-react-compiler";
3
+ // eslint-disable-next-line import/no-namespace -- This is a cjs module.
4
+ import * as reactCompiler from "eslint-plugin-react-compiler";
4
5
  import storybook from "eslint-plugin-storybook";
5
6
  import { pluginsToRulesDTS } from "eslint-typegen/core";
6
7
  import fs from "fs-extra";
@@ -1,9 +1,9 @@
1
1
  import type { TypedFlatConfigItem } from "@antfu/eslint-config";
2
2
  import type { DistributiveOmit } from "@mui/types";
3
- import { defaultPluginRenaming, renameRules } from "@antfu/eslint-config";
4
3
 
5
4
  // eslint-disable-next-line import/no-namespace -- `mdx` exports the plugin as a namespace.
6
5
  import * as mdxPlugin from "eslint-plugin-mdx";
6
+ import { renameRules } from "../utils/renameRules";
7
7
 
8
8
  namespace mdx {
9
9
  export interface Options
@@ -20,18 +20,15 @@ const mdx = ({
20
20
  }: mdx.Options = {}) => {
21
21
  const flatCodeBlocksOptions: TypedFlatConfigItem =
22
22
  typeof flatCodeBlocks !== "object" ? {} : flatCodeBlocks;
23
- return [
23
+ const configs: Array<TypedFlatConfigItem> = [
24
24
  {
25
25
  name: "vdustr/mdx",
26
26
  ...mdxPlugin.flat,
27
27
  ...options,
28
28
  rules: {
29
- ...renameRules(
30
- {
31
- ...mdxPlugin.flat.rules,
32
- },
33
- defaultPluginRenaming,
34
- ),
29
+ ...renameRules({
30
+ ...mdxPlugin.flat.rules,
31
+ }),
35
32
  ...options.rules,
36
33
  },
37
34
  processor: mdxPlugin.createRemarkProcessor({
@@ -50,17 +47,15 @@ const mdx = ({
50
47
  ...mdxPlugin.flatCodeBlocks,
51
48
  ...flatCodeBlocksOptions,
52
49
  rules: {
53
- ...renameRules(
54
- {
55
- ...mdxPlugin.flatCodeBlocks.rules,
56
- },
57
- defaultPluginRenaming,
58
- ),
50
+ ...renameRules({
51
+ ...mdxPlugin.flatCodeBlocks.rules,
52
+ }),
59
53
  ...flatCodeBlocksOptions.rules,
60
54
  },
61
55
  } satisfies TypedFlatConfigItem,
62
56
  ]),
63
- ] satisfies Array<TypedFlatConfigItem>;
57
+ ];
58
+ return configs;
64
59
  };
65
60
 
66
61
  export { mdx };
package/src/vdustr.ts CHANGED
@@ -1,14 +1,15 @@
1
+ // eslint-disable-next-line import/no-empty-named-blocks -- Type only import.
2
+ import type {} from "./eslint-typegen";
1
3
  import type { Config } from "./types";
2
4
  import antfu from "@antfu/eslint-config";
3
- import packageJson from "eslint-plugin-package-json/configs/recommended";
4
5
 
6
+ import packageJson from "eslint-plugin-package-json/configs/recommended";
5
7
  // eslint-disable-next-line import/no-namespace -- This is a cjs module.
6
8
  import * as reactCompilerPlugin from "eslint-plugin-react-compiler";
7
9
  import { isPackageExists } from "local-pkg";
8
10
  import { mdx } from "./configs/mdx";
9
11
  import { prettier } from "./configs/prettier";
10
12
  import { storybook } from "./configs/storybook";
11
- import "./eslint-typegen.d";
12
13
 
13
14
  type Options = NonNullable<Parameters<typeof antfu>[0]> & {
14
15
  mdx?: boolean | mdx.Options;
package/tsconfig.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "exclude": ["configs", "./*.ts", "src/lib"],
2
+ "exclude": ["scripts", "./*.ts", "src/lib"],
3
3
  "extends": ["@vp-tw/tsconfig/base/bundler/tsconfig"]
4
4
  }