Javascript 吞咽埃斯林特不';找不到我的.eslintrc文件
似乎找不到我的Javascript 吞咽埃斯林特不';找不到我的.eslintrc文件,javascript,node.js,gulp,eslint,Javascript,Node.js,Gulp,Eslint,似乎找不到我的.eslintrc文件mygulp eslint 我定义了一个lint任务: gulp.task('lint', function () { gulp.src(['src/**/*.js', 'src/**/*.jsx']) .pipe(eslint()) .pipe(eslint.format()); }) 它运行,但没有显示任何错误 我的.eslintrc文件在src文件夹中定义。我试图将它移动到我的项目的根文件夹,但它没有改变任何东西 这是一个非常简单的文件:
.eslintrc
文件mygulp eslint
我定义了一个lint
任务:
gulp.task('lint', function () {
gulp.src(['src/**/*.js', 'src/**/*.jsx'])
.pipe(eslint())
.pipe(eslint.format());
})
它运行,但没有显示任何错误
我的.eslintrc
文件在src
文件夹中定义。我试图将它移动到我的项目的根文件夹,但它没有改变任何东西
这是一个非常简单的文件:
{
"parser": "babel-eslint",
"ecmaFeatures": {
"classes": true,
"jsx": true
},
"plugins": [
"react"
],
"extends": "eslint-config-airbnb"
}
当我在终端中运行eslint src
时,我得到一堆eslint错误,这很好
知道什么不正常工作吗?根据管道中的错误,您需要失败
gulp.task('lint', function () {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['**/*.js','!node_modules/**'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
只是提醒一下,在使用配置文件、它们的使用优先级以及它们的位置方面,非常有用且简洁。还可以添加路径以指定特定管道的配置文件位置:
gulp.task('lint', function () {
gulp.src(['src/**/*.js', 'src/**/*.jsx'])
.pipe(eslint({ configFile: '.eslintrc'}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
在gulp eslint中,应该注意,建议使用failOnError()和failAfterError()方法,因为任务/流已停止,因此不会向输出写入无效代码
如果两者都不使用,则仍会捕获错误,但仅显示在控制台输出中。因此,根据您的任务流和设计,目标文件可能仍然会被写入,但您可以方便地立即更正错误并继续,而无需再次启动管道处理/监视任务。另一种方法是研究或其他一些方法,通过这些方法,您既不会中断gulp watch任务,也不会编写包含未通过linting验证的代码的文件。您必须捕获gulp中的错误。