让sass-lint忽略某一行? [英] Have sass-lint ignore a certain line?

查看:130
本文介绍了让sass-lint忽略某一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Gulp上使用 sass -lint。如何从lint控制台输出中禁用我sass中特定样式的警告?



我发现了一个类似的问题,但我使用的是 sass -lint,而不是 scss -lint:
让scss-lint忽略特定行 p>

这是我正在使用的那个: https://www.npmjs.com/package/gulp-sass-lint



我尝试了一些基于 scss -lint项目:

  // scss-lint:disable ImportantRule 
// sass-lint:禁用ImportantRule
// sass-lint:禁用不重要的

为了清楚起见,我想在我的SASS中禁用特定样式的警告,而不是全局警告。当触发警告的事件是故意的时候,我会使用它。例如,我可能会设置多种背景样式,因此可以作为旧版浏览器的后备。但目前这引发了不重复属性警告。

解决方案

通过评论禁用

根据文档,现在可以使用以下语法: / b>


禁用整个文件超过1个规则

  // sass-lint:禁用border-zero,引号

p {
border:none; //无lint报告
内容:hello; //无lint报告
}

为单行禁用规则

  p {
border:none; // sass-lint:disable-line border-zero
}

禁用块中的所有块(以及所有包含的块)

  p {
// sass-lint :disable-block border-zero
border:none; //没有结果报告


$ / pre


$ <$>新信息由@IanRoutledge提供。



然而, 之前,如果您想禁用某些规则,但仅限于特定的代码块和/或代码段。只要我可以告诉底层的源代码,它可以不用sass-lint来实现。我也尝试了其他一些搜索,并且一般地浏览了代码库,但没有发现您正在寻找的功能存在的提示。



用于比较,此查询scss-lint源代码清楚显示它在那里实现,这种方式似乎没有类似的解决方案。



禁用直通yml configs



You can 通常会禁用规则。您需要有一个 .sass-lint.yml 文件来禁用警告。



假设您有 gulpfile.js

 'use strict'; 
$ b $ 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]使用gulpfile D:\experiments\myfolder\gulpfile.js 
[23:53:33]开始'default'...
[23:53:33] 8.84 ms后完成'default'

sass\styles.scss
1:7警告属性`dsply`似乎拼写错误没有拼写错误的属性
1:21警告文件必须以新行结束换行

??? 2个问题(0个错误,2个警告)

现在如果添加

 规则:$ b包含以下内容的gulp文件旁边的sass-lint.yml 文件$ b没有拼写错误的属性:0 

你会看到:

  [23:54:56]使用gulpfile D:\experiments \myfolder\gulpfile.js 
[23:54:56]开始'默认'...
[23:54:56] 9.32 ms后完成'default'

sass\styles.scss
1:21警告文件必须以新行结束换行

??? 1个问题(0个错误,1个警告)

其中一个警告现在被忽略。



sass-lint readme.md 链接到明显的默认配置,它有更多的例子。

I'm using sass-lint with Gulp. How can I disable warnings for a particular style in my sass from the lint console output?

I've found a similar question but I'm using sass-lint, not scss-lint: Having scss-lint ignore a particular line

This is the one I'm using: https://www.npmjs.com/package/gulp-sass-lint

I've tried a few variations based off of the scss-lint project:

// scss-lint:disable ImportantRule
// sass-lint:disable ImportantRule
// sass-lint:disable no-important

Just to be clear, I want to disable warnings for a specific style in my SASS, not globally. I will use this when the thing triggering the warning is intentional. For instance I might set multiple background styles so one can be a fallback for older browsers. But currently this is triggering the no-duplicate-properties warning.

解决方案

Disabling through comments

Update per December 2016 according to the docs this will now be possible using this syntax:

Disable more than 1 rule for entire file

// sass-lint:disable border-zero, quotes

p {
  border: none; // No lint reported
  content: "hello"; // No lint reported
}

Disable a rule for a single line

p {
  border: none; // sass-lint:disable-line border-zero
}

Disable all lints within a block (and all contained blocks)

p {
  // sass-lint:disable-block border-zero
  border: none; // No result reported
}

New info courtesy of commenter @IanRoutledge.

However, before, if you wanted to disable certain rules, but only for specific code blocks and/or pieces of the code. As far as I can tell from the underlying source code it would not be possible with sass-lint. I've tried a few other searches as well, and skimmed the code base in general, but found no hint that the feature you're looking for exists.

For comparison, this query for the scss-lint source code clearly shows it is implemented there, in a fashion that doesn't seem to have an analogous solution in the lib you are using.

Disabling through yml configs

You can disable rules in general though. You need to have a .sass-lint.yml file to disable warnings.

Suppose you have this 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());
});

And this package.json:

{
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-sass": "^2.1.1",
    "gulp-sass-lint": "^1.1.1"
  }
}

Running on this styles.scss file:

div { dsply: block; }

You get this output:

[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)

Now if you add a .sass-lint.yml file next to the gulpfile, with this content:

rules:
  no-misspelled-properties: 0

You'll instead see:

[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)

One of the warnings is now ignored.

The sass-lint readme.md links to the apparent default config which has some more examples.

这篇关于让sass-lint忽略某一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆