前端工程化工具系列(三)—— Stylelint(v16.6.1):CSS/SCSS 代碼質量工具

Stylelint 是 CSS/SCSS 的靜態分析工具,用于檢查其中的違規和錯誤。

1. 環境要求

v16 以上的 Stylelint,支持 Node.js 的版本為 v18.12.0+。
在命令行工具中輸入以下內容后回車,來查看當前系統中 Node.js 的版本。

node -v

Node.js 推薦使用 v18.20.3+ 或者 v20.13.1+。
這里使用的包管理器是 PNPM,版本為 v9.1.4。

2 安裝

2.1 針對 CSS

pnpm install -D stylelint stylelint-config-standard stylelint-order

2.2 針對 SCSS(包含CSS)

pnpm install -D stylelint stylelint-order stylelint-config-standard stylelint-config-standard-scss stylelint-config-sass-guidelines stylelint-scss

3 配置

在項目根目錄下創建 stylelint.config.js 文件,根據樣式文件類型(CSS/SCSS)填入以下內容:

3.1 針對 CSS

export default {// 繼承已有配置 如果規則與自己想要的沖突 可以在下面rules中修改規則extends: ['stylelint-config-standard'],// 插件是由社區創建的規則或規則集 按照規則對CSS屬性進行排序plugins: [// 指定排序,比如聲明的塊內(插件包)屬性的順序'stylelint-order',],rules: {// 允許的最大嵌套深度為 3'max-nesting-depth': 3,// 屏蔽一些scss等語法檢查'at-rule-no-unknown': [true,{ignoreAtRules: ['extend','at-root','debug','warn','error','if','else','for','each','while','mixin','include','content','return','function',],},],// 屏蔽沒有申明通用字體'font-family-no-missing-generic-family-keyword': null,// ID選擇器 最多使用一個'selector-max-id': 1,// 不允許使用的選擇器的類型'selector-no-qualifying-type': null,// 屏蔽類選擇器的檢查,以確保使用字符 __'selector-class-pattern': null,// 允許的最大復合選擇器為 5'selector-max-compound-selectors': 5,// 屬性排序規則'order/properties-order': [['content','position','top','right','bottom','left','z-index','display','vertical-align','flex','flex-grow','flex-shrink','flex-basis','flex-direction','flex-flow','flex-wrap','grid','grid-area','grid-template','grid-template-areas','grid-template-rows','grid-template-columns','grid-row','grid-row-start','grid-row-end','grid-column','grid-column-start','grid-column-end','grid-auto-rows','grid-auto-columns','grid-auto-flow','grid-gap','grid-row-gap','grid-column-gap','gap','row-gap','column-gap','align-content','align-items','align-self','justify-content','justify-items','justify-self','order','float','clear','object-fit','overflow','overflow-x','overflow-y','overflow-scrolling','clip',//'box-sizing','width','min-width','max-width','height','min-height','max-height','margin','margin-top','margin-right','margin-bottom','margin-left','padding','padding-top','padding-right','padding-bottom','padding-left','border','border-spacing','border-collapse','border-width','border-style','border-color','border-top','border-top-width','border-top-style','border-top-color','border-right','border-right-width','border-right-style','border-right-color','border-bottom','border-bottom-width','border-bottom-style','border-bottom-color','border-left','border-left-width','border-left-style','border-left-color','border-radius','border-top-left-radius','border-top-right-radius','border-bottom-right-radius','border-bottom-left-radius','border-image','border-image-source','border-image-slice','border-image-width','border-image-outset','border-image-repeat','border-top-image','border-right-image','border-bottom-image','border-left-image','border-corner-image','border-top-left-image','border-top-right-image','border-bottom-right-image','border-bottom-left-image',//'background','background-color','background-image','background-attachment','background-position','background-position-x','background-position-y','background-clip','background-origin','background-size','background-repeat','color','box-decoration-break','box-shadow','outline','outline-width','outline-style','outline-color','outline-offset','table-layout','caption-side','empty-cells','list-style','list-style-position','list-style-type','list-style-image',//'font','font-weight','font-style','font-variant','font-size-adjust','font-stretch','font-size','font-family','src','line-height','letter-spacing','quotes','counter-increment','counter-reset','-ms-writing-mode','text-align','text-align-last','text-decoration','text-emphasis','text-emphasis-position','text-emphasis-style','text-emphasis-color','text-indent','text-justify','text-outline','text-transform','text-wrap','text-overflow','text-overflow-ellipsis','text-overflow-mode','text-shadow','white-space','word-spacing','word-wrap','word-break','overflow-wrap','tab-size','hyphens','interpolation-mode',//'opacity','visibility','filter','resize','cursor','pointer-events','user-select',//'unicode-bidi','direction','columns','column-span','column-width','column-count','column-fill','column-gap','column-rule','column-rule-width','column-rule-style','column-rule-color','break-before','break-inside','break-after','page-break-before','page-break-inside','page-break-after','orphans','widows','zoom','max-zoom','min-zoom','user-zoom','orientation','fill','stroke',//'transition','transition-delay','transition-timing-function','transition-duration','transition-property','transform','transform-origin','animation','animation-name','animation-duration','animation-play-state','animation-timing-function','animation-delay','animation-iteration-count','animation-direction','animation-fill-mode',],{unspecified: 'bottom',severity: 'warning',},],// 屏蔽屬性按字母順序檢查'order/properties-alphabetical-order': null,},
};

3.2 針對 SCSS

export default {// 繼承已有配置 如果規則與自己想要的沖突 可以在下面rules中修改規則extends: ['stylelint-config-standard','stylelint-config-standard-scss','stylelint-config-sass-guidelines',],// 插件是由社區創建的規則或規則集 按照規則對CSS屬性進行排序plugins: [// 執行各種各樣的 SCSS語法特性檢測規則(插件包)'stylelint-scss',// 指定排序,比如聲明的塊內(插件包)屬性的順序'stylelint-order',],rules: {// 允許的最大嵌套深度為 3'max-nesting-depth': 3,// 屏蔽一些scss等語法檢查'at-rule-no-unknown': [true,{ignoreAtRules: ['extend','at-root','debug','warn','error','if','else','for','each','while','mixin','include','content','return','function',],},],// 屏蔽沒有申明通用字體'font-family-no-missing-generic-family-keyword': null,// ID選擇器 最多使用一個'selector-max-id': 1,// 不允許使用的選擇器的類型'selector-no-qualifying-type': null,// 屏蔽類選擇器的檢查,以確保使用字符 __'selector-class-pattern': null,// 允許的最大復合選擇器為 5'selector-max-compound-selectors': 5,// 屬性排序規則'order/properties-order': [['content','position','top','right','bottom','left','z-index','display','vertical-align','flex','flex-grow','flex-shrink','flex-basis','flex-direction','flex-flow','flex-wrap','grid','grid-area','grid-template','grid-template-areas','grid-template-rows','grid-template-columns','grid-row','grid-row-start','grid-row-end','grid-column','grid-column-start','grid-column-end','grid-auto-rows','grid-auto-columns','grid-auto-flow','grid-gap','grid-row-gap','grid-column-gap','gap','row-gap','column-gap','align-content','align-items','align-self','justify-content','justify-items','justify-self','order','float','clear','object-fit','overflow','overflow-x','overflow-y','overflow-scrolling','clip',//'box-sizing','width','min-width','max-width','height','min-height','max-height','margin','margin-top','margin-right','margin-bottom','margin-left','padding','padding-top','padding-right','padding-bottom','padding-left','border','border-spacing','border-collapse','border-width','border-style','border-color','border-top','border-top-width','border-top-style','border-top-color','border-right','border-right-width','border-right-style','border-right-color','border-bottom','border-bottom-width','border-bottom-style','border-bottom-color','border-left','border-left-width','border-left-style','border-left-color','border-radius','border-top-left-radius','border-top-right-radius','border-bottom-right-radius','border-bottom-left-radius','border-image','border-image-source','border-image-slice','border-image-width','border-image-outset','border-image-repeat','border-top-image','border-right-image','border-bottom-image','border-left-image','border-corner-image','border-top-left-image','border-top-right-image','border-bottom-right-image','border-bottom-left-image',//'background','background-color','background-image','background-attachment','background-position','background-position-x','background-position-y','background-clip','background-origin','background-size','background-repeat','color','box-decoration-break','box-shadow','outline','outline-width','outline-style','outline-color','outline-offset','table-layout','caption-side','empty-cells','list-style','list-style-position','list-style-type','list-style-image',//'font','font-weight','font-style','font-variant','font-size-adjust','font-stretch','font-size','font-family','src','line-height','letter-spacing','quotes','counter-increment','counter-reset','-ms-writing-mode','text-align','text-align-last','text-decoration','text-emphasis','text-emphasis-position','text-emphasis-style','text-emphasis-color','text-indent','text-justify','text-outline','text-transform','text-wrap','text-overflow','text-overflow-ellipsis','text-overflow-mode','text-shadow','white-space','word-spacing','word-wrap','word-break','overflow-wrap','tab-size','hyphens','interpolation-mode',//'opacity','visibility','filter','resize','cursor','pointer-events','user-select',//'unicode-bidi','direction','columns','column-span','column-width','column-count','column-fill','column-gap','column-rule','column-rule-width','column-rule-style','column-rule-color','break-before','break-inside','break-after','page-break-before','page-break-inside','page-break-after','orphans','widows','zoom','max-zoom','min-zoom','user-zoom','orientation','fill','stroke',//'transition','transition-delay','transition-timing-function','transition-duration','transition-property','transform','transform-origin','animation','animation-name','animation-duration','animation-play-state','animation-timing-function','animation-delay','animation-iteration-count','animation-direction','animation-fill-mode',],{unspecified: 'bottom',severity: 'warning',},],// 屏蔽屬性按字母順序檢查'order/properties-alphabetical-order': null,},
};

4 結合 Husky

利用 Husky 在 git commit 時自動校驗文件中的樣式內容,如不符合規范,則文件不能被 commit。詳細操作見《前端工程化工具系列(五)—— Husky(v9.0.11)&lint-staged(v15.2.5):代碼提交前的自動審查利器》中的 2.1節。

5 結合 VS Code

配合 VS Code 插件,可在做文件保存時自動修復錯誤。詳細操作見《前端工程化工具系列(六)—— VS Code(v1.89.1):強大的代碼編輯器》。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/22239.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/22239.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/22239.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Shell腳本快速入門

為什么要學shell?能做什么? 答:CI/CD 持續集成,自動化部署作業方式,需要將一系列linux命令程序化,shell 就能做到。

13. 《C語言》——【strlen函數的使用和模擬實現】

文章目錄 前言strlen函數strlen函數的使用strlen函數的3種方法實現方法1方法2方法3 總結 前言 各位老板好~ , 今天我們講解strlen函數如何去使用以及如何去模擬實現strlen函數。希望各位老板能夠給一個點贊和一個大大的關注,感謝各位老板!str…

塑料焊接機熔深對激光焊接質量有什么影響

塑料焊接機的熔深對焊接質量具有直接且顯著的影響。以下是熔深對焊接質量影響的詳細解釋: 1. 焊接強度:熔深直接決定了焊縫的截面積,從而影響焊接接頭的強度。較深的熔深意味著焊縫的截面積更大,可以提供更強的結合力,…

OpenStreetMap部署(OSM)

參考:https://github.com/openstreetmap/openstreetmap-website/blob/master/DOCKER.md OpenStreeMap 部署 操作系統建議使用 Ubuntu 22 版本 安裝 Docker # 更新軟件包索引: sudo apt-get update # 允許APT使用HTTPS: sudo apt-get inst…

【計算機組成原理】詳談計算機發展歷程

計算機發展歷程 導讀一、計算機的誕生1.1 歷史背景1.2 計算機的發明 二、計算機硬件的發展1.1 計算機的四代變化1.1.1 第一代計算機bug的由來 1.1.2 第二代計算機1.1.3 第三代計算機半導體存儲器的發展 1.1.4 第四代計算機 1.2 個人計算機的發展1.2.1 微處理器的發展1.2.2 個人…

AIGC之Stable Diffusion Web Ui 初體驗

前言 Stable Diffusion辣么火,同學你確定不嘗試一下嘛? 純代碼學習版本搞啦,Web Ui 也得試試咧 網上有很多安裝Stable Diffusion Web Ui 的介紹了,我在這說一下我的踩坑記錄 想安裝的同學,看這個鏈接 萬字長文&#x…

U-Net: Convolutional Networks for Biomedical Image Segmentation--論文筆記

U-Net: Convolutional Networks for Biomedical Image Segmentation 資料 1.代碼地址 2.論文地址 https://arxiv.org/pdf/1505.04597 3.數據集地址 論文摘要的翻譯 人們普遍認為,深度網絡的成功訓練需要數千個帶注釋的訓練樣本。在本文中,我們提出…

44-5 waf繞過 - SQL注入繞WAF方法

環境準備: 43-5 waf繞過 - 安全狗簡介及安裝-CSDN博客然后安裝sqlilabs靶場:構建完善的安全滲透測試環境:推薦工具、資源和下載鏈接_滲透測試靶機下載-CSDN博客 一、雙寫繞過 打開sql靶場的第一關:http://127.0.0.1/sqli-labs-master/Less-1/?id=1 驗證一下waf是否開啟防…

C\C++內存管理(未完結)

文章目錄 一.C\C內存分布二.C語言中動態內存管理方式:malloc/calloc/realloc/free三.C內存管理方式3.1.new/delete操作內置類型3.2.new和delete操作自定義類型 四.operator new與operator delete函數(重要點進行講解)4.1. operator new與oper…

npm install 出錯,‘proxy‘ config is set properly. See: ‘npm help config‘

背景 從遠程clone下項目之后,使用命令 npm install 安裝依賴,報錯如下 意為: 報錯: npm犯錯!network與網絡連通性有關的問題。 npm犯錯!網絡在大多數情況下,你背后的代理或有壞的網絡設置。 npm犯錯!網絡 npm犯錯…

spring-kafka-生產者服務搭建測試(SpringBoot整合Kafka)

文章目錄 1、生產者服務搭建1.1、引入spring-kafka依賴1.2、使用Java代碼創建主題分區副本1.3、發送消息 1、生產者服務搭建 1.1、引入spring-kafka依賴 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/…

KOL營銷新篇章:互動式內容與線上活動如何助力品牌增長

在當今數字化時代&#xff0c;KOL營銷已成為品牌推廣的重點策略之一。然而&#xff0c;隨著市場競爭的加劇&#xff0c;單純依靠KOL的曝光已經不再足夠&#xff0c;更多的是需要與用戶進行互動&#xff0c;幫助品牌與受眾建立更緊密的聯系。本文將探討KOL營銷如何通過互動式內容…

《企業應用架構模式》學習指南

導讀&#xff1a;企業應用包括哪些&#xff1f;它們又分別有哪些架構模式&#xff1f; 世界著名軟件開發大師Martin Fowler給你答案 01什么是企業應用 我的職業生涯專注于企業應用&#xff0c;因此&#xff0c;這里所談及的模式也都是關于企業應用的。&#xff08;企業應用還有…

怎么用NodeJS腳本實現遠程控制空調

怎么用NodeJS腳本實現遠程控制空調呢&#xff1f; 本文描述了使用NodeJS腳本調用HTTP接口&#xff0c;實現控制空調&#xff0c;通過不同規格的通斷器&#xff0c;來控制不同功率的空調的電源。 可選用產品&#xff1a;可根據實際場景需求&#xff0c;選擇對應的規格 序號設備…

MySQL從入門到高級 --- 12.事務 13.鎖機制 14.日志

文章目錄 第十二章 && 第十三章 && 第十四章&#xff1a;12.事務12.1 特性12.2 隔離級別 13.鎖機制13.1 各存儲引擎對鎖的支持狀況&#xff1a;13.2 鎖特性13.3 MyISAM表鎖13.3.1 加表鎖 13.4 InnoDB行鎖13.4.1 行鎖特點13.4.2 行鎖模式 14.日志14.1 錯誤日志1…

深入理解計算機系統 第三版 中文版 圖5-27 p371 錯漏

中文版 英文版 對照 可以看出錯漏 這本書中文版很多錯漏,可以配合英文版查正,不過英文版也很多錯漏,所以不用太相信書本.要根據自己的理解來.

微軟云計算Windows Azure(一)

目錄 一、微軟云計算平臺二、微軟云操作系統Windows Azure&#xff08;一&#xff09;Windows Azure概述&#xff08;二&#xff09;Windows Azure計算服務&#xff08;三&#xff09;Windows Azure存儲服務&#xff08;四&#xff09;Windows Azure Connect&#xff08;五&…

Win 11官宣取消硬件限制,微軟這次徹底服軟了

上市近 3 年&#xff0c;微軟寄予厚望的 Win 11 終究落了個被上代 Win 10 光環狠狠掩埋的結局。 有小伙伴兒認為是 Win 11 本身做的太爛&#xff0c;更新頻繁、BUG 一堆&#xff0c;讓人失去興趣。 也有人認為&#xff0c;系統本身體驗沒啥大毛病&#xff0c;嚴苛的硬件限制才…

數據結構算法-堆排序

堆排序&#xff1a;利用堆的特性進行排序,先將數組轉換為堆對象&#xff08;最大堆或最小堆&#xff09;&#xff0c;以最大堆為例&#xff0c;每次heapify之后&#xff0c;取出堆頂&#xff08;索引為0)的元素與最后一個元素交換。以后每次做同樣的事情&#xff0c;只是堆的長…

Golang性能分析工具pprof--遠程分析時無法定位源代碼行數問題解決方案

場景 通過命令行模式的list命令&#xff0c;為了查看指標消耗在具體哪一行&#xff0c;需要源代碼。但實際程序是部署在線上或者程序的源代碼目錄變了&#xff0c;則pprof從默認路徑找不到代碼&#xff0c;無法顯示是哪一行的問題。 通過瀏覽器模式的source頁面&#xff0c;有…