您是否也有在開發 Vue 的 CSS 或 SCSS 檔案時,是不是也有這個困擾,常常為了加了外層一個 Class ,又得手動重新調整縮排,團隊開發時,每個成員的撰寫風格都不一樣,Stylelint 則就是為了解決上述的問題而存在。
StyleLint 是一套檢查 CSS Coding Style ,就像是 eslint 一樣,在撰寫 css 時,它可以幫助團隊
npm install --save-dev stylelint stylelint-config-standard stylelint-order stylelint-scss
{ "extends": "stylelint-config-standard", "plugins": [ "stylelint-scss", "stylelint-order" ], "rules": { "property-no-unknown": [ true, { "ignore": [ "promotioncolorfirst", "promotioncolorsecond", "promotioncolorthird" ] } ], "color-hex-case": "upper", "no-descending-specificity": null, "at-rule-no-unknown": null, "order/properties-order": [ "position", "top", "right", "bottom", "left", "z-index", "display", "justify-content", "align-items", "float", "clear", "overflow", "overflow-x", "overflow-y", "margin", "margin-top", "margin-right", "margin-bottom", "margin-left", "border", "border-style", "border-width", "border-color", "border-top", "border-top-style", "border-top-width", "border-top-color", "border-right", "border-right-style", "border-right-width", "border-right-color", "border-bottom", "border-bottom-style", "border-bottom-width", "border-bottom-color", "border-left", "border-left-style", "border-left-width", "border-left-color", "border-radius", "padding", "padding-top", "padding-right", "padding-bottom", "padding-left", "width", "min-width", "max-width", "height", "min-height", "max-height", "font-size", "font-family", "font-weight", "text-align", "text-justify", "text-indent", "text-overflow", "text-decoration", "white-space", "color", "background", "background-position", "background-repeat", "background-size", "background-color", "background-clip", "opacity", "filter", "list-style", "outline", "visibility", "box-shadow", "text-shadow", "resize", "transition" ], "selector-pseudo-class-no-unknown": [ true, { "ignorePseudoClasses": ["export"] } ], "property-no-unknown": [ true, { "ignoreProperties": ["composes", "compose-with"], "ignoreSelectors": [":export", "/^:import/"] } ] } }
"editor.codeActionsOnSave": { "source.fixAll.eslint": true, "source.fixAll.stylelint": true },
// 檢查錯誤 npx stylelint "**/*.css" // 修正錯誤 npx stylelint "**/*.css" --fix
/ package.json { "scripts": { "check:style": "stylelint **/*.{css,scss,sass,vue}", "lint:style": "stylelint **/*.{css,scss,sass,vue} --fix" } }