@vp-tw/eslint-config 0.0.5 → 0.0.7

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
@@ -7,9 +7,43 @@ ViPro's ESLint configuration.
7
7
  - [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier)
8
8
  - [eslint-mdx](https://github.com/mdx-js/eslint-mdx).
9
9
  - [eslint-plugin-storybook](https://github.com/storybookjs/eslint-plugin-storybook)
10
+ - [eslint-plugin-react-compiler](https://www.npmjs.com/package/eslint-plugin-react-compiler)
10
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).
11
12
 
12
- Click [here](https://vdustr.dev/eslint-config) to preview the ESLint inspection.
13
+ Check [here](https://vdustr.dev/eslint-config) to preview the ESLint inspection.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pnpm i -D @vp-tw/eslint-config
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Simlar to [antfu/eslint-config](https://github.com/antfu/eslint-config) but with additional options:
24
+
25
+ ```ts
26
+ // eslint.config.ts
27
+ import { fileURLToPath } from "node:url";
28
+
29
+ import { includeIgnoreFile } from "@eslint/compat";
30
+ import { vdustr } from "@vp-tw/eslint-config";
31
+ import path from "pathe";
32
+
33
+ const __filename = fileURLToPath(import.meta.url);
34
+ const __dirname = path.dirname(__filename);
35
+ const prettierignorePath = path.resolve(__dirname, ".prettierignore");
36
+
37
+ export default vdustr(
38
+ {
39
+ // `stylistic` has been removed in favor of `prettier`.
40
+ // stylistic: true,
41
+ storybook: true,
42
+ mdx: true,
43
+ },
44
+ includeIgnoreFile(prettierignorePath),
45
+ );
46
+ ```
13
47
 
14
48
  ## License
15
49
 
@@ -1,7 +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
- type Options = NonNullable<Parameters<typeof antfu>[0]> & {
4
+ type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
5
5
  mdx?: boolean | mdx.Options;
6
6
  storybook?: boolean;
7
7
  };
@@ -10,22 +10,22 @@ const vdustr = (options, ...userConfigs) => {
10
10
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
11
11
  const reactEnabled = Boolean(options?.react ?? false);
12
12
  const storybookEnabled = Boolean(options?.storybook ?? false);
13
- const mdxOptions = options?.mdx ?? true;
14
- const defaultConfigs = [
15
- ...!jsoncEnabled ? [] : [packageJson],
16
- ...!mdxOptions ? [] : mdx({
17
- ...typeof mdxOptions !== "object" ? null : mdxOptions
18
- }),
19
- ...!storybookEnabled ? [] : storybook,
20
- prettier
21
- ];
13
+ const mdxEnabled = Boolean(options?.mdx ?? false);
14
+ const mdxOptions = {
15
+ ...typeof options?.mdx !== "object" ? null : options.mdx
16
+ };
17
+ const mdxFlatCodeBlocksEnabled = Boolean(
18
+ mdxOptions?.flatCodeBlocks ?? true
19
+ );
20
+ const mdxFlatCodeBlocksOptions = {
21
+ ...typeof mdxOptions?.flatCodeBlocks !== "object" ? null : mdxOptions.flatCodeBlocks
22
+ };
22
23
  let config = antfu(
23
24
  {
24
25
  // We use `prettier`.
25
26
  stylistic: false,
26
27
  ...options
27
28
  },
28
- ...defaultConfigs,
29
29
  ...userConfigs
30
30
  );
31
31
  config = config.override("antfu/javascript/rules", (config2) => ({
@@ -72,6 +72,7 @@ const vdustr = (options, ...userConfigs) => {
72
72
  "import/no-default-export": "off"
73
73
  },
74
74
  files: [
75
+ // Configuration files
75
76
  "**/*.config.*",
76
77
  // Single file components
77
78
  "**/*.vue",
@@ -115,7 +116,7 @@ const vdustr = (options, ...userConfigs) => {
115
116
  */
116
117
  "**/package.json"
117
118
  ]
118
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
119
+ })).insertAfter("antfu/jsonc/rules", packageJson).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
119
120
  }
120
121
  if (reactEnabled) {
121
122
  config = config.override("antfu/react/rules", (config2) => ({
@@ -135,7 +136,7 @@ const vdustr = (options, ...userConfigs) => {
135
136
  }));
136
137
  }
137
138
  if (storybookEnabled) {
138
- config = config.override("storybook:csf:stories-rules", (config2) => ({
139
+ config = config.append(storybook).override("storybook:csf:stories-rules", (config2) => ({
139
140
  ...config2,
140
141
  rules: {
141
142
  ...config2.rules,
@@ -143,6 +144,21 @@ const vdustr = (options, ...userConfigs) => {
143
144
  }
144
145
  }));
145
146
  }
147
+ if (mdxEnabled) {
148
+ config = config.append(
149
+ mdx({
150
+ ...mdxOptions,
151
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
152
+ ...mdxFlatCodeBlocksOptions,
153
+ rules: {
154
+ "import/no-default-export": "off",
155
+ ...mdxFlatCodeBlocksOptions?.rules
156
+ }
157
+ }
158
+ })
159
+ );
160
+ }
161
+ config = config.append(prettier);
146
162
  return config;
147
163
  };
148
164
  export { vdustr };
package/dist/vdustr.d.ts CHANGED
@@ -1,7 +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
- type Options = NonNullable<Parameters<typeof antfu>[0]> & {
4
+ type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
5
5
  mdx?: boolean | mdx.Options;
6
6
  storybook?: boolean;
7
7
  };
package/dist/vdustr.js CHANGED
@@ -17,15 +17,19 @@ const vdustr = (options, ...userConfigs) => {
17
17
  const jsoncEnabled = Boolean(options?.jsonc ?? true);
18
18
  const reactEnabled = Boolean(options?.react ?? false);
19
19
  const storybookEnabled = Boolean(options?.storybook ?? false);
20
- const mdxOptions = options?.mdx ?? true;
21
- const defaultConfigs = [...(!jsoncEnabled ? [] : [_recommended.default]), ...(!mdxOptions ? [] : (0, _mdx.mdx)({
22
- ...(typeof mdxOptions !== "object" ? null : mdxOptions)
23
- })), ...(!storybookEnabled ? [] : _storybook.storybook), _prettier.prettier];
20
+ const mdxEnabled = Boolean(options?.mdx ?? false);
21
+ const mdxOptions = {
22
+ ...(typeof options?.mdx !== "object" ? null : options.mdx)
23
+ };
24
+ const mdxFlatCodeBlocksEnabled = Boolean(mdxOptions?.flatCodeBlocks ?? true);
25
+ const mdxFlatCodeBlocksOptions = {
26
+ ...(typeof mdxOptions?.flatCodeBlocks !== "object" ? null : mdxOptions.flatCodeBlocks)
27
+ };
24
28
  let config = (0, _eslintConfig.default)({
25
29
  // We use `prettier`.
26
30
  stylistic: false,
27
31
  ...options
28
- }, ...defaultConfigs, ...userConfigs);
32
+ }, ...userConfigs);
29
33
  config = config.override("antfu/javascript/rules", config2 => ({
30
34
  ...config2,
31
35
  rules: {
@@ -69,7 +73,9 @@ const vdustr = (options, ...userConfigs) => {
69
73
  rules: {
70
74
  "import/no-default-export": "off"
71
75
  },
72
- files: ["**/*.config.*",
76
+ files: [
77
+ // Configuration files
78
+ "**/*.config.*",
73
79
  // Single file components
74
80
  "**/*.vue", "**/*.svelte"]
75
81
  });
@@ -110,7 +116,7 @@ const vdustr = (options, ...userConfigs) => {
110
116
  * Lint `package.json` files with `eslint-plugin-package-json` instead.
111
117
  */
112
118
  "**/package.json"]
113
- })).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
119
+ })).insertAfter("antfu/jsonc/rules", _recommended.default).remove("antfu/sort/package-json").remove("antfu/sort/tsconfig-json");
114
120
  }
115
121
  if (reactEnabled) {
116
122
  config = config.override("antfu/react/rules", config2 => ({
@@ -130,7 +136,7 @@ const vdustr = (options, ...userConfigs) => {
130
136
  }));
131
137
  }
132
138
  if (storybookEnabled) {
133
- config = config.override("storybook:csf:stories-rules", config2 => ({
139
+ config = config.append(_storybook.storybook).override("storybook:csf:stories-rules", config2 => ({
134
140
  ...config2,
135
141
  rules: {
136
142
  ...config2.rules,
@@ -138,6 +144,19 @@ const vdustr = (options, ...userConfigs) => {
138
144
  }
139
145
  }));
140
146
  }
147
+ if (mdxEnabled) {
148
+ config = config.append((0, _mdx.mdx)({
149
+ ...mdxOptions,
150
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled ? false : {
151
+ ...mdxFlatCodeBlocksOptions,
152
+ rules: {
153
+ "import/no-default-export": "off",
154
+ ...mdxFlatCodeBlocksOptions?.rules
155
+ }
156
+ }
157
+ }));
158
+ }
159
+ config = config.append(_prettier.prettier);
141
160
  return config;
142
161
  };
143
162
  exports.vdustr = vdustr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vp-tw/eslint-config",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "ViPro's ESLint configuration",
5
5
  "homepage": "https://github.com/vdustr/eslint-config",
6
6
  "author": {
package/src/vdustr.ts CHANGED
@@ -11,7 +11,7 @@ import { prettier } from "./configs/prettier";
11
11
  import { storybook } from "./configs/storybook";
12
12
  import { reactCompiler } from "./lib/eslint-plugin-react-compiler";
13
13
 
14
- type Options = NonNullable<Parameters<typeof antfu>[0]> & {
14
+ type Options = Omit<NonNullable<Parameters<typeof antfu>[0]>, "stylistic"> & {
15
15
  mdx?: boolean | mdx.Options;
16
16
  storybook?: boolean;
17
17
  };
@@ -36,33 +36,12 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
36
36
  ? null
37
37
  : mdxOptions.flatCodeBlocks),
38
38
  };
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
39
  let config = antfu(
60
40
  {
61
41
  // We use `prettier`.
62
42
  stylistic: false,
63
43
  ...options,
64
44
  },
65
- ...defaultConfigs,
66
45
  ...userConfigs,
67
46
  );
68
47
 
@@ -120,7 +99,9 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
120
99
  "import/no-default-export": "off",
121
100
  },
122
101
  files: [
102
+ // Configuration files
123
103
  "**/*.config.*",
104
+
124
105
  // Single file components
125
106
  "**/*.vue",
126
107
  "**/*.svelte",
@@ -169,6 +150,7 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
169
150
  "**/package.json",
170
151
  ],
171
152
  }))
153
+ .insertAfter("antfu/jsonc/rules", packageJson)
172
154
  .remove("antfu/sort/package-json")
173
155
  .remove("antfu/sort/tsconfig-json");
174
156
  }
@@ -193,15 +175,36 @@ const vdustr = (options?: Options, ...userConfigs: Array<Config>) => {
193
175
  }
194
176
 
195
177
  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
- }));
178
+ config = config
179
+ .append(storybook)
180
+ .override("storybook:csf:stories-rules", (config) => ({
181
+ ...config,
182
+ rules: {
183
+ ...config.rules,
184
+ "import/no-default-export": "off",
185
+ },
186
+ }));
203
187
  }
204
188
 
189
+ if (mdxEnabled) {
190
+ config = config.append(
191
+ mdx({
192
+ ...mdxOptions,
193
+ flatCodeBlocks: !mdxFlatCodeBlocksEnabled
194
+ ? false
195
+ : {
196
+ ...mdxFlatCodeBlocksOptions,
197
+ rules: {
198
+ "import/no-default-export": "off",
199
+ ...mdxFlatCodeBlocksOptions?.rules,
200
+ },
201
+ },
202
+ }),
203
+ );
204
+ }
205
+
206
+ config = config.append(prettier);
207
+
205
208
  return config;
206
209
  };
207
210