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

jscs-dev/gulp-jscs: Check JavaScript code style with jscs

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

开源软件名称(OpenSource Name):

jscs-dev/gulp-jscs

开源软件地址(OpenSource Url):

https://github.com/jscs-dev/gulp-jscs

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-jscs Build Status

Check JavaScript code style with JSCS

Issues with the output should be reported on the JSCS issue tracker.

Install

$ npm install --save-dev gulp-jscs

Usage

Reporting

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs())
		.pipe(jscs.reporter());
});

Fixing

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs({fix: true}))
		.pipe(gulp.dest('src'));
});

Reporting & fixing & failing on lint error

const gulp = require('gulp');
const jscs = require('gulp-jscs');

gulp.task('default', () => {
	return gulp.src('src/app.js')
		.pipe(jscs({fix: true}))
		.pipe(jscs.reporter())
		.pipe(jscs.reporter('fail'))
		.pipe(gulp.dest('src'));
});

Results

A jscs object will be attached to the file object.
An example with one error might look like this:

{
	success: false,  // or true if no errors
	errorCount: 1,   // number of errors in the errors array
	errors: [{       // an array of jscs error objects
		filename: 'index.js',  // basename of the file
		rule: 'requireCamelCaseOrUpperCaseIdentifiers',  // the rule which triggered the error
		message: 'All identifiers must be camelCase or UPPER_CASE',  // error message
		line: 32,  // error line number
		column: 7  // error column
	}]
};

API

JSCS config should be placed in a .jscsrc file.

jscs([options])

options

fix

Type: boolean
Default: false

Make JSCS attempt to auto-fix your files.
Be sure to pipe to gulp.dest if you use this option.

configPath

Type: string
Default: JSCS will search for the config file up to your home directory.

Set the path to the JSCS config file.
Only use this option when it can't be found automatically.

jscs.reporter([reporter])

reporter

Type: string
Default: console

See the JSCS reporter docs for supported input.

Can be used multiple times in the same pipeline.

This plugin also ships with some custom reporters:

  • fail - Emits an error at the end of the stream if there are lint errors.
  • failImmediately - Emits an error immediately if there are lint errors.

License

MIT © Sindre Sorhus




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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