Stylelint
安装
bash
pnpm add -D @uniboot/stylelint-config stylelint postcss postcss-html postcss-scssVue / SCSS 场景请保证 postcss-html、postcss-scss 已装。
包内已声明的运行时依赖:@stylistic/stylelint-plugin、stylelint-config-recess-order、stylelint-scss。常用的 stylelint-config-standard、stylelint-config-recommended-scss、stylelint-config-recommended-vue 等以 devDependency 形式存在,发布时由 stylelint 从消费侧解析到对应版本(团队对齐 catalog 版本即可)。
使用
在仓库根目录放 stylelint.config.mjs(或 stylelint.config.js,需 ESM):
js
// stylelint.config.mjs
import config from '@uniboot/stylelint-config'
export default config需要追加规则或调整 overrides 时,在导出对象上展开后再写自己的键:
js
import baseConfig from '@uniboot/stylelint-config'
export default {
...baseConfig,
rules: {
...baseConfig.rules,
'selector-class-pattern': null,
},
}预设里大约包含什么
extends:stylelint-config-standard+stylelint-config-recess-orderplugins:stylelint-order、@stylistic/stylelint-plugin、stylelint-scssignoreFiles: JS/TS/JSX/TSX、JSON、Markdownoverrides:*.vue/*.html使用postcss-html,并放开 Vue 常见伪类/伪元素(:global、:deep、::v-deep、::v-global、::v-slotted)*.scss使用postcss-scss,并extendsstylelint-config-recommended-scss与stylelint-config-recommended-vue/scss
rules:- 关闭
at-rule-no-deprecated、function-no-unknown、media-feature-range-notation等老旧/噪音规则 - 放行 SCSS / Tailwind 常见 at-rule(
tailwind、apply、screen、use、forward、mixin、include等) order/order强制约定顺序:dollar-variables→custom-properties→at-rules→declarations→supports/media/include→rulesselector-class-pattern采用兼容 BEM + 工具前缀(o-/c-/u-/t-/s-/is-/has-/js-/qa-)的正则
- 关闭
完整规则以源码 uniboot-configs/packages/lint-configs/stylelint-config/index.mjs 为准。