Stylelint

安装

bash
pnpm add -D @uniboot/stylelint-config stylelint postcss postcss-html postcss-scss

Vue / SCSS 场景请保证 postcss-htmlpostcss-scss 已装。

包内已声明的运行时依赖:@stylistic/stylelint-pluginstylelint-config-recess-orderstylelint-scss。常用的 stylelint-config-standardstylelint-config-recommended-scssstylelint-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-order
  • plugins: stylelint-order@stylistic/stylelint-pluginstylelint-scss
  • ignoreFiles: JS/TS/JSX/TSX、JSON、Markdown
  • overrides
    • *.vue / *.html 使用 postcss-html,并放开 Vue 常见伪类/伪元素(:global:deep::v-deep::v-global::v-slotted
    • *.scss 使用 postcss-scss,并 extends stylelint-config-recommended-scssstylelint-config-recommended-vue/scss
  • rules
    • 关闭 at-rule-no-deprecatedfunction-no-unknownmedia-feature-range-notation 等老旧/噪音规则
    • 放行 SCSS / Tailwind 常见 at-rule(tailwindapplyscreenuseforwardmixininclude 等)
    • order/order 强制约定顺序:dollar-variablescustom-propertiesat-rulesdeclarationssupports / media / includerules
    • selector-class-pattern 采用兼容 BEM + 工具前缀(o- / c- / u- / t- / s- / is- / has- / js- / qa-)的正则

完整规则以源码 uniboot-configs/packages/lint-configs/stylelint-config/index.mjs 为准。