@icebreakers/stylelint-config 3.0.0 → 3.0.2
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 +27 -0
- package/README.zh.md +26 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
|
48
48
|
|
|
49
49
|
export default createStylelintConfig({
|
|
50
50
|
miniProgram: true,
|
|
51
|
+
formattingPreset: 'safe',
|
|
51
52
|
tailwindcssPreset: 'recommended',
|
|
52
53
|
presets: {
|
|
53
54
|
vue: false, // disable Vue rules for pure SCSS projects
|
|
@@ -77,6 +78,7 @@ export default createStylelintConfig({
|
|
|
77
78
|
- `presets.scss` – include `stylelint-config-standard-scss` (default `true`)
|
|
78
79
|
- `presets.vue` – include `stylelint-config-recommended-vue/scss` (default `true`)
|
|
79
80
|
- `presets.order` – include `stylelint-config-recess-order` (default `true`)
|
|
81
|
+
- `formattingPreset` – enable fix-oriented formatting conventions. Use `'safe'` for a conservative autofix layer, or `'off'` (default) to keep only the linting presets.
|
|
80
82
|
- `tailwindcssPreset` – choose the bundled utility-policy layer: `'base'` (default), `'recommended'`, or `'strict'`
|
|
81
83
|
- `ignores.*` – replace the default ignore lists (units, selector types, at-rules)
|
|
82
84
|
- `ignores.add*` – append to the default ignore allowlists
|
|
@@ -92,6 +94,31 @@ Defaults include:
|
|
|
92
94
|
- Disallowing authored Tailwind utility selectors such as `.flex` or `.hover\:bg-red-500`
|
|
93
95
|
- Ignoring the `page` selector used by various platforms
|
|
94
96
|
|
|
97
|
+
### Safe Formatting Preset
|
|
98
|
+
|
|
99
|
+
If you want Stylelint to own a small set of autofix-friendly formatting
|
|
100
|
+
conventions, enable:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
104
|
+
|
|
105
|
+
export default createStylelintConfig({
|
|
106
|
+
formattingPreset: 'safe',
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`formattingPreset: 'safe'` is intentionally conservative. It focuses on rules
|
|
111
|
+
that Stylelint 16+ still supports and can fix reliably, such as:
|
|
112
|
+
|
|
113
|
+
- modern color function notation (`rgba()` -> `rgb(... / ...)`)
|
|
114
|
+
- quoted `url(...)` values
|
|
115
|
+
- quoted attribute selector values
|
|
116
|
+
- collapsing redundant longhand declarations into shorthand
|
|
117
|
+
- removing redundant shorthand values
|
|
118
|
+
|
|
119
|
+
This is not a full Prettier-style formatter. It is a fix-oriented convention
|
|
120
|
+
layer for style files that works well with `stylelint --fix`.
|
|
121
|
+
|
|
95
122
|
### Mini Program Templates
|
|
96
123
|
|
|
97
124
|
#### Native Template Minimal Config
|
package/README.zh.md
CHANGED
|
@@ -46,6 +46,7 @@ import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
|
46
46
|
|
|
47
47
|
export default createStylelintConfig({
|
|
48
48
|
miniProgram: true,
|
|
49
|
+
formattingPreset: 'safe',
|
|
49
50
|
tailwindcssPreset: 'recommended',
|
|
50
51
|
presets: {
|
|
51
52
|
vue: false, // 纯 SCSS 项目无需 Vue 规则
|
|
@@ -75,6 +76,7 @@ export default createStylelintConfig({
|
|
|
75
76
|
- `presets.scss`:是否包含 `stylelint-config-standard-scss`,默认开启
|
|
76
77
|
- `presets.vue`:是否包含 `stylelint-config-recommended-vue/scss`,默认开启
|
|
77
78
|
- `presets.order`:是否包含 `stylelint-config-recess-order`,默认开启
|
|
79
|
+
- `formattingPreset`:是否启用面向 `--fix` 的保守格式化约定层。`'safe'` 表示启用,`'off'`(默认)表示只保留 lint 预设。
|
|
78
80
|
- `tailwindcssPreset`:选择内置 utility 策略层,支持 `'base'`(默认)、`'recommended'` 或 `'strict'`
|
|
79
81
|
- `ignores.*`:替换默认的忽略列表(单位、选择器类型、指令)
|
|
80
82
|
- `ignores.add*`:在默认忽略列表基础上追加项
|
|
@@ -90,6 +92,30 @@ export default createStylelintConfig({
|
|
|
90
92
|
- 禁止在手写样式中声明 `.flex`、`.hover\:bg-red-500` 这类 Tailwind 原子类选择器
|
|
91
93
|
- 忽略多端平台常见的 `page` 选择器
|
|
92
94
|
|
|
95
|
+
### Safe Formatting 预设
|
|
96
|
+
|
|
97
|
+
如果你希望样式文件的部分可修复格式约定由 Stylelint 承担,可以开启:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
101
|
+
|
|
102
|
+
export default createStylelintConfig({
|
|
103
|
+
formattingPreset: 'safe',
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`formattingPreset: 'safe'` 是一层刻意保守的配置,只包含 Stylelint 16+
|
|
108
|
+
仍支持、且 `--fix` 行为稳定的规则,例如:
|
|
109
|
+
|
|
110
|
+
- 使用现代颜色函数写法(如 `rgba()` 转成 `rgb(... / ...)`)
|
|
111
|
+
- 为 `url(...)` 补齐引号
|
|
112
|
+
- 为属性选择器值补齐引号
|
|
113
|
+
- 将冗余的 longhand 属性折叠为 shorthand
|
|
114
|
+
- 移除冗余的 shorthand 值
|
|
115
|
+
|
|
116
|
+
它不是 Prettier 那种“完整格式化器”,而是一层适合配合
|
|
117
|
+
`stylelint --fix` 使用的可修复约定集。
|
|
118
|
+
|
|
93
119
|
## 小程序模板推荐用法
|
|
94
120
|
|
|
95
121
|
### 原生小程序最小配置
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ interface IgnoreListOptions {
|
|
|
43
43
|
addUnits?: string[];
|
|
44
44
|
}
|
|
45
45
|
type TailwindcssPresetLevel = 'base' | 'recommended' | 'strict';
|
|
46
|
+
type FormattingPresetLevel = 'off' | 'safe';
|
|
46
47
|
interface IcebreakerStylelintOptions {
|
|
47
48
|
/** Enable Mini Program defaults such as common ignore paths. */
|
|
48
49
|
miniProgram?: boolean;
|
|
@@ -50,6 +51,8 @@ interface IcebreakerStylelintOptions {
|
|
|
50
51
|
presets?: PresetToggles;
|
|
51
52
|
/** Control the bundled Tailwind/UnoCSS policy layer. */
|
|
52
53
|
tailwindcssPreset?: TailwindcssPresetLevel;
|
|
54
|
+
/** Enable fix-oriented formatting conventions that remain supported in Stylelint 16+. */
|
|
55
|
+
formattingPreset?: FormattingPresetLevel;
|
|
53
56
|
/** Append extra extends entries. */
|
|
54
57
|
extends?: StylelintConfig['extends'];
|
|
55
58
|
/** Append override entries. */
|
|
@@ -73,4 +76,4 @@ declare function createIcebreakerStylelintConfig(options?: IcebreakerStylelintOp
|
|
|
73
76
|
declare function icebreaker(config?: IcebreakerStylelintOptions & StylelintConfig): StylelintConfig;
|
|
74
77
|
type IcebreakerStylelintConfig = ReturnType<typeof icebreaker>;
|
|
75
78
|
//#endregion
|
|
76
|
-
export { IcebreakerStylelintConfig, type IcebreakerStylelintOptions, type IgnoreListOptions, type PresetToggles, type StylelintConfig, type StylelintOverride, type StylelintRuleOptions, type StylelintRuleSetting, type TailwindcssPresetLevel, createIcebreakerStylelintConfig as createStylelintConfig, icebreaker };
|
|
79
|
+
export { type FormattingPresetLevel, 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
|
@@ -87,6 +87,14 @@ const MINI_PROGRAM_IGNORE_FILES = [
|
|
|
87
87
|
"node_modules/**",
|
|
88
88
|
"miniprogram_npm/**"
|
|
89
89
|
];
|
|
90
|
+
const SAFE_FORMATTING_RULES = {
|
|
91
|
+
"color-function-notation": "modern",
|
|
92
|
+
"declaration-block-no-redundant-longhand-properties": true,
|
|
93
|
+
"function-url-quotes": "always",
|
|
94
|
+
"hue-degree-notation": "number",
|
|
95
|
+
"selector-attribute-quotes": "always",
|
|
96
|
+
"shorthand-property-no-redundant-values": true
|
|
97
|
+
};
|
|
90
98
|
function resolvePresetExtends(presets) {
|
|
91
99
|
const entries = [];
|
|
92
100
|
if (presets?.scss !== false) entries.push(PRESET_PATH_STANDARD_SCSS);
|
|
@@ -144,6 +152,10 @@ function resolveTailwindcssPreset(options) {
|
|
|
144
152
|
default: return base;
|
|
145
153
|
}
|
|
146
154
|
}
|
|
155
|
+
function resolveFormattingPresetRules(options) {
|
|
156
|
+
if (options?.formattingPreset === "safe") return SAFE_FORMATTING_RULES;
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
147
159
|
function createIcebreakerStylelintConfig(options = {}) {
|
|
148
160
|
const extendsConfig = resolveExtends(options);
|
|
149
161
|
const overrides = resolveOverrides(options);
|
|
@@ -151,6 +163,7 @@ function createIcebreakerStylelintConfig(options = {}) {
|
|
|
151
163
|
const ignoreFiles = resolveIgnoreFiles(options);
|
|
152
164
|
const rules = resolveRules(options);
|
|
153
165
|
const tailwindcssPreset = resolveTailwindcssPreset(options);
|
|
166
|
+
const formattingPresetRules = resolveFormattingPresetRules(options);
|
|
154
167
|
return {
|
|
155
168
|
...extendsConfig !== void 0 ? { extends: extendsConfig } : {},
|
|
156
169
|
...options.customSyntax !== void 0 ? { customSyntax: options.customSyntax } : {},
|
|
@@ -173,6 +186,7 @@ function createIcebreakerStylelintConfig(options = {}) {
|
|
|
173
186
|
[unocssNoArbitraryValueRuleName]: true,
|
|
174
187
|
[unocssNoVariantGroupRuleName]: true
|
|
175
188
|
},
|
|
189
|
+
...formattingPresetRules,
|
|
176
190
|
...rules
|
|
177
191
|
}
|
|
178
192
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icebreakers/stylelint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"description": "Stylelint preset from Icebreaker's dev-configs",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"stylelint-config-recommended-scss": "^17.0.0",
|
|
51
51
|
"stylelint-config-recommended-vue": "^1.6.1",
|
|
52
52
|
"stylelint-config-standard-scss": "^17.0.0",
|
|
53
|
-
"stylelint-plugin-tailwindcss": "2.0.
|
|
53
|
+
"stylelint-plugin-tailwindcss": "2.0.1"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public",
|