@icebreakers/stylelint-config 2.0.7 → 2.1.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 +44 -7
- package/README.zh.md +44 -7
- package/dist/index.d.ts +4 -1
- package/dist/index.js +27 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ Use `createStylelintConfig` for fine-grained control over preset toggles, ignore
|
|
|
44
44
|
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
45
45
|
|
|
46
46
|
export default createStylelintConfig({
|
|
47
|
+
tailwindcssPreset: 'recommended',
|
|
47
48
|
presets: {
|
|
48
49
|
vue: false, // disable Vue rules for pure SCSS projects
|
|
49
50
|
},
|
|
@@ -71,6 +72,7 @@ export default createStylelintConfig({
|
|
|
71
72
|
- `presets.scss` – include `stylelint-config-standard-scss` (default `true`)
|
|
72
73
|
- `presets.vue` – include `stylelint-config-recommended-vue/scss` (default `true`)
|
|
73
74
|
- `presets.order` – include `stylelint-config-recess-order` (default `true`)
|
|
75
|
+
- `tailwindcssPreset` – choose the bundled utility-policy layer: `'base'` (default), `'recommended'`, or `'strict'`
|
|
74
76
|
- `ignores.*` – replace the default ignore lists (units, selector types, at-rules)
|
|
75
77
|
- `ignores.add*` – append to the default ignore allowlists
|
|
76
78
|
- `extends` – append additional Stylelint configs after the presets
|
|
@@ -87,21 +89,56 @@ Defaults include:
|
|
|
87
89
|
|
|
88
90
|
## Tailwind Utility Selector Guard
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
By default this preset enables the plugin's `base` policy layer:
|
|
91
93
|
|
|
92
94
|
```txt
|
|
93
95
|
tailwindcss/no-atomic-class
|
|
94
96
|
tailwindcss/no-invalid-apply
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
unocss/no-atomic-class
|
|
98
|
+
unocss/no-invalid-apply
|
|
97
99
|
```
|
|
98
100
|
|
|
99
|
-
These rules:
|
|
101
|
+
These default rules:
|
|
100
102
|
|
|
101
|
-
- report Tailwind utility selectors declared in authored stylesheets while still allowing semantic selectors such as BEM/OOCSS class names
|
|
103
|
+
- report Tailwind and UnoCSS utility selectors declared in authored stylesheets while still allowing semantic selectors such as BEM/OOCSS class names
|
|
102
104
|
- report invalid utility-like `@apply` candidates
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
|
|
106
|
+
If you want the broader everyday policy layer, switch to:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
110
|
+
|
|
111
|
+
export default createStylelintConfig({
|
|
112
|
+
tailwindcssPreset: 'recommended',
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
That adds:
|
|
117
|
+
|
|
118
|
+
- `tailwindcss/no-apply`
|
|
119
|
+
- `tailwindcss/no-arbitrary-value`
|
|
120
|
+
- `tailwindcss/no-invalid-theme-function`
|
|
121
|
+
- `unocss/no-apply`
|
|
122
|
+
- `unocss/no-arbitrary-value`
|
|
123
|
+
- `unocss/no-variant-group`
|
|
124
|
+
|
|
125
|
+
If you want the stricter architecture-oriented Tailwind policy layer, switch to:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
129
|
+
|
|
130
|
+
export default createStylelintConfig({
|
|
131
|
+
tailwindcssPreset: 'strict',
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
That adds these Tailwind-only rules on top of the default policy:
|
|
136
|
+
|
|
137
|
+
- `tailwindcss/no-theme-function`
|
|
138
|
+
- `tailwindcss/no-screen-directive`
|
|
139
|
+
- `tailwindcss/no-tailwind-directive`
|
|
140
|
+
- `tailwindcss/no-import-directive`
|
|
141
|
+
- `tailwindcss/no-css-layer`
|
|
105
142
|
|
|
106
143
|
The underlying plugin supports both Tailwind CSS v3 and v4, and switches automatically based on the installed `tailwindcss` major version in the consuming project.
|
|
107
144
|
|
package/README.zh.md
CHANGED
|
@@ -42,6 +42,7 @@ export default icebreaker()
|
|
|
42
42
|
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
43
43
|
|
|
44
44
|
export default createStylelintConfig({
|
|
45
|
+
tailwindcssPreset: 'recommended',
|
|
45
46
|
presets: {
|
|
46
47
|
vue: false, // 纯 SCSS 项目无需 Vue 规则
|
|
47
48
|
},
|
|
@@ -69,6 +70,7 @@ export default createStylelintConfig({
|
|
|
69
70
|
- `presets.scss`:是否包含 `stylelint-config-standard-scss`,默认开启
|
|
70
71
|
- `presets.vue`:是否包含 `stylelint-config-recommended-vue/scss`,默认开启
|
|
71
72
|
- `presets.order`:是否包含 `stylelint-config-recess-order`,默认开启
|
|
73
|
+
- `tailwindcssPreset`:选择内置 utility 策略层,支持 `'base'`(默认)、`'recommended'` 或 `'strict'`
|
|
72
74
|
- `ignores.*`:替换默认的忽略列表(单位、选择器类型、指令)
|
|
73
75
|
- `ignores.add*`:在默认忽略列表基础上追加项
|
|
74
76
|
- `extends`:在预设之后追加自定义 Stylelint 配置
|
|
@@ -85,21 +87,56 @@ export default createStylelintConfig({
|
|
|
85
87
|
|
|
86
88
|
## Tailwind 原子类拦截
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
该预设默认启用 `stylelint-plugin-tailwindcss` 的 `base` 策略层,对应规则为:
|
|
89
91
|
|
|
90
92
|
```txt
|
|
91
93
|
tailwindcss/no-atomic-class
|
|
92
94
|
tailwindcss/no-invalid-apply
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
unocss/no-atomic-class
|
|
96
|
+
unocss/no-invalid-apply
|
|
95
97
|
```
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
这些默认规则会:
|
|
98
100
|
|
|
99
|
-
- 拦截在样式文件中直接声明 Tailwind utility selector,但不会影响正常的语义化类名,例如 BEM / OOCSS 风格命名
|
|
101
|
+
- 拦截在样式文件中直接声明 Tailwind / UnoCSS utility selector,但不会影响正常的语义化类名,例如 BEM / OOCSS 风格命名
|
|
100
102
|
- 拦截无效的 `@apply` utility candidate
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
|
|
104
|
+
如果你需要更完整的日常策略层,可以切到:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
108
|
+
|
|
109
|
+
export default createStylelintConfig({
|
|
110
|
+
tailwindcssPreset: 'recommended',
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
这会额外启用:
|
|
115
|
+
|
|
116
|
+
- `tailwindcss/no-apply`
|
|
117
|
+
- `tailwindcss/no-arbitrary-value`
|
|
118
|
+
- `tailwindcss/no-invalid-theme-function`
|
|
119
|
+
- `unocss/no-apply`
|
|
120
|
+
- `unocss/no-arbitrary-value`
|
|
121
|
+
- `unocss/no-variant-group`
|
|
122
|
+
|
|
123
|
+
如果你需要更严格、偏架构约束的 Tailwind 策略层,可以切到:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { createStylelintConfig } from '@icebreakers/stylelint-config'
|
|
127
|
+
|
|
128
|
+
export default createStylelintConfig({
|
|
129
|
+
tailwindcssPreset: 'strict',
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
这会在默认策略上额外启用这些 Tailwind 规则:
|
|
134
|
+
|
|
135
|
+
- `tailwindcss/no-theme-function`
|
|
136
|
+
- `tailwindcss/no-screen-directive`
|
|
137
|
+
- `tailwindcss/no-tailwind-directive`
|
|
138
|
+
- `tailwindcss/no-import-directive`
|
|
139
|
+
- `tailwindcss/no-css-layer`
|
|
103
140
|
|
|
104
141
|
底层插件同时兼容 Tailwind CSS v3 和 v4,会根据使用方项目实际安装的 `tailwindcss` 主版本自动切换检测逻辑。
|
|
105
142
|
|
package/dist/index.d.ts
CHANGED
|
@@ -41,9 +41,12 @@ interface IgnoreListOptions {
|
|
|
41
41
|
/** Additional units to ignore. */
|
|
42
42
|
addUnits?: string[];
|
|
43
43
|
}
|
|
44
|
+
type TailwindcssPresetLevel = 'base' | 'recommended' | 'strict';
|
|
44
45
|
interface IcebreakerStylelintOptions {
|
|
45
46
|
/** Toggle built-in preset bundles. */
|
|
46
47
|
presets?: PresetToggles;
|
|
48
|
+
/** Control the bundled Tailwind/UnoCSS policy layer. */
|
|
49
|
+
tailwindcssPreset?: TailwindcssPresetLevel;
|
|
47
50
|
/** Append extra extends entries. */
|
|
48
51
|
extends?: StylelintConfig['extends'];
|
|
49
52
|
/** Append override entries. */
|
|
@@ -60,4 +63,4 @@ declare function createIcebreakerStylelintConfig(options?: IcebreakerStylelintOp
|
|
|
60
63
|
//#region src/index.d.ts
|
|
61
64
|
declare function icebreaker(config?: StylelintConfig): StylelintConfig;
|
|
62
65
|
//#endregion
|
|
63
|
-
export { type IcebreakerStylelintOptions, type IgnoreListOptions, type PresetToggles, createIcebreakerStylelintConfig as createStylelintConfig, icebreaker };
|
|
66
|
+
export { type IcebreakerStylelintOptions, type IgnoreListOptions, type PresetToggles, type TailwindcssPresetLevel, createIcebreakerStylelintConfig as createStylelintConfig, icebreaker };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { noApplyRuleName, noArbitraryValueRuleName, noAtomicClassRuleName, noInvalidApplyRuleName, recommended } from "stylelint-plugin-tailwindcss";
|
|
4
|
+
import { base, noApplyRuleName, noArbitraryValueRuleName, noAtomicClassRuleName, noCssLayerRuleName, noInvalidApplyRuleName, noInvalidThemeFunctionRuleName, noScreenDirectiveRuleName, noThemeFunctionRuleName, recommended, strict, unocssNoApplyRuleName, unocssNoArbitraryValueRuleName, unocssNoAtomicClassRuleName, unocssNoInvalidApplyRuleName, unocssNoVariantGroupRuleName } from "stylelint-plugin-tailwindcss";
|
|
5
5
|
//#region src/constants.ts
|
|
6
6
|
const PRESET_STANDARD_SCSS = "stylelint-config-standard-scss";
|
|
7
7
|
const PRESET_VUE_SCSS = "stylelint-config-recommended-vue/scss";
|
|
@@ -12,6 +12,7 @@ const IGNORE_DEFAULTS = {
|
|
|
12
12
|
atRules: [
|
|
13
13
|
"tailwind",
|
|
14
14
|
"theme",
|
|
15
|
+
"screen",
|
|
15
16
|
"apply",
|
|
16
17
|
"source",
|
|
17
18
|
"utility",
|
|
@@ -111,6 +112,7 @@ function resolveRules(options) {
|
|
|
111
112
|
"unit-no-unknown": [true, { ignoreUnits }],
|
|
112
113
|
"selector-type-no-unknown": [true, { ignoreTypes }],
|
|
113
114
|
"at-rule-no-deprecated": [true, { ignoreAtRules }],
|
|
115
|
+
"at-rule-no-unknown": [true, { ignoreAtRules }],
|
|
114
116
|
"scss/selector-no-redundant-nesting-selector": true,
|
|
115
117
|
"scss/at-rule-no-unknown": [true, { ignoreAtRules }]
|
|
116
118
|
};
|
|
@@ -120,19 +122,38 @@ function resolveRules(options) {
|
|
|
120
122
|
};
|
|
121
123
|
return rules;
|
|
122
124
|
}
|
|
125
|
+
function resolveTailwindcssPreset(options) {
|
|
126
|
+
switch (options?.tailwindcssPreset) {
|
|
127
|
+
case "recommended": return recommended;
|
|
128
|
+
case "strict": return strict;
|
|
129
|
+
default: return base;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
123
132
|
function createIcebreakerStylelintConfig(options = {}) {
|
|
124
133
|
const extendsConfig = resolveExtends(options);
|
|
125
134
|
const overrides = resolveOverrides(options);
|
|
126
135
|
const rules = resolveRules(options);
|
|
136
|
+
const tailwindcssPreset = resolveTailwindcssPreset(options);
|
|
127
137
|
return {
|
|
128
138
|
...extendsConfig !== void 0 ? { extends: extendsConfig } : {},
|
|
129
|
-
plugins: [...
|
|
139
|
+
plugins: [...tailwindcssPreset.plugins ?? []],
|
|
130
140
|
overrides,
|
|
131
141
|
rules: {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
...tailwindcssPreset.rules ?? {
|
|
143
|
+
[noAtomicClassRuleName]: true,
|
|
144
|
+
[noInvalidApplyRuleName]: true,
|
|
145
|
+
[noApplyRuleName]: true,
|
|
146
|
+
[noArbitraryValueRuleName]: true,
|
|
147
|
+
[noThemeFunctionRuleName]: true,
|
|
148
|
+
[noInvalidThemeFunctionRuleName]: true,
|
|
149
|
+
[noScreenDirectiveRuleName]: true,
|
|
150
|
+
[noCssLayerRuleName]: true,
|
|
151
|
+
[unocssNoAtomicClassRuleName]: true,
|
|
152
|
+
[unocssNoInvalidApplyRuleName]: true,
|
|
153
|
+
[unocssNoApplyRuleName]: true,
|
|
154
|
+
[unocssNoArbitraryValueRuleName]: true,
|
|
155
|
+
[unocssNoVariantGroupRuleName]: true
|
|
156
|
+
},
|
|
136
157
|
...rules
|
|
137
158
|
}
|
|
138
159
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icebreakers/stylelint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.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": "0.0
|
|
50
|
+
"stylelint-plugin-tailwindcss": "1.0.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|