@icebreakers/stylelint-config 2.1.1 → 2.2.0
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 +9 -1
- package/dist/index.js +18 -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
|
@@ -43,6 +43,8 @@ interface IgnoreListOptions {
|
|
|
43
43
|
}
|
|
44
44
|
type TailwindcssPresetLevel = 'base' | 'recommended' | 'strict';
|
|
45
45
|
interface IcebreakerStylelintOptions {
|
|
46
|
+
/** Enable Mini Program defaults such as common ignore paths. */
|
|
47
|
+
miniProgram?: boolean;
|
|
46
48
|
/** Toggle built-in preset bundles. */
|
|
47
49
|
presets?: PresetToggles;
|
|
48
50
|
/** Control the bundled Tailwind/UnoCSS policy layer. */
|
|
@@ -51,6 +53,12 @@ interface IcebreakerStylelintOptions {
|
|
|
51
53
|
extends?: StylelintConfig['extends'];
|
|
52
54
|
/** Append override entries. */
|
|
53
55
|
overrides?: StylelintConfig['overrides'];
|
|
56
|
+
/** Append plugins. */
|
|
57
|
+
plugins?: StylelintConfig['plugins'];
|
|
58
|
+
/** Set a top-level custom syntax. */
|
|
59
|
+
customSyntax?: StylelintConfig['customSyntax'];
|
|
60
|
+
/** Append ignoreFiles entries. */
|
|
61
|
+
ignoreFiles?: StylelintConfig['ignoreFiles'];
|
|
54
62
|
/** Provide additional or replacement rule ignore lists. */
|
|
55
63
|
ignores?: IgnoreListOptions;
|
|
56
64
|
/** Override or add rules. */
|
|
@@ -61,7 +69,7 @@ interface IcebreakerStylelintOptions {
|
|
|
61
69
|
declare function createIcebreakerStylelintConfig(options?: IcebreakerStylelintOptions): StylelintConfig;
|
|
62
70
|
//#endregion
|
|
63
71
|
//#region src/index.d.ts
|
|
64
|
-
declare function icebreaker(config?: StylelintConfig): StylelintConfig;
|
|
72
|
+
declare function icebreaker(config?: IcebreakerStylelintOptions & StylelintConfig): StylelintConfig;
|
|
65
73
|
type IcebreakerStylelintConfig = ReturnType<typeof icebreaker>;
|
|
66
74
|
//#endregion
|
|
67
75
|
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,12 @@ function resolveOverrides(options) {
|
|
|
98
104
|
if (!overrides || overrides.length === 0) return [];
|
|
99
105
|
return [...overrides];
|
|
100
106
|
}
|
|
107
|
+
function resolvePlugins(options) {
|
|
108
|
+
return toArray(options?.plugins);
|
|
109
|
+
}
|
|
110
|
+
function resolveIgnoreFiles(options) {
|
|
111
|
+
return normalizeExtends(unique([...options?.miniProgram ? MINI_PROGRAM_IGNORE_FILES : [], ...toArray(options?.ignoreFiles)]));
|
|
112
|
+
}
|
|
101
113
|
function resolveRules(options) {
|
|
102
114
|
const ignoreUnits = resolveIgnoreList("units", options?.ignores);
|
|
103
115
|
const ignoreTypes = resolveIgnoreList("types", options?.ignores);
|
|
@@ -132,11 +144,15 @@ function resolveTailwindcssPreset(options) {
|
|
|
132
144
|
function createIcebreakerStylelintConfig(options = {}) {
|
|
133
145
|
const extendsConfig = resolveExtends(options);
|
|
134
146
|
const overrides = resolveOverrides(options);
|
|
147
|
+
const plugins = resolvePlugins(options);
|
|
148
|
+
const ignoreFiles = resolveIgnoreFiles(options);
|
|
135
149
|
const rules = resolveRules(options);
|
|
136
150
|
const tailwindcssPreset = resolveTailwindcssPreset(options);
|
|
137
151
|
return {
|
|
138
152
|
...extendsConfig !== void 0 ? { extends: extendsConfig } : {},
|
|
139
|
-
|
|
153
|
+
...options.customSyntax !== void 0 ? { customSyntax: options.customSyntax } : {},
|
|
154
|
+
...ignoreFiles !== void 0 ? { ignoreFiles } : {},
|
|
155
|
+
plugins: [...tailwindcssPreset.plugins ?? [], ...plugins],
|
|
140
156
|
overrides,
|
|
141
157
|
rules: {
|
|
142
158
|
...tailwindcssPreset.rules ?? {
|
|
@@ -160,22 +176,8 @@ function createIcebreakerStylelintConfig(options = {}) {
|
|
|
160
176
|
}
|
|
161
177
|
//#endregion
|
|
162
178
|
//#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
179
|
function icebreaker(config) {
|
|
178
|
-
return
|
|
180
|
+
return createIcebreakerStylelintConfig(config);
|
|
179
181
|
}
|
|
180
182
|
//#endregion
|
|
181
183
|
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.
|
|
4
|
+
"version": "2.2.0",
|
|
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.1"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|