当我从命令行运行"gulp样式“时,Gulp将运行,随后将运行gulp,但后者似乎无法检测jscs配置文件(.jscsrc)中定义的规则。但是,如果我从命令行运行jscs,那么jscs就会检测到配置文件的规则。知道这笔交易可能是什么吗?
这是我的吞咽文件:
(function() {
"use strict";
var gulp = require("gulp");
var jshint = require("gulp-jshint");
var jscs = require("gulp-jscs");
var jsFiles = ["*.js", "src/**/*.js"];
gulp.task("style", function () {
console.log("Running the style task.");
return gulp.src(jsFiles)
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish", {
verbose: true
}))
.pipe(jscs({configPath: "./.jscsrc"}));
});
})();发布于 2015-12-25 12:51:21
您需要一个记者 (就像jshint有一个):
var gulp = require("gulp");
var jshint = require("gulp-jshint");
var jscs = require("gulp-jscs");
var jsFiles = ["*.js", "src/**/*.js"];
gulp.task("style", function () {
console.log("Running the style task.");
return gulp.src(jsFiles)
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish", {
verbose: true
}))
.pipe(jscs({configPath: "./.jscsrc"}))
.pipe(jscs.reporter()); // << this line here
});其他注意事项,(如果从cmd运行),Gulpfile.js不需要将其包装到匿名函数或使用'use strict'。
示例输出:
[13:53:30] Using gulpfile C:\del\so\gulpjscs\Gulpfile.js
[13:53:30] Starting 'style'...
Running the style task.
[13:53:31] gulp-debug: Gulpfile.js
[13:53:31] gulp-debug: index.js
[13:53:31] gulp-debug: 2 items
Comments must start with a lowercase letter at C:\del\so\gulpjscs\index.js :
1 |// Invalid
--------^
2 |// valid
3 |
1 code style error found.
[13:53:31] Finished 'style' after 187 ms如果您不确定如何考虑当前路径./,则可以始终使用path模块来解析,例如:
var path = require('path');
var configPath = path.resolve(path.join(__dirname, '.jscsrc'))https://stackoverflow.com/questions/34458154
复制相似问题