Gulp eslint 找不到我的 .eslintrc 文件
Gulp eslint doesn't find my .eslintrc file
看起来我的.eslintrc
文件找不到我的gulp-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-plumber 或其他一些方法,这样您就不会突破 gulp 监视任务,也不会编写包含未通过 linting 验证的代码的文件。
相关文章:
- 如何播放部分音频文件
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用WCF服务和javascript表单post上传.doc文件
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何在php文件中获取$.post-ajax传递的值
- 直接下载文件,而不是从window.open(url)
- 如何在android中使用phonegap将文件从一个文件夹移动/复制到另一个文件夹
- 使用压缩的JavaScript文件(不是运行时压缩)
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 如何在elfinder插件(一个文件管理器插件)上获得上传前事件
- Javascript运行php文件,然后下载文件
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 我应该如何从xml文件构建一个javascript页面
- Gulp eslint 找不到我的 .eslintrc 文件