通过 cmets 禁用
2016 年 12 月更新,根据 the docs,现在可以使用以下语法:
为整个文件禁用超过 1 条规则
// sass-lint:disable border-zero, quotes
p {
border: none; // No lint reported
content: "hello"; // No lint reported
}
为单行禁用规则
p {
border: none; // sass-lint:disable-line border-zero
}
禁用块内的所有 lint(以及所有包含的块)
p {
// sass-lint:disable-block border-zero
border: none; // No result reported
}
新信息由评论者 @IanRoutledge 提供。
但是,之前,如果您想禁用某些规则,但仅限于特定代码块和/或代码片段。 据我所知,从底层源代码tell 使用 sass-lint不可能。我也尝试了其他一些搜索,并且大致浏览了代码库,但没有发现您正在寻找的功能存在的提示。
为了比较,this query for the scss-lint source code 清楚地表明它是在那里实现的,在您使用的库中似乎没有类似的解决方案。
通过 yml 配置禁用
您可以在一般情况下禁用规则。您需要有一个.sass-lint.yml 文件才能禁用警告。
假设你有这个gulpfile.js:
'use strict';
var gulp = require('gulp'),
sassLint = require('gulp-sass-lint');
gulp.task('default', [], function() {
gulp.src('sass/*.scss')
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
还有这个package.json:
{
"devDependencies": {
"gulp": "^3.9.0",
"gulp-sass": "^2.1.1",
"gulp-sass-lint": "^1.1.1"
}
}
在这个styles.scss 文件上运行:
div { dsply: block; }
你得到这个输出:
[23:53:33] Using gulpfile D:\experiments\myfolder\gulpfile.js
[23:53:33] Starting 'default'...
[23:53:33] Finished 'default' after 8.84 ms
sass\styles.scss
1:7 warning Property `dsply` appears to be spelled incorrectly no-misspelled-properties
1:21 warning Files must end with a new line final-newline
??? 2 problems (0 errors, 2 warnings)
现在,如果您在 gulpfile 旁边添加一个 .sass-lint.yml 文件,其内容如下:
rules:
no-misspelled-properties: 0
你会看到:
[23:54:56] Using gulpfile D:\experiments\myfolder\gulpfile.js
[23:54:56] Starting 'default'...
[23:54:56] Finished 'default' after 9.32 ms
sass\styles.scss
1:21 warning Files must end with a new line final-newline
??? 1 problem (0 errors, 1 warning)
现在忽略其中一个警告。
The sass-lint readme.md 链接到the apparent default config,其中有更多示例。