sass-lint 是否忽略了某行? [英] Have sass-lint ignore a certain line?

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

问题描述

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

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

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

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

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

我尝试了一些基于 scss-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

为了清楚起见,我想在我的 SASS 中禁用特定样式的警告,而不是全局.当触发警告的事情是故意的时,我会使用它.例如,我可能会设置多种背景样式,以便可以作为旧浏览器的后备样式.但目前这正在触发 no-duplicate-properties 警告.

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.

推荐答案

通过评论禁用

2016 年 12 月更新,根据 文档现在可以使用以下语法:

Disabling through comments

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

为整个文件禁用超过 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 提供.

但是,之前,如果您想禁用某些规则,但仅限于特定代码块和/或代码片段.尽我所能告诉底层源代码不可能使用 sass-lint.我也尝试了其他一些搜索,并且大致浏览了代码库,但没有发现您正在寻找的功能存在的提示.

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.

为了比较,这个查询scss-lint源代码 清楚地表明它 在那里实现,在您使用的库中似乎没有类似的解决方案.

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.

可以在一般情况下禁用规则.您需要有一个 .sass-lint.yml 文件来禁用警告.

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

假设你有这个 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 文件上运行:

Running on this styles.scss file:

div { dsply: block; }

你得到这个输出:

[23:53:33] Using gulpfile D:experimentsmyfoldergulpfile.js
[23:53:33] Starting 'default'...
[23:53:33] Finished 'default' after 8.84 ms

sassstyles.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 文件,其内容如下:

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

rules:
  no-misspelled-properties: 0

你会看到:

[23:54:56] Using gulpfile D:experimentsmyfoldergulpfile.js
[23:54:56] Starting 'default'...
[23:54:56] Finished 'default' after 9.32 ms

sassstyles.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.

sass-lint readme.md 链接到 明显的默认配置,其中有更多示例.

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

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

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