@vp-tw/eslint-config 0.0.1 → 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.
@@ -17,10 +17,90 @@ export interface RuleOptions {
17
17
  * Surfaces diagnostics from React Forget
18
18
  */
19
19
  'react-compiler/react-compiler'?: Linter.RuleEntry<ReactCompilerReactCompiler>
20
+ /**
21
+ * Interactions should be awaited
22
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/await-interactions.md
23
+ */
24
+ 'storybook/await-interactions'?: Linter.RuleEntry<[]>
25
+ /**
26
+ * Pass a context when invoking play function of another story
27
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/context-in-play-function.md
28
+ */
29
+ 'storybook/context-in-play-function'?: Linter.RuleEntry<[]>
30
+ /**
31
+ * The component property should be set
32
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/csf-component.md
33
+ */
34
+ 'storybook/csf-component'?: Linter.RuleEntry<[]>
35
+ /**
36
+ * Story files should have a default export
37
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/default-exports.md
38
+ */
39
+ 'storybook/default-exports'?: Linter.RuleEntry<[]>
40
+ /**
41
+ * Deprecated hierarchy separator in title property
42
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/hierarchy-separator.md
43
+ */
44
+ 'storybook/hierarchy-separator'?: Linter.RuleEntry<[]>
45
+ /**
46
+ * Meta should only have inline properties
47
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/meta-inline-properties.md
48
+ */
49
+ 'storybook/meta-inline-properties'?: Linter.RuleEntry<StorybookMetaInlineProperties>
50
+ /**
51
+ * A story should not have a redundant name property
52
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-redundant-story-name.md
53
+ */
54
+ 'storybook/no-redundant-story-name'?: Linter.RuleEntry<[]>
55
+ /**
56
+ * storiesOf is deprecated and should not be used
57
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-stories-of.md
58
+ */
59
+ 'storybook/no-stories-of'?: Linter.RuleEntry<[]>
60
+ /**
61
+ * Do not define a title in meta
62
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-title-property-in-meta.md
63
+ */
64
+ 'storybook/no-title-property-in-meta'?: Linter.RuleEntry<[]>
65
+ /**
66
+ * This rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name.
67
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-uninstalled-addons.md
68
+ */
69
+ 'storybook/no-uninstalled-addons'?: Linter.RuleEntry<StorybookNoUninstalledAddons>
70
+ /**
71
+ * Stories should use PascalCase
72
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/prefer-pascal-case.md
73
+ */
74
+ 'storybook/prefer-pascal-case'?: Linter.RuleEntry<[]>
75
+ /**
76
+ * A story file must contain at least one story export
77
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/story-exports.md
78
+ */
79
+ 'storybook/story-exports'?: Linter.RuleEntry<[]>
80
+ /**
81
+ * Use expect from `@storybook/test` or `@storybook/jest`
82
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/use-storybook-expect.md
83
+ */
84
+ 'storybook/use-storybook-expect'?: Linter.RuleEntry<[]>
85
+ /**
86
+ * Do not use testing-library directly on stories
87
+ * @see https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/use-storybook-testing-library.md
88
+ */
89
+ 'storybook/use-storybook-testing-library'?: Linter.RuleEntry<[]>
20
90
  }
21
91
 
22
92
  /* ======= Declarations ======= */
23
93
  // ----- react-compiler/react-compiler -----
24
94
  type ReactCompilerReactCompiler = []|[{
25
95
  [k: string]: unknown | undefined
96
+ }]
97
+ // ----- storybook/meta-inline-properties -----
98
+ type StorybookMetaInlineProperties = []|[{
99
+ csfVersion?: number
100
+ }]
101
+ // ----- storybook/no-uninstalled-addons -----
102
+ type StorybookNoUninstalledAddons = []|[{
103
+ packageJsonLocation?: string
104
+ ignore?: string[]
105
+ [k: string]: unknown | undefined
26
106
  }]
package/src/tsconfig.json CHANGED
@@ -1,4 +1,3 @@
1
1
  {
2
- "extends": ["@vp-tw/tsconfig/base/bundler/tsconfig"],
3
- "include": [".", "../lib"]
2
+ "extends": ["@vp-tw/tsconfig/base/bundler/tsconfig"]
4
3
  }
@@ -0,0 +1,7 @@
1
+ import { defaultPluginRenaming, renameRules } from "@antfu/eslint-config";
2
+
3
+ function renameRulesInternal(rules: Parameters<typeof renameRules>[0]) {
4
+ return renameRules(rules, defaultPluginRenaming);
5
+ }
6
+
7
+ export { renameRulesInternal as renameRules };
package/src/vdustr.ts CHANGED
@@ -1,19 +1,27 @@
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";
7
+ // eslint-disable-next-line import/no-namespace -- This is a cjs module.
5
8
  import * as reactCompilerPlugin from "eslint-plugin-react-compiler";
9
+ import { isPackageExists } from "local-pkg";
6
10
  import { mdx } from "./configs/mdx";
7
11
  import { prettier } from "./configs/prettier";
8
- import "./eslint-typegen.d";
12
+ import { storybook } from "./configs/storybook";
9
13
 
10
14
  type Options = NonNullable<Parameters<typeof antfu>[0]> & {
11
15
  mdx?: boolean | mdx.Options;
16
+ storybook?: boolean;
12
17
  };
13
18
 
14
19
  const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
15
- const mdxOptions = options?.mdx ?? true;
20
+ const typescriptEnabled = isPackageExists("typescript");
16
21
  const jsoncEnabled: boolean = Boolean(options?.jsonc ?? true);
22
+ const reactEnabled: boolean = Boolean(options?.react ?? false);
23
+ const storybookEnabled: boolean = Boolean(options?.storybook ?? false);
24
+ const mdxOptions = options?.mdx ?? true;
17
25
  type Config = NonNullable<Parameters<typeof antfu>[1]>;
18
26
  const defaultConfigs: Array<Config> = [
19
27
  ...(!jsoncEnabled ? [] : [packageJson]),
@@ -22,9 +30,10 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
22
30
  : mdx({
23
31
  ...(typeof mdxOptions !== "object" ? null : mdxOptions),
24
32
  })),
33
+ ...(!storybookEnabled ? [] : storybook),
25
34
  prettier,
26
35
  ];
27
- return antfu(
36
+ let config = antfu(
28
37
  {
29
38
  // We use `prettier`.
30
39
  stylistic: false,
@@ -32,7 +41,9 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
32
41
  },
33
42
  ...defaultConfigs,
34
43
  ...userConfigs,
35
- )
44
+ );
45
+
46
+ config = config
36
47
  .override("antfu/javascript/rules", (config) => ({
37
48
  ...config,
38
49
  rules: {
@@ -61,9 +72,40 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
61
72
  * Forbid `import {} from "module"`.
62
73
  */
63
74
  "import/no-empty-named-blocks": "error",
75
+
76
+ /**
77
+ * Wildcard imports can prevent tree shaking and cause name conflicts.
78
+ * Consider using named imports instead.
79
+ */
80
+ "import/no-namespace": "error",
81
+
82
+ /**
83
+ * Enforcing named exports improves consistency, enhances auto-completion and refactoring, and avoids issues
84
+ * with default export renaming. Additionally, default exports might lead to different behavior when transformed
85
+ * to CJS.
86
+ */
87
+ "import/no-default-export": "error",
64
88
  },
65
89
  }))
66
- .override("antfu/typescript/rules", (config) => ({
90
+
91
+ /**
92
+ * Allow default exports in certain files.
93
+ */
94
+ .insertAfter("antfu/imports/rules", {
95
+ name: "vdustr/allow-default-export",
96
+ rules: {
97
+ "import/no-default-export": "off",
98
+ },
99
+ files: [
100
+ "**/*.config.*",
101
+ // Single file components
102
+ "**/*.vue",
103
+ "**/*.svelte",
104
+ ],
105
+ });
106
+
107
+ if (typescriptEnabled) {
108
+ config = config.override("antfu/typescript/rules", (config) => ({
67
109
  ...config,
68
110
  rules: {
69
111
  ...config.rules,
@@ -84,25 +126,32 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
84
126
  */
85
127
  "ts/no-unused-vars": "off",
86
128
  },
87
- }))
88
- .override("antfu/jsonc/rules", (config) => ({
89
- ...config,
90
- rules: {
91
- ...config.rules,
92
- "jsonc/sort-keys": "error",
93
- },
94
- files: [...(config.files ?? []), "**/*.code-workspace"],
95
- ignores: [
96
- ...(config.ignores ?? []),
97
- /**
98
- * Lint `package.json` files with `eslint-plugin-package-json` instead.
99
- */
100
- "**/package.json",
101
- ],
102
- }))
103
- .remove("antfu/sort/package-json")
104
- .remove("antfu/sort/tsconfig-json")
105
- .override("antfu/react/rules", (config) => ({
129
+ }));
130
+ }
131
+
132
+ if (jsoncEnabled) {
133
+ config = config
134
+ .override("antfu/jsonc/rules", (config) => ({
135
+ ...config,
136
+ rules: {
137
+ ...config.rules,
138
+ "jsonc/sort-keys": "error",
139
+ },
140
+ files: [...(config.files ?? []), "**/*.code-workspace"],
141
+ ignores: [
142
+ ...(config.ignores ?? []),
143
+ /**
144
+ * Lint `package.json` files with `eslint-plugin-package-json` instead.
145
+ */
146
+ "**/package.json",
147
+ ],
148
+ }))
149
+ .remove("antfu/sort/package-json")
150
+ .remove("antfu/sort/tsconfig-json");
151
+ }
152
+
153
+ if (reactEnabled) {
154
+ config = config.override("antfu/react/rules", (config) => ({
106
155
  ...config,
107
156
  plugins: {
108
157
  ...config.plugins,
@@ -118,6 +167,19 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
118
167
  "react/prefer-destructuring-assignment": "off",
119
168
  },
120
169
  }));
170
+ }
171
+
172
+ if (storybookEnabled) {
173
+ config = config.override("storybook:csf:stories-rules", (config) => ({
174
+ ...config,
175
+ rules: {
176
+ ...config.rules,
177
+ "import/no-default-export": "off",
178
+ },
179
+ }));
180
+ }
181
+
182
+ return config;
121
183
  };
122
184
 
123
185
  export { vdustr };
package/tsconfig.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "exclude": ["dist", "src", "node_modules"],
2
+ "exclude": ["scripts", "./*.ts", "src/lib"],
3
3
  "extends": ["@vp-tw/tsconfig/base/bundler/tsconfig"]
4
4
  }