首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.eslintrc找不到我的.eslintrc文件

.eslintrc找不到我的.eslintrc文件
EN

Stack Overflow用户
提问于 2016-03-21 16:35:58
回答 2查看 2.8K关注 0票数 1

看起来我的.eslintrc文件没有找到我的gulp-eslint

我定义了一个lint任务:

代码语言:javascript
复制
gulp.task('lint', function () {
  gulp.src(['src/**/*.js', 'src/**/*.jsx'])
  .pipe(eslint())
  .pipe(eslint.format());
})

它运行,但没有显示任何错误。

我的.eslintrc文件在src文件夹中定义。我试着把它移到我的项目的根文件夹,但是它没有改变任何东西。

这是一个非常简单的文件:

代码语言:javascript
复制
{
  "parser": "babel-eslint",
  "ecmaFeatures": {
    "classes": true,
    "jsx": true
  },
  "plugins": [
    "react"
  ],

  "extends": "eslint-config-airbnb"
}

当我在终端中运行eslint src时,会得到大量的eslint错误,这很好。

知道什么不合适吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-21 16:39:30

根据文档,您需要在管道中失败。

代码语言:javascript
复制
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());
});
票数 1
EN

Stack Overflow用户

发布于 2017-08-08 23:22:51

文档只是一个提示,它在使用配置文件、它们的使用优先级以及它们的位置方面非常有用和简洁。还可以添加路径以指定特定管道的配置文件位置:

代码语言:javascript
复制
gulp.task('lint', function () {
  gulp.src(['src/**/*.js', 'src/**/*.jsx'])
  .pipe(eslint({ configFile: '.eslintrc'}))
  .pipe(eslint.format())
  .pipe(eslint.failAfterError())
})

在gulp 文档中,应该注意使用failOnError()和failAfterError()方法是可取的,因为任务/流已经停止,因此不存在写入输出的无效代码。

如果两个都不使用,那么错误仍然会被捕获,但只显示在控制台输出中。因此,取决于您的任务流程和设计,目标文件可能仍然会被写入,但是您可以方便地立即更正错误并继续执行,而不必再次启动管道处理/监视任务。另一种选择是研究咽喉工或其他一些方法,在这种方法中,您不会跳出一个庞大的监视任务,同时也不会编写一个包含代码的文件,这些代码不会通过linting验证。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36136737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档