@icebreakers/stylelint-config 2.1.2 → 2.2.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 +39 -2
- package/README.zh.md +38 -2
- package/dist/index.d.ts +13 -4
- package/dist/index.js +21 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,10 +31,13 @@ The CLI will create or update `.vscode/settings.json` with the proper `stylelint
|
|
|
31
31
|
// stylelint.config.ts
|
|
32
32
|
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
33
33
|
|
|
34
|
-
export default icebreaker(
|
|
34
|
+
export default icebreaker({
|
|
35
|
+
miniProgram: true,
|
|
36
|
+
})
|
|
35
37
|
```
|
|
36
38
|
|
|
37
|
-
`icebreaker()`
|
|
39
|
+
`icebreaker()` accepts the same options as `createStylelintConfig()`, so the
|
|
40
|
+
minimal Mini Program setup is a single call with `miniProgram: true`.
|
|
38
41
|
|
|
39
42
|
## Advanced Configuration
|
|
40
43
|
|
|
@@ -44,6 +47,7 @@ Use `createStylelintConfig` for fine-grained control over preset toggles, ignore
|
|
|
44
47
|
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
45
48
|
|
|
46
49
|
export default createStylelintConfig({
|
|
50
|
+
miniProgram: true,
|
|
47
51
|
tailwindcssPreset: 'recommended',
|
|
48
52
|
presets: {
|
|
49
53
|
vue: false, // disable Vue rules for pure SCSS projects
|
|
@@ -69,6 +73,7 @@ export default createStylelintConfig({
|
|
|
69
73
|
|
|
70
74
|
### Option Reference
|
|
71
75
|
|
|
76
|
+
- `miniProgram` – ignore Mini Program build outputs by default: `dist/**`, `.weapp-vite/**`, `node_modules/**`, `miniprogram_npm/**`
|
|
72
77
|
- `presets.scss` – include `stylelint-config-standard-scss` (default `true`)
|
|
73
78
|
- `presets.vue` – include `stylelint-config-recommended-vue/scss` (default `true`)
|
|
74
79
|
- `presets.order` – include `stylelint-config-recess-order` (default `true`)
|
|
@@ -87,6 +92,38 @@ Defaults include:
|
|
|
87
92
|
- Disallowing authored Tailwind utility selectors such as `.flex` or `.hover\:bg-red-500`
|
|
88
93
|
- Ignoring the `page` selector used by various platforms
|
|
89
94
|
|
|
95
|
+
### Mini Program Templates
|
|
96
|
+
|
|
97
|
+
#### Native Template Minimal Config
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
101
|
+
|
|
102
|
+
export default icebreaker({
|
|
103
|
+
miniProgram: true,
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Use a script such as:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
stylelint "**/*.{css,scss,wxss,vue}" --fix
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Vue / wevu Template Minimal Config
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
117
|
+
|
|
118
|
+
export default icebreaker({
|
|
119
|
+
miniProgram: true,
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This works for `.css`, `.scss`, `.wxss`, and Vue `<style>` blocks without
|
|
124
|
+
having to manually wire `postcss-html`, Vue overrides, or Mini Program ignore
|
|
125
|
+
paths.
|
|
126
|
+
|
|
90
127
|
## Tailwind Utility Selector Guard
|
|
91
128
|
|
|
92
129
|
By default this preset enables the plugin's `base` policy layer:
|
package/README.zh.md
CHANGED
|
@@ -29,10 +29,13 @@ npx @icebreakers/stylelint-config
|
|
|
29
29
|
// stylelint.config.ts
|
|
30
30
|
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
31
31
|
|
|
32
|
-
export default icebreaker(
|
|
32
|
+
export default icebreaker({
|
|
33
|
+
miniProgram: true,
|
|
34
|
+
})
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
`icebreaker()`
|
|
37
|
+
`icebreaker()` 现在可直接接收和 `createStylelintConfig()` 相同的选项;
|
|
38
|
+
对小程序模板来说,最小配置就是 `miniProgram: true`。
|
|
36
39
|
|
|
37
40
|
## 进阶配置
|
|
38
41
|
|
|
@@ -42,6 +45,7 @@ export default icebreaker()
|
|
|
42
45
|
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
43
46
|
|
|
44
47
|
export default createStylelintConfig({
|
|
48
|
+
miniProgram: true,
|
|
45
49
|
tailwindcssPreset: 'recommended',
|
|
46
50
|
presets: {
|
|
47
51
|
vue: false, // 纯 SCSS 项目无需 Vue 规则
|
|
@@ -67,6 +71,7 @@ export default createStylelintConfig({
|
|
|
67
71
|
|
|
68
72
|
### 配置说明
|
|
69
73
|
|
|
74
|
+
- `miniProgram`:默认忽略小程序常见产物目录:`dist/**`、`.weapp-vite/**`、`node_modules/**`、`miniprogram_npm/**`
|
|
70
75
|
- `presets.scss`:是否包含 `stylelint-config-standard-scss`,默认开启
|
|
71
76
|
- `presets.vue`:是否包含 `stylelint-config-recommended-vue/scss`,默认开启
|
|
72
77
|
- `presets.order`:是否包含 `stylelint-config-recess-order`,默认开启
|
|
@@ -85,6 +90,37 @@ export default createStylelintConfig({
|
|
|
85
90
|
- 禁止在手写样式中声明 `.flex`、`.hover\:bg-red-500` 这类 Tailwind 原子类选择器
|
|
86
91
|
- 忽略多端平台常见的 `page` 选择器
|
|
87
92
|
|
|
93
|
+
## 小程序模板推荐用法
|
|
94
|
+
|
|
95
|
+
### 原生小程序最小配置
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
99
|
+
|
|
100
|
+
export default icebreaker({
|
|
101
|
+
miniProgram: true,
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
推荐脚本:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
stylelint "**/*.{css,scss,wxss,vue}" --fix
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Vue / wevu 模板最小配置
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { icebreaker } from '@icebreakers/stylelint-config'
|
|
115
|
+
|
|
116
|
+
export default icebreaker({
|
|
117
|
+
miniProgram: true,
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
该配置默认兼容 `.css`、`.scss`、`.wxss` 以及 Vue SFC 的 `<style>`,
|
|
122
|
+
无需手动处理 `postcss-html`、Vue preset 或小程序 ignore 路径。
|
|
123
|
+
|
|
88
124
|
## Tailwind 原子类拦截
|
|
89
125
|
|
|
90
126
|
该预设默认启用 `stylelint-plugin-tailwindcss` 的 `base` 策略层,对应规则为:
|
package/dist/index.d.ts
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
interface StylelintRuleOptions {
|
|
3
3
|
[key: string]: unknown;
|
|
4
4
|
}
|
|
5
|
-
type
|
|
5
|
+
type StylelintPlugin = string | object;
|
|
6
|
+
type StylelintRuleSetting = null | undefined | string | number | boolean | RegExp | StylelintRuleOptions | [unknown] | [unknown, StylelintRuleOptions] | unknown[];
|
|
6
7
|
interface StylelintOverride {
|
|
7
8
|
files: string | string[];
|
|
8
9
|
name?: string;
|
|
9
10
|
customSyntax?: any;
|
|
10
11
|
extends?: string | string[];
|
|
11
|
-
plugins?:
|
|
12
|
+
plugins?: StylelintPlugin | StylelintPlugin[];
|
|
12
13
|
rules?: Record<string, StylelintRuleSetting>;
|
|
13
14
|
}
|
|
14
15
|
interface StylelintConfig {
|
|
15
16
|
extends?: string | string[];
|
|
16
|
-
plugins?:
|
|
17
|
+
plugins?: StylelintPlugin | StylelintPlugin[];
|
|
17
18
|
overrides?: StylelintOverride[];
|
|
18
19
|
rules?: Record<string, StylelintRuleSetting>;
|
|
19
20
|
customSyntax?: any;
|
|
@@ -43,6 +44,8 @@ interface IgnoreListOptions {
|
|
|
43
44
|
}
|
|
44
45
|
type TailwindcssPresetLevel = 'base' | 'recommended' | 'strict';
|
|
45
46
|
interface IcebreakerStylelintOptions {
|
|
47
|
+
/** Enable Mini Program defaults such as common ignore paths. */
|
|
48
|
+
miniProgram?: boolean;
|
|
46
49
|
/** Toggle built-in preset bundles. */
|
|
47
50
|
presets?: PresetToggles;
|
|
48
51
|
/** Control the bundled Tailwind/UnoCSS policy layer. */
|
|
@@ -51,6 +54,12 @@ interface IcebreakerStylelintOptions {
|
|
|
51
54
|
extends?: StylelintConfig['extends'];
|
|
52
55
|
/** Append override entries. */
|
|
53
56
|
overrides?: StylelintConfig['overrides'];
|
|
57
|
+
/** Append plugins. */
|
|
58
|
+
plugins?: StylelintConfig['plugins'];
|
|
59
|
+
/** Set a top-level custom syntax. */
|
|
60
|
+
customSyntax?: StylelintConfig['customSyntax'];
|
|
61
|
+
/** Append ignoreFiles entries. */
|
|
62
|
+
ignoreFiles?: StylelintConfig['ignoreFiles'];
|
|
54
63
|
/** Provide additional or replacement rule ignore lists. */
|
|
55
64
|
ignores?: IgnoreListOptions;
|
|
56
65
|
/** Override or add rules. */
|
|
@@ -61,7 +70,7 @@ interface IcebreakerStylelintOptions {
|
|
|
61
70
|
declare function createIcebreakerStylelintConfig(options?: IcebreakerStylelintOptions): StylelintConfig;
|
|
62
71
|
//#endregion
|
|
63
72
|
//#region src/index.d.ts
|
|
64
|
-
declare function icebreaker(config?: StylelintConfig): StylelintConfig;
|
|
73
|
+
declare function icebreaker(config?: IcebreakerStylelintOptions & StylelintConfig): StylelintConfig;
|
|
65
74
|
type IcebreakerStylelintConfig = ReturnType<typeof icebreaker>;
|
|
66
75
|
//#endregion
|
|
67
76
|
export { IcebreakerStylelintConfig, type IcebreakerStylelintOptions, type IgnoreListOptions, type PresetToggles, type StylelintConfig, type StylelintOverride, type StylelintRuleOptions, type StylelintRuleSetting, type TailwindcssPresetLevel, createIcebreakerStylelintConfig as createStylelintConfig, icebreaker };
|
package/dist/index.js
CHANGED
|
@@ -81,6 +81,12 @@ function resolvePresetPath(specifier) {
|
|
|
81
81
|
const PRESET_PATH_STANDARD_SCSS = resolvePresetPath(PRESET_STANDARD_SCSS);
|
|
82
82
|
const PRESET_PATH_VUE_SCSS = resolvePresetPath(PRESET_VUE_SCSS);
|
|
83
83
|
const PRESET_PATH_RECESS_ORDER = resolvePresetPath(PRESET_RECESS_ORDER);
|
|
84
|
+
const MINI_PROGRAM_IGNORE_FILES = [
|
|
85
|
+
"dist/**",
|
|
86
|
+
".weapp-vite/**",
|
|
87
|
+
"node_modules/**",
|
|
88
|
+
"miniprogram_npm/**"
|
|
89
|
+
];
|
|
84
90
|
function resolvePresetExtends(presets) {
|
|
85
91
|
const entries = [];
|
|
86
92
|
if (presets?.scss !== false) entries.push(PRESET_PATH_STANDARD_SCSS);
|
|
@@ -98,6 +104,15 @@ function resolveOverrides(options) {
|
|
|
98
104
|
if (!overrides || overrides.length === 0) return [];
|
|
99
105
|
return [...overrides];
|
|
100
106
|
}
|
|
107
|
+
function normalizePlugins(plugins) {
|
|
108
|
+
return toArray(plugins);
|
|
109
|
+
}
|
|
110
|
+
function resolvePlugins(options) {
|
|
111
|
+
return normalizePlugins(options?.plugins);
|
|
112
|
+
}
|
|
113
|
+
function resolveIgnoreFiles(options) {
|
|
114
|
+
return normalizeExtends(unique([...options?.miniProgram ? MINI_PROGRAM_IGNORE_FILES : [], ...toArray(options?.ignoreFiles)]));
|
|
115
|
+
}
|
|
101
116
|
function resolveRules(options) {
|
|
102
117
|
const ignoreUnits = resolveIgnoreList("units", options?.ignores);
|
|
103
118
|
const ignoreTypes = resolveIgnoreList("types", options?.ignores);
|
|
@@ -132,11 +147,15 @@ function resolveTailwindcssPreset(options) {
|
|
|
132
147
|
function createIcebreakerStylelintConfig(options = {}) {
|
|
133
148
|
const extendsConfig = resolveExtends(options);
|
|
134
149
|
const overrides = resolveOverrides(options);
|
|
150
|
+
const plugins = resolvePlugins(options);
|
|
151
|
+
const ignoreFiles = resolveIgnoreFiles(options);
|
|
135
152
|
const rules = resolveRules(options);
|
|
136
153
|
const tailwindcssPreset = resolveTailwindcssPreset(options);
|
|
137
154
|
return {
|
|
138
155
|
...extendsConfig !== void 0 ? { extends: extendsConfig } : {},
|
|
139
|
-
|
|
156
|
+
...options.customSyntax !== void 0 ? { customSyntax: options.customSyntax } : {},
|
|
157
|
+
...ignoreFiles !== void 0 ? { ignoreFiles } : {},
|
|
158
|
+
plugins: [...normalizePlugins(tailwindcssPreset.plugins), ...plugins],
|
|
140
159
|
overrides,
|
|
141
160
|
rules: {
|
|
142
161
|
...tailwindcssPreset.rules ?? {
|
|
@@ -160,22 +179,8 @@ function createIcebreakerStylelintConfig(options = {}) {
|
|
|
160
179
|
}
|
|
161
180
|
//#endregion
|
|
162
181
|
//#region src/index.ts
|
|
163
|
-
function mergeConfigs(base, overrides) {
|
|
164
|
-
if (!overrides) return base;
|
|
165
|
-
const basePlugins = Array.isArray(base.plugins) ? base.plugins : base.plugins ? [base.plugins] : [];
|
|
166
|
-
const overridePlugins = Array.isArray(overrides.plugins) ? overrides.plugins : overrides.plugins ? [overrides.plugins] : [];
|
|
167
|
-
return {
|
|
168
|
-
...base,
|
|
169
|
-
...overrides,
|
|
170
|
-
plugins: [...basePlugins, ...overridePlugins],
|
|
171
|
-
rules: {
|
|
172
|
-
...base.rules ?? {},
|
|
173
|
-
...overrides.rules ?? {}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
182
|
function icebreaker(config) {
|
|
178
|
-
return
|
|
183
|
+
return createIcebreakerStylelintConfig(config);
|
|
179
184
|
}
|
|
180
185
|
//#endregion
|
|
181
186
|
export { createIcebreakerStylelintConfig as createStylelintConfig, icebreaker };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icebreakers/stylelint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"description": "Stylelint preset from Icebreaker's dev-configs",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"stylelint-config-recommended-scss": "^17.0.0",
|
|
48
48
|
"stylelint-config-recommended-vue": "^1.6.1",
|
|
49
49
|
"stylelint-config-standard-scss": "^17.0.0",
|
|
50
|
-
"stylelint-plugin-tailwindcss": "1.0.
|
|
50
|
+
"stylelint-plugin-tailwindcss": "1.0.2"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|