@icebreakers/eslint-config 2.0.0 → 2.0.1

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
@@ -10,7 +10,7 @@
10
10
 
11
11
  - Node.js 18 or newer
12
12
  - ESLint 9 with flat config support
13
- - Install optional peer plugins when you turn on Tailwind (`eslint-plugin-tailwindcss` or `eslint-plugin-better-tailwindcss`), MDX (`eslint-plugin-mdx`), Stylelint bridge (`eslint-plugin-better-stylelint`), or UnoCSS (`@unocss/eslint-plugin`)
13
+ - Install optional peer plugins when you turn on Tailwind (`eslint-plugin-tailwindcss` or `eslint-plugin-better-tailwindcss`), MDX (`eslint-plugin-mdx`), or UnoCSS (`@unocss/eslint-plugin`)
14
14
 
15
15
  ## Installation
16
16
 
@@ -74,24 +74,42 @@ export default icebreaker({
74
74
 
75
75
  ### Stylelint Bridge
76
76
 
77
- Set `stylelint: true` to bridge Stylelint diagnostics into ESLint for
78
- `*.css`, `*.scss`, and `.vue` style blocks:
77
+ `@icebreakers/eslint-config` bundles the Stylelint bridge and uses
78
+ `@icebreakers/stylelint-config` as the default Stylelint preset when you opt in.
79
+ The bridge is still disabled by default. Turn it on with `stylelint: true` to
80
+ lint `*.css`, `*.scss`, and `.vue` style blocks through ESLint:
79
81
 
80
- ```bash
81
- pnpm add -D eslint-plugin-better-stylelint
82
+ ```ts
83
+ import { icebreaker } from '@icebreakers/eslint-config'
84
+
85
+ export default icebreaker({
86
+ vue: true,
87
+ stylelint: true,
88
+ })
82
89
  ```
83
90
 
91
+ You can also inline Stylelint preset options directly in `eslint.config.ts`:
92
+
84
93
  ```ts
85
94
  import { icebreaker } from '@icebreakers/eslint-config'
86
95
 
87
96
  export default icebreaker({
88
97
  vue: true,
89
- stylelint: true,
98
+ stylelint: {
99
+ cwd: process.cwd(),
100
+ presets: {
101
+ order: false,
102
+ },
103
+ rules: {
104
+ 'color-named': 'never',
105
+ },
106
+ },
90
107
  })
91
108
  ```
92
109
 
93
- You can also pass `stylelint: { cwd: '/path/to/project' }` if Stylelint should
94
- resolve its config from a different working directory.
110
+ `stylelint.cwd` changes the resolution root, and the remaining fields follow
111
+ the `@icebreakers/stylelint-config` options (`presets`, `tailwindcssPreset`,
112
+ `ignores`, `extends`, `overrides`, `rules`).
95
113
 
96
114
  ### NestJS Projects
97
115
 
package/README.zh.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  - Node.js 18 或更高版本
10
10
  - 支持 Flat Config 的 ESLint 9
11
- - 如需启用 Tailwind、MDX、Stylelint 桥接、UnoCSS 等,可安装对应的可选依赖:`eslint-plugin-tailwindcss` / `eslint-plugin-better-tailwindcss`、`eslint-plugin-mdx`、`eslint-plugin-better-stylelint`、`@unocss/eslint-plugin`
11
+ - 如需启用 Tailwind、MDX、UnoCSS 等,可安装对应的可选依赖:`eslint-plugin-tailwindcss` / `eslint-plugin-better-tailwindcss`、`eslint-plugin-mdx`、`@unocss/eslint-plugin`
12
12
 
13
13
  ## 安装
14
14
 
@@ -72,16 +72,14 @@ export default icebreaker({
72
72
 
73
73
  ### Stylelint 桥接
74
74
 
75
+ `@icebreakers/eslint-config` 已内置 Stylelint bridge,并在启用时默认使用
76
+ `@icebreakers/stylelint-config` 作为 Stylelint 预设;但 bridge 默认仍是关闭的。
75
77
  设置 `stylelint: true` 后,会把 Stylelint 诊断桥接到 ESLint,用于:
76
78
 
77
79
  - `*.css`
78
80
  - `*.scss`
79
81
  - `.vue` 文件里的 `<style>` 块
80
82
 
81
- ```bash
82
- pnpm add -D eslint-plugin-better-stylelint
83
- ```
84
-
85
83
  ```ts
86
84
  import { icebreaker } from '@icebreakers/eslint-config'
87
85
 
@@ -91,18 +89,29 @@ export default icebreaker({
91
89
  })
92
90
  ```
93
91
 
94
- 如果 Stylelint 需要从其它目录解析配置,也可以传:
92
+ 也可以直接把 Stylelint 预设配置写进 `eslint.config.ts`:
95
93
 
96
94
  ```ts
97
95
  import { icebreaker } from '@icebreakers/eslint-config'
98
96
 
99
97
  export default icebreaker({
98
+ vue: true,
100
99
  stylelint: {
101
- cwd: '/path/to/project',
100
+ cwd: process.cwd(),
101
+ presets: {
102
+ order: false,
103
+ },
104
+ rules: {
105
+ 'color-named': 'never',
106
+ },
102
107
  },
103
108
  })
104
109
  ```
105
110
 
111
+ 其中 `stylelint.cwd` 用来指定配置解析根目录,其余字段沿用
112
+ `@icebreakers/stylelint-config` 的选项结构,例如 `presets`、
113
+ `tailwindcssPreset`、`ignores`、`extends`、`overrides`、`rules`。
114
+
106
115
  ### NestJS 项目
107
116
 
108
117
  建议在 Nest 项目中同时开启 `typescript` 与 `nestjs`,以便应用以下定制:
package/dist/index.cjs CHANGED
@@ -149,6 +149,9 @@ function getDefaultTypescriptOptions(opts) {
149
149
  }
150
150
  //#endregion
151
151
  //#region src/features.ts
152
+ function resolveStylelintConfigLoader() {
153
+ return require("url").pathToFileURL(__filename).href.endsWith(".ts") ? new URL("./stylelint.ts", require("url").pathToFileURL(__filename).href).href : new URL("./stylelint.js", require("url").pathToFileURL(__filename).href).href;
154
+ }
152
155
  function resolveTailwindPresets(option) {
153
156
  if (!option) return [];
154
157
  if (typeof option === "object") return [(0, antfu_exports.interopDefault)(import("eslint-plugin-better-tailwindcss")).then((eslintPluginBetterTailwindcss) => {
@@ -170,29 +173,37 @@ function resolveTailwindPresets(option) {
170
173
  return tailwind.configs["flat/recommended"];
171
174
  }), { rules: { "tailwindcss/no-custom-classname": "off" } }];
172
175
  }
176
+ function resolveStylelintBridgeOptions(option) {
177
+ const { cwd, ...stylelintConfigOptions } = typeof option === "object" ? option : {};
178
+ return {
179
+ ...cwd ? { cwd } : {},
180
+ configLoader: resolveStylelintConfigLoader(),
181
+ configOptions: stylelintConfigOptions
182
+ };
183
+ }
173
184
  function resolveStylelintBridgePresets(option) {
174
185
  if (!option) return [];
175
- const stylelintOptions = typeof option === "object" ? option : {};
176
- const pluginPromise = (0, antfu_exports.interopDefault)(import("eslint-plugin-better-stylelint"));
186
+ const pluginModulePromise = import("eslint-plugin-better-stylelint");
187
+ const stylelintOptions = resolveStylelintBridgeOptions(option);
177
188
  return [
178
- pluginPromise.then((plugin) => {
189
+ pluginModulePromise.then((pluginModule) => {
179
190
  return {
180
191
  files: ["**/*.{css,pcss,postcss}"],
181
- plugins: { stylelint: plugin },
182
- processor: "stylelint/css"
192
+ plugins: { stylelint: pluginModule.default },
193
+ processor: pluginModule.createStylelintProcessor(stylelintOptions)
183
194
  };
184
195
  }),
185
- pluginPromise.then((plugin) => {
196
+ pluginModulePromise.then((pluginModule) => {
186
197
  return {
187
198
  files: ["**/*.{scss,sass}"],
188
- plugins: { stylelint: plugin },
189
- processor: "stylelint/scss"
199
+ plugins: { stylelint: pluginModule.default },
200
+ processor: pluginModule.createStylelintProcessor(stylelintOptions)
190
201
  };
191
202
  }),
192
- pluginPromise.then((plugin) => {
203
+ pluginModulePromise.then((pluginModule) => {
193
204
  return {
194
205
  files: ["**/*.vue"],
195
- plugins: { stylelint: plugin },
206
+ plugins: { stylelint: pluginModule.default },
196
207
  rules: { "stylelint/stylelint": ["error", stylelintOptions] }
197
208
  };
198
209
  })
@@ -475,6 +486,7 @@ function icebreakerLegacy(options = {}, ...userConfigs) {
475
486
  return (0, antfu_exports.antfu)(...getPresets(options, "legacy"), ...userConfigs);
476
487
  }
477
488
  //#endregion
489
+ exports.__toESM = __toESM;
478
490
  exports.getPresets = getPresets;
479
491
  exports.icebreaker = icebreaker;
480
492
  exports.icebreakerLegacy = icebreakerLegacy;
package/dist/index.d.cts CHANGED
@@ -2922,9 +2922,10 @@ interface TailwindcssOption {
2922
2922
  tailwindConfig?: string;
2923
2923
  }
2924
2924
  type TailwindcssConfig = boolean | TailwindcssOption;
2925
- type StylelintBridgeConfig = boolean | {
2925
+ interface StylelintBridgeOption {
2926
2926
  cwd?: string;
2927
- };
2927
+ }
2928
+ type StylelintBridgeConfig = boolean | StylelintBridgeOption;
2928
2929
  type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2929
2930
  /**
2930
2931
  * Enable TailwindCSS support
@@ -2976,4 +2977,4 @@ declare function icebreakerLegacy(options?: UserDefinedOptions, ...userConfigs:
2976
2977
  //#region src/preset.d.ts
2977
2978
  declare function getPresets(options?: UserDefinedOptions, mode?: 'legacy'): [UserDefinedOptions, ...UserConfigItem[]];
2978
2979
  //#endregion
2979
- export { type ConfigNames, type FlatConfigComposer, type TailwindcssConfig, type TailwindcssOption, type TypedFlatConfigItem, type UserConfigItem, type UserDefinedOptions, getPresets, icebreaker, icebreakerLegacy };
2980
+ export { type ConfigNames, type FlatConfigComposer, type StylelintBridgeConfig, type StylelintBridgeOption, type TailwindcssConfig, type TailwindcssOption, type TypedFlatConfigItem, type UserConfigItem, type UserDefinedOptions, getPresets, icebreaker, icebreakerLegacy };
package/dist/index.d.ts CHANGED
@@ -2922,9 +2922,10 @@ interface TailwindcssOption {
2922
2922
  tailwindConfig?: string;
2923
2923
  }
2924
2924
  type TailwindcssConfig = boolean | TailwindcssOption;
2925
- type StylelintBridgeConfig = boolean | {
2925
+ interface StylelintBridgeOption {
2926
2926
  cwd?: string;
2927
- };
2927
+ }
2928
+ type StylelintBridgeConfig = boolean | StylelintBridgeOption;
2928
2929
  type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2929
2930
  /**
2930
2931
  * Enable TailwindCSS support
@@ -2976,4 +2977,4 @@ declare function icebreakerLegacy(options?: UserDefinedOptions, ...userConfigs:
2976
2977
  //#region src/preset.d.ts
2977
2978
  declare function getPresets(options?: UserDefinedOptions, mode?: 'legacy'): [UserDefinedOptions, ...UserConfigItem[]];
2978
2979
  //#endregion
2979
- export { type ConfigNames, type FlatConfigComposer, type TailwindcssConfig, type TailwindcssOption, type TypedFlatConfigItem, type UserConfigItem, type UserDefinedOptions, getPresets, icebreaker, icebreakerLegacy };
2980
+ export { type ConfigNames, type FlatConfigComposer, type StylelintBridgeConfig, type StylelintBridgeOption, type TailwindcssConfig, type TailwindcssOption, type TypedFlatConfigItem, type UserConfigItem, type UserDefinedOptions, getPresets, icebreaker, icebreakerLegacy };
package/dist/index.js CHANGED
@@ -140,6 +140,9 @@ function getDefaultTypescriptOptions(opts) {
140
140
  }
141
141
  //#endregion
142
142
  //#region src/features.ts
143
+ function resolveStylelintConfigLoader() {
144
+ return import.meta.url.endsWith(".ts") ? new URL("./stylelint.ts", import.meta.url).href : new URL("./stylelint.js", import.meta.url).href;
145
+ }
143
146
  function resolveTailwindPresets(option) {
144
147
  if (!option) return [];
145
148
  if (typeof option === "object") return [(0, antfu_exports.interopDefault)(import("eslint-plugin-better-tailwindcss")).then((eslintPluginBetterTailwindcss) => {
@@ -161,29 +164,37 @@ function resolveTailwindPresets(option) {
161
164
  return tailwind.configs["flat/recommended"];
162
165
  }), { rules: { "tailwindcss/no-custom-classname": "off" } }];
163
166
  }
167
+ function resolveStylelintBridgeOptions(option) {
168
+ const { cwd, ...stylelintConfigOptions } = typeof option === "object" ? option : {};
169
+ return {
170
+ ...cwd ? { cwd } : {},
171
+ configLoader: resolveStylelintConfigLoader(),
172
+ configOptions: stylelintConfigOptions
173
+ };
174
+ }
164
175
  function resolveStylelintBridgePresets(option) {
165
176
  if (!option) return [];
166
- const stylelintOptions = typeof option === "object" ? option : {};
167
- const pluginPromise = (0, antfu_exports.interopDefault)(import("eslint-plugin-better-stylelint"));
177
+ const pluginModulePromise = import("eslint-plugin-better-stylelint");
178
+ const stylelintOptions = resolveStylelintBridgeOptions(option);
168
179
  return [
169
- pluginPromise.then((plugin) => {
180
+ pluginModulePromise.then((pluginModule) => {
170
181
  return {
171
182
  files: ["**/*.{css,pcss,postcss}"],
172
- plugins: { stylelint: plugin },
173
- processor: "stylelint/css"
183
+ plugins: { stylelint: pluginModule.default },
184
+ processor: pluginModule.createStylelintProcessor(stylelintOptions)
174
185
  };
175
186
  }),
176
- pluginPromise.then((plugin) => {
187
+ pluginModulePromise.then((pluginModule) => {
177
188
  return {
178
189
  files: ["**/*.{scss,sass}"],
179
- plugins: { stylelint: plugin },
180
- processor: "stylelint/scss"
190
+ plugins: { stylelint: pluginModule.default },
191
+ processor: pluginModule.createStylelintProcessor(stylelintOptions)
181
192
  };
182
193
  }),
183
- pluginPromise.then((plugin) => {
194
+ pluginModulePromise.then((pluginModule) => {
184
195
  return {
185
196
  files: ["**/*.vue"],
186
- plugins: { stylelint: plugin },
197
+ plugins: { stylelint: pluginModule.default },
187
198
  rules: { "stylelint/stylelint": ["error", stylelintOptions] }
188
199
  };
189
200
  })
@@ -0,0 +1,9 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./index.cjs");
3
+ let _icebreakers_stylelint_config = require("@icebreakers/stylelint-config");
4
+ //#region src/stylelint.ts
5
+ function resolveStylelintConfig(options = {}) {
6
+ return (0, _icebreakers_stylelint_config.createStylelintConfig)(options);
7
+ }
8
+ //#endregion
9
+ exports.resolveStylelintConfig = resolveStylelintConfig;
@@ -0,0 +1,6 @@
1
+ import { IcebreakerStylelintOptions, IcebreakerStylelintOptions as IcebreakerStylelintOptions$1, createStylelintConfig } from "@icebreakers/stylelint-config";
2
+
3
+ //#region src/stylelint.d.ts
4
+ declare function resolveStylelintConfig(options?: IcebreakerStylelintOptions$1): ReturnType<typeof createStylelintConfig>;
5
+ //#endregion
6
+ export { type IcebreakerStylelintOptions, resolveStylelintConfig };
@@ -0,0 +1,6 @@
1
+ import { IcebreakerStylelintOptions, IcebreakerStylelintOptions as IcebreakerStylelintOptions$1, createStylelintConfig } from "@icebreakers/stylelint-config";
2
+
3
+ //#region src/stylelint.d.ts
4
+ declare function resolveStylelintConfig(options?: IcebreakerStylelintOptions$1): ReturnType<typeof createStylelintConfig>;
5
+ //#endregion
6
+ export { type IcebreakerStylelintOptions, resolveStylelintConfig };
@@ -0,0 +1,7 @@
1
+ import { createStylelintConfig } from "@icebreakers/stylelint-config";
2
+ //#region src/stylelint.ts
3
+ function resolveStylelintConfig(options = {}) {
4
+ return createStylelintConfig(options);
5
+ }
6
+ //#endregion
7
+ export { resolveStylelintConfig };
package/index.d.ts CHANGED
@@ -13,9 +13,14 @@ export interface TailwindcssOption {
13
13
  }
14
14
 
15
15
  export type TailwindcssConfig = boolean | TailwindcssOption
16
+ export interface StylelintBridgeOption {
17
+ cwd?: string
18
+ }
19
+ export type StylelintBridgeConfig = boolean | StylelintBridgeOption
16
20
 
17
21
  export type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem & {
18
22
  tailwindcss?: TailwindcssConfig
23
+ stylelint?: StylelintBridgeConfig
19
24
  mdx?: boolean
20
25
  a11y?: boolean
21
26
  nestjs?: boolean
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/eslint-config",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "description": "ESLint preset from Icebreaker's dev-configs",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -24,6 +24,11 @@
24
24
  "import": "./dist/index.js",
25
25
  "require": "./dist/index.cjs"
26
26
  },
27
+ "./stylelint": {
28
+ "types": "./dist/stylelint.d.ts",
29
+ "import": "./dist/stylelint.js",
30
+ "require": "./dist/stylelint.cjs"
31
+ },
27
32
  "./*": "./*"
28
33
  },
29
34
  "main": "./dist/index.cjs",
@@ -34,13 +39,9 @@
34
39
  "index.d.ts"
35
40
  ],
36
41
  "peerDependencies": {
37
- "eslint-plugin-pnpm": "^1.4.3",
38
- "eslint-plugin-better-stylelint": "0.1.0"
42
+ "eslint-plugin-pnpm": "^1.4.3"
39
43
  },
40
44
  "peerDependenciesMeta": {
41
- "eslint-plugin-better-stylelint": {
42
- "optional": true
43
- },
44
45
  "eslint-plugin-pnpm": {
45
46
  "optional": true
46
47
  }
@@ -56,7 +57,9 @@
56
57
  "eslint-plugin-react-hooks": "^7.0.1",
57
58
  "eslint-plugin-react-refresh": "^0.5.2",
58
59
  "eslint-plugin-tailwindcss": "3.18.2",
59
- "eslint-plugin-vuejs-accessibility": "^2.5.0"
60
+ "eslint-plugin-vuejs-accessibility": "^2.5.0",
61
+ "@icebreakers/stylelint-config": "2.1.0",
62
+ "eslint-plugin-better-stylelint": "0.1.1"
60
63
  },
61
64
  "optionalDependencies": {
62
65
  "@unocss/eslint-plugin": "66.6.7",
@@ -69,6 +72,8 @@
69
72
  "tsd": {
70
73
  "directory": "test-d",
71
74
  "compilerOptions": {
75
+ "module": "esnext",
76
+ "moduleResolution": "bundler",
72
77
  "skipLibCheck": true
73
78
  }
74
79
  },