sass lint guidance

一、安装:npm intsall -g stylelint

二、配置:http://stylelint.io/user-guide/rules/ (以下规则文件配置一个即可,置于项目根目录下)

  1. “.stylelintrc”

    {

    "rules": {

    "declaration-block-trailing-semicolon": null

    }

    }

  2. “stylelint.config.js”

    module.exports = {

    "rules": {

    "declaration-block-trailing-semicolon": null

    }

    }

  3. “package.json”

    {

    ......

    "stylelint": {

    "rules": {

    "color-hex-case": "lower"

    }

    }

    }

三、官网给出的标准配置:

  1. 本地安装: npm install stylelint-config-standard
  2. 在配置文件“.stylelintrc”中配置

    {

    "extends": "stylelint-config-standard"

    }
  3. 添加或修改标准配置中的内容

    {

    "extends": "stylelint-config-standard",

    "rules": {

    "declaration-block-trailing-semicolon": null

    }

    }

四、使用命令行:stylelint doc/text.css

五、使用gulp自动监听检查 https://github.com/olegskl/gulp-stylelint

  1. 本地安装gulp: npm install gulp

  2. 创建package.json文件:npm init

  3. 本地安装gulp-stylelint: npm install gulp-stylelint --save-dev

  4. 创建gulpfile.js

    var gulp = require("gulp");

    var gulpStyleLint = require("gulp-stylelint");

     gulp.task('lint-css', function lintCssTask() {
    gulp.watch("css/*.css", ["lint-css"]);
    return gulp
    .src("css/*.css")
    .pipe(gulpStyleLint({
    reporters: [
    {formatter: 'string', console: true}
    ]
    }));
    }); gulp.task("default", ["lint-css"]);

六、其他

  1. 在样式之前标注“/* stylelint-disable */”,可忽略配置的规则;标注“/* stylelint-enable */“,开启配置的规则
  2. “/* stylelint-enable */“必须在“/* stylelint-disable */”之后使用
  3. 忽略指定的内容:

    (1).stylelintrc

    {

    "rules": {

    "unit-no-unknown": [true, ignoreUnits:["xxx"]]

    }

    }

    (2)package.json && stylelint.config.js

    {

    "rules": {

    "at-rule-no-unknown": [true, {"ignoreAtRules": ["function", "if", "return", "include", "extend", "mixin", "else", "while", "for", "each"]}]

    }

    }

七、配置文件

1.

{

"rules": {

"color-hex-case": "lower",

"color-no-invalid-hex": true,

"at-rule-name-space-after": "always",

"at-rule-semicolon-newline-after": "always",

"at-rule-no-unknown": [true, ignoreAtRules: ["function", "if", "return", "include", "extend", "mixin", "else", "while", "for", "each"]],

"function-comma-space-after": "always",

"function-linear-gradient-no-nonstandard-direction": true,

"function-url-quotes": "always",

"function-whitespace-after": "always",

"number-leading-zero": "never",

"number-no-trailing-zeros": true,

"string-no-newline": true,

"string-quotes": "double",

"unit-case": "lower",

"unit-no-unknown": true,

"value-keyword-case": "lower",

"value-list-comma-newline-after": "always-multi-line",

"value-list-comma-space-after": "always",

"shorthand-property-no-redundant-values": true,

"declaration-bang-space-after": "never",

"declaration-bang-space-before": "always",

"declaration-colon-space-after": "always",

"declaration-colon-space-before": "never",

"declaration-block-no-ignored-properties": true,

"declaration-block-no-shorthand-property-overrides": true,

"declaration-block-semicolon-newline-after": "always-multi-line",

"declaration-block-semicolon-newline-before": "never-multi-line",

"declaration-block-semicolon-space-after": "always-single-line",

"declaration-block-semicolon-space-before": "never",

"declaration-block-trailing-semicolon": "always",

"block-no-empty": true,

"block-opening-brace-space-after": "always-single-line",

"block-opening-brace-space-before": "always",

"block-closing-brace-space-before": "always-single-line",

"selector-attribute-brackets-space-inside": "always",

"selector-attribute-operator-space-after": "always",

"selector-attribute-operator-space-before": "always",

"selector-combinator-space-after": "always",

"selector-combinator-space-before": "always",

"selector-max-compound-selectors": 4,

"selector-no-universal": true,

"selector-pseudo-class-case": "lower",

"selector-pseudo-class-no-unknown": true,

"selector-pseudo-element-case": "lower",

"selector-pseudo-element-no-unknown": true,

"selector-type-case": "lower",

"selector-max-empty-lines": 0,

"selector-list-comma-newline-before": "never-multi-line",

"selector-list-comma-space-after": "always-single-line",

"rule-nested-empty-line-before": "never",

"media-query-list-comma-newline-after": "always-multi-line",

"media-query-list-comma-space-after": "always-single-line",

"comment-whitespace-inside": "always",

"max-empty-lines": 1,

"max-nesting-depth": 4,

"no-descending-specificity": true,

"no-duplicate-selectors": true,

"no-empty-source": true,

"no-eol-whitespace": true,

"no-extra-semicolons": true,

"no-invalid-double-slash-comments": true,

"no-unknown-animations": true

}

}

八、配置文件说明

属性名 属性值 描述
[color-hex-case](http://stylelint.io/user-guide/rules/color-hex-case/) lower 颜色值为小写字母
[color-no-invalid-hex](http://stylelint.io/user-guide/rules/color-no-invalid-hex) true 颜色值不能为无效值
[at-rule-name-space-after](http://stylelint.io/user-guide/rules/at-rule-name-space-after) always @xx 后需空格
[at-rule-semicolon-new-new-line](http://stylelint.io/user-guide/rules/at-rule-semicolon-new-new-line) alway @xx 分号后要换行
[function-calc-no-unspaced-operator](http://stylelint.io/user-guide/rules/function-calc-no-unspaced-operator) true 方法中的计算符号左右需空格
[function-comma-space-after](http://stylelint.io/user-guide/rules/function-comma-space-after) always 方法中逗号后需空格
[function-linear-gradient-no-nonstandard-direction](http://stylelint.io/user-guide/rules/function-linear-gradient-no-nonstandard-direction) true linear-gradient()内参数严格按照css规范
[function-max-line-lines](http://stylelint.io/user-guide/rules/function-max-line-lines) 0 方法中参数允许0行空行
[function-parentheses-newline-inside](http://stylelint.io/user-guide/rules/function-parentheses-newline-inside) never-multi-line 方法中参数允许逗号后换行
[function-url-quotes](http://stylelint.io/user-guide/rules/function-url-quotes) always 地址一定要写引号
[function-whitespace-after](http://stylelint.io/user-guide/rules/function-whitespace-after) always 方法之间一定要空格
[number-leading-zero](http://stylelint.io/user-guide/rules/number-leading-zero) never 数字不以0开头。错误:0.5;正确:.5
[number-no-trailing-zeros](http://stylelint.io/user-guide/rules/number-no-trailing-zeros) true 不能有数字末尾多余的0。错误:1.000;正确:1
[string-no-newline](http://stylelint.io/user-guide/rules/string-no-newline) true 字符串之前不能有“\n"
[string-quotes](http://stylelint.io/user-guide/rules/string-quotes) double 字符串最外层用双引号,而不是单引号
[unit-case](http://stylelint.io/user-guide/rules/unit-case) lower 单位小写
[unit-no-unknown](http://stylelint.io/user-guide/rules/unit-no-unknown) true 不允许未知的单位
[value-keyword-case](http://stylelint.io/user-guide/rules/value-keyword-case) lower 属性值小写
[value-list-comma-newline-after](http://stylelint.io/user-guide/rules/value-list-comma-newline-after) always-multi-line 属性值列不允许逗号前换行
[value-list-comma-space-after](http://stylelint.io/user-guide/rules/value-list-comma-space-after) always 属性值列表逗号后需空格
[shorthand-properyu-no-redundat-values](http://stylelint.io/user-guide/rules/shorthand-properyu-no-redundat-values) true 可简写的属性不重复写,错误:margin: 1px 1px;
[declaration-bang-space-after](http://stylelint.io/user-guide/rules/declaration-bang-space-after) never !important中!后不空格
[declatation-bang-space-before](http://stylelint.io/user-guide/rules/declatation-bang-space-before) always !important中!前空一格
[declatation-colon-space-after](http://stylelint.io/user-guide/rules/declatation-colon-space-after) always 属性名冒号后空一格
[declatation-colon-space-before](http://stylelint.io/user-guide/rules/declatation-colon-space-before) never 属性名冒号前不空格
[declatation-block-no-ignored-properties](http://stylelint.io/user-guide/rules/declatation-block-no-ignored-properties) true 禁止那些由于在同一规则的另一个属性值忽略的属性值。
[declaration-block-no-shorthand-property-overrides](http://stylelint.io/user-guide/rules/declaration-block-no-shorthand-property-overrides) true 错误:border-top-width: 1px; border: 2px solid blue;
[declaration-block-semicolon-newline-after](http://stylelint.io/user-guide/rules/declaration-block-semicolon-newline-after) always-multi-line 一个模块要么整个模块一行显示,要么分号后分行显示
[declaration-block-semicolon-space-after](http://stylelint.io/user-guide/rules/declaration-block-semicolon-space-after) always-single-line 属性之间分号后空一格或换行
[declaration-block-semicolon-newline-before](http://stylelint.io/user-guide/rules/declaration-block-semicolon-newline-before) never-multi-line 分号前不允许换行
[declaration-block-semicolon-space-before](http://stylelint.io/user-guide/rules/declaration-block-semicolon-space-before) never 分号前不允许空格
[declaration-block-trailing-semicolon](http://stylelint.io/user-guide/rules/declaration-block-trailing-semicolon) always 模块内最后一个属性必须有分号
[block-no-empty](http://stylelint.io/user-guide/rules/block-no-empty) true 不允许模块内为空
[block-opening-brace-space-after](http://stylelint.io/user-guide/rules/block-opening-brace-space-after) always-single-line 模块单行时“{”后空一格
[block-opening-brace-space-before](http://stylelint.io/user-guide/rules/block-opening-brace-space-before) always “{”前空一格
[block-closing-brace-space-before](http://stylelint.io/user-guide/rules/block-closing-brace-space-before) always-single-line 模块单行时“}”前空一格
[selector-attribute-brackets-space-inside](http://stylelint.io/user-guide/rules/selector-attribute-brackets-space-inside) always “[”后空一格,“]”前空一格
[selector-attribute-operator-space-after](http://stylelint.io/user-guide/rules/selector-attribute-operator-space-after) always “[]”内的“=”后空一格
[selector-attribute-operator-space-before](http://stylelint.io/user-guide/rules/selector-attribute-operator-space-before) always “[]”内的“=”前空一格
[selector-combinator-space-after](http://stylelint.io/user-guide/rules/selector-combinator-space-after) always 选择器后空一格,例如:ul> li
[selector-combinator-space-before](http://stylelint.io/user-guide/rules/selector-combinator-space-before) always 选择器前空一格,例如:ul >li
[selector-max-compound-selectors](http://stylelint.io/user-guide/rules/selector-max-compound-selectors) 4 最多4层选择器
[selector-no-universal](http://stylelint.io/user-guide/rules/selector-no-universal) true 不允许通用选择器*
[selector-pseudo-class-case](http://stylelint.io/user-guide/rules/selector-pseudo-class-case) lower 伪类选择器小写(:hover之类)
[selector-pseudo-class-no-unknown](http://stylelint.io/user-guide/rules/selector-pseudo-class-no-unknown) true 不允许css规范外的伪类选择器(:hover之类)
[selector-pseudo-element-case](http://stylelint.io/user-guide/rules/selector-pseudo-element-case) lower 伪类选择器小写(:: before之类)
[selector-pseudo-element-no-unknown](http://stylelint.io/user-guide/rules/selector-pseudo-element-no-unknown) true 不允许css规范外的伪类选择器(:: before之类)
[selector-type-case](http://stylelint.io/user-guide/rules/selector-type-case lower 标签选择器小写
[selector-max-empty-lines](http://stylelint.io/user-guide/rules/selector-max-empty-lines) 0 选择器共用一个模块,选择器之间允许0行空白
[selector-list-comma-newline-before](http://stylelint.io/user-guide/rules/selector-list-comma-newline-before) never-multi-line 选择器共用一个模块,选择器之间要么一行,要么逗号后换行
[selector-list-comma-space-after](http://stylelint.io/user-guide/rules/selector-list-comma-space-after) always-single-line 选择器共用一个模块,选择器一行时,逗号后空一格
[rule-nested-empty-line-before](http://stylelint.io/user-guide/rules/rule-nested-empty-line-before) never 嵌套规则前不空行
[media-query-list-comma-newline-before](http://stylelint.io/user-guide/rules/media-query-list-comma-newline-before) always-single-line 媒体查询列表中不允许逗号之前换行
[media-query-list-comma-space-after](http://stylelint.io/user-guide/rules/media-query-list-comma-space-after) always-single-line 媒体查询列表中单行逗号之后空一格
[comment-whitespace-inside](http://stylelint.io/user-guide/rules/comment-whitespace-inside) always 注释符之间空格。错误:/*\* haha \*/;正确:/\* haha \*/
[max-empty-lines](http://stylelint.io/user-guide/rules/max-empty-lines) 1 内容之间最多允许1行空白行
[max-nesting-depth](http://stylelint.io/user-guide/rules/max-nesting-depth) 4 sass中允许嵌套的深度为4
[no-descending-specificity](http://stylelint.io/user-guide/rules/no-descending-specificity) true 选择的同一元素,不允许权重较轻的选择器出现在权重较重的之后
[no-duplicate-selectors](http://stylelint.io/user-guide/rules/no-duplicate-selectors) true 一个样式表不允许相同的选择器出现
[no-empty-source](http://stylelint.io/user-guide/rules/no-empty-source) true 样式表不允许为空
[no-eol-whitespace](http://stylelint.io/user-guide/rules/no-eol-whitespace) true 样式表末尾不允许空行
[no-extra-semicolons](http://stylelint.io/user-guide/rules/no-extra-semicolons) true 不允许多余的分号
[no-invalid-double-slash-comments](http://stylelint.io/user-guide/rules/no-invalid-double-slash-comments) true 不允许//注释
[no-unknown-animations](http://stylelint.io/user-guide/rules/no-unknown-animations) true> animation的name不能是keyframes没有定义的

stylelint — css书写规范的更多相关文章

  1. CSS书写规范、命名规范、网易CSS框架NEC

    网易CSS框架NEC:http://nec.netease.com/ NEC框架的CSS规范:  CSS规范 - 分类方法 CSS规范 - 命名规则 CSS规范 - 代码格式 CSS规范 - 优化方案 ...

  2. html和css书写规范

    HTML 规范 分离的标记.样式和脚本 结构.表现.行为分离 在可能情况下验证你的标记 使用编辑器验证你的标记是否正确,一般编辑器都自带有这个功能. 技术不支持的时候使用备胎,如canvas 编码格式 ...

  3. CSS书写规范

    一.CSS书写顺序 1.位置属性(position,top,right,z-index,display,float等) 2.大小(width,height,padding,margin) 3.文字系列 ...

  4. 推荐大家使用的CSS书写规范、顺序

    写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里总结一个CSS书写规范.CSS书写顺序供大家参考,这些是参考了国外一些文章以及我的个人经 ...

  5. 分享给大家的CSS书写规范、顺序

    写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里总结一个CSS书写规范.CSS书写顺序供大家参考,这些是参考了国外一些文章以及我的个人经 ...

  6. CSS书写规范及顺序

    CSS书写顺序 1.位置属性(position, top, right, z-index, display, float等)2.大小(width, height, padding, margin)3. ...

  7. 推荐大家使用的CSS书写规范及顺序

    @设计达人网 写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里我总结一个CSS书写规范.CSS书写顺序供大家参考,这些是参考了国外一些文 ...

  8. CSS书写规范、顺序

    写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,总结一个CSS书写规范.CSS书写顺序供大家参考,这些是参考了国外一些文章以及我的个人经验总 ...

  9. CSS书写规范、顺序和命名规则

    写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里总结一个CSS书写规范.CSS书写顺序供大家参考   这些是参考了国外一些文章以及我的个 ...

随机推荐

  1. Bootstrap-table实现动态合并相同行(表格同名合并)

    写在前面: 有时候表格的需求就是奇奇怪怪的,最近要做的表格需要实现当紧挨着的记录的某一列的行元素内容相同,就将其合并.要是不是相同的就不合并.如果表格数据的顺序不需要被改变,这个样子是可以很简单就完成 ...

  2. 【java】java中直接根据Date 获取明天的时间

    展示代码: @Test public void dateTest(){ Date now = new Date(); System.out.println(now); // java.util.Dat ...

  3. 自己做的javascript简易计算器

    html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF- ...

  4. 《linux 内核全然剖析》 chapter 4 80x86 保护模式极其编程

    80x86 保护模式极其编程       首先我不得不说.看这章真的非常纠结...看了半天.不知道这个东西能干嘛.我感觉唯一有点用的就是对于内存映射的理解...我假设不在底层给80x86写汇编的话.我 ...

  5. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.1.安装并配置ASM驱动

    3.1.安装并配置ASM驱动 3.3.1.检查内核 [root@linuxrac2 etc]# uname -r 2.6.18-164.el5 下载以下rpm包(注意rpm包版本和Linux内核版本一 ...

  6. javascript快速入门12--函数式与面向对象

    函数 函数是一组可以随时随地运行的语句. 函数是 ECMAScript 的核心. 创建函数 function fnOne() {//具有名称的函数,函数名必须符合变量名命名规范 //可以没有符何语句 ...

  7. dx12 memory management

    https://msdn.microsoft.com/en-us/library/windows/desktop/dn508285(v=vs.85).aspx Map with D3D11_MAP_W ...

  8. D3.js系列——比例尺和坐标轴

    比例尺是 D3 中很重要的一个概念.绘制图形时直接用数值的大小来代表像素不是一种好方法,本章正是要解决此问题. 一.为什么需要比例尺 上一章制作了一个柱形图,当时有一个数组,绘图时,直接使用 250 ...

  9. http://www.binghe.org/2010/03/use-httpsurlconnection-in-java/

    http://www.binghe.org/2010/03/use-httpsurlconnection-in-java/

  10. Tempter of the Bone——DFS(王道)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...