• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sasstools/gulp-sass-lint: Gulp plugin for Sass Lint

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sasstools/gulp-sass-lint

开源软件地址(OpenSource Url):

https://github.com/sasstools/gulp-sass-lint

开源编程语言(OpenSource Language):

JavaScript 84.9%

开源软件介绍(OpenSource Introduction):

Gulp Sass Lint npm version

Gulp plugin for Sass Lint.

Install

npm install gulp-sass-lint --save-dev

Usage

gulpfile.js

'use strict';

var gulp = require('gulp'),
    sassLint = require('gulp-sass-lint');

gulp.task('default', function () {
  return gulp.src('sass/**/*.s+(a|c)ss')
    .pipe(sassLint())
    .pipe(sassLint.format())
    .pipe(sassLint.failOnError())
});

API

sassLint(options)

You can pass an object of options to configure gulp-sass-lint to your specific projects needs the options are listed below.

options.options

You can find out more about the specific SassLint options from the SassLint Documentation

{
  options: {
    formatter: 'stylish',
    'merge-default-rules': false
  }
}

By default SassLint includes it's own configuration file, if you provide one it attempts to merge everything except for the files section below. If you pass options directly into the plugin they take precedence. The order can be visualised below with the SassLint config being the base.

options > config file > SassLint default included config

You can disable this behaviour by setting merge-default-rules to false within the options.options object that you pass to gulp-sass-lint or you can include it in your config file options that you can pass into gulp-sass-lint with options.configFile.

More info and examples can be found within the SassLint docs

options.files

Type: Object

Within the files object you can specify a glob pattern as a string or an array of glob pattern for both the include and ignore options. Please note that your include option will currently be ignored as you should be passing the glob patterns / file paths to be linted directly to gulp gulp.src('sass/**/*.s+(a|c)ss'). The ignore option however will still be respected if you'd rather specify them in your config rather than in the gulp.src method.

{
  files: {
    include: '**/*.scss', // This will be ignored by gulp-sass-lint
    ignore: 'test/**/*.scss' // This will still be respected and read
  }
}

options.rules

Type: Object

You can define which rules you would like to use here and set a severity too. For more information see how to configure and also the SassLint rules

{
  rules: {
    'no-ids': 0, // Severity 0 (disabled)
    'no-mergeable-selectors': 1, // Severity 1 (warning)
    'hex-length': [
      2, // Severity 2 (error)
      {
        'style': 'long'
      }
    ]
  }
}

options.configFile

You can pass the path to a custom config file via the configFile option. The path will be relative to where you're running gulp from.

{
  configFile: 'app/config/.my-config.yml'
}

Example

The following highlights all of the above options in use

'use strict';

var gulp = require('gulp'),
    sassLint = require('gulp-sass-lint');

gulp.task('default', function () {
  return gulp.src('sass/**/*.s+(a|c)ss')
    .pipe(sassLint({
      options: {
        formatter: 'stylish',
        'merge-default-rules': false
      },
      files: {ignore: '**/*.scss'},
      rules: {
        'no-ids': 1,
        'no-mergeable-selectors': 0
      },
      configFile: 'config/other/.sass-lint.yml'
    }))
    .pipe(sassLint.format())
    .pipe(sassLint.failOnError())
});

sassLint.format(writable)

Formats the results dependent on your config file or the options you provided to the sassLint task above. The default format is stylish but you can choose any of the others that SassLint provides, see the docs.

You can also choose to output to a file from within the options you provide or your config file. See the output-file docs

gulp.task('lint_sass_jenkins', function () {
    var file = fs.createWriteStream('reports/lint_sass.xml');
    var stream = gulp.src('public/sass/**/*.scss')
        .pipe(sassLint({
            options: {
                configFile: '.sass-lint.yml',
                formatter: 'checkstyle'
            }
        }))
        .pipe(sassLint.format(file));
    stream.on('finish', function() {
        file.end();
    });
    return stream;
});

sassLint.failOnError()

Fails the task and emits a gulp error when all files have been linted if an error has been detected (rules set to severity 2).




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
marcinkrzeminski/gulp-starter-kit: My Gulp Starter Kit发布时间:2022-06-21
下一篇:
sindresorhus/gulp-jasmine: Run Jasmine tests in Node.js发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap