javascript - Gulp eslint 找不到我的 .eslintrc 文件

标签 javascript node.js gulp eslint

看起来我的 .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 错误,这很好。

知道什么地方不能正常工作吗?

最佳答案

根据docs您需要因管道中的错误而失败。

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());
});

关于javascript - Gulp eslint 找不到我的 .eslintrc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36136737/

相关文章:

javascript - Angular ui-sortable 不适用于移动设备

node.js - 为什么 OpenShift 上的 Ghost node_modules 比本地大得多?

node.js - 错误 : Cannot find module 'jasmine-core'

javascript - 本地安装 gulp 插件与全局安装 gulp 插件

javascript - Jquery:获取 parent 的 parent

javascript - 如何使 jquery 图像在屏幕尺寸上动态替换而不是仅在刷新时替换?

php - 如何在 Google map API 标记上添加数字?

node.js - Sequelize destroy 无法测试真实性

node.js - Team Build 停止并等待 Gulp 任务完成

javascript - gulp.watch() 不适用于 ftp 更新