我的 gulp-eslint 不工作?

My gulp-eslint is not working?

我正在尝试使用 gulp-eslint 来显示终端中的错误,但它不起作用..!

我在 GitHub 的项目源代码:https://github.com/nicefellow1234/react-skeleton

我的 gulpfile.js :

"use strict";

var gulp = require('gulp');
var connect = require('gulp-connect'); // Runs a local Dev Server
var open = require('gulp-open'); // Open a URL in a Web Browser
var browserify = require('browserify'); // Bundles JS
var reactify = require('reactify'); // Transforms React JSX to JS
var source = require('vinyl-source-stream'); // Use Conventional text strams with Gulp
var concat = require('gulp-concat'); // Concatenates files
var lint = require('gulp-eslint'); // Lint JS files, including JSX

var config = {
    port: 9005,
    devBaseUrl: 'http:localhost',
    paths: {
        html: './src/*.html',
        js: './src/**/*.js',
        css : [
            'node_modules/bootstrap/dist/css/bootstrap.min.css',
            'node_modules/bootstrap/dist/css/bootstrap-theme.min.css'
        ],
        dist: './dist',
        mainJs: './src/main.js'
    }
}

gulp.task('connect', function(){
    connect.server({
        root: ['dist'],
        port: config.port,
        base: config.devBaseUrl,
        livereload: true
    });
});

gulp.task('open', ['connect'], function() {
    gulp.src(__filename)
    .pipe(open({ uri : config.devBaseUrl + ':' + config.port + '/'}))

});

gulp.task('html', function() {
    gulp.src(config.paths.html)
    .pipe(gulp.dest(config.paths.dist))
    .pipe(connect.reload());
});

gulp.task('js', function() {
    browserify(config.paths.mainJs)
    .transform(reactify)
    .bundle()
    .on('error',function() { 
        console.error(console)})
    .pipe(source('bundle.js'))
    .pipe(gulp.dest(config.paths.dist + '/scripts'))
    .pipe(connect.reload());
});


gulp.task('css', function() {
    gulp.src(config.paths.css)
    .pipe(concat('bundle.css'))
    .pipe(gulp.dest(config.paths.dist + '/css'));
});

gulp.task('lint', function() {
    return gulp
    .src(config.paths.js)
    .pipe(lint({config: 'eslint.config.json'}))
    .pipe(lint.format())
    .pipe(lint.failAfterError());
});


gulp.task('watch', function(){
    gulp.watch(config.paths.html, ['html']);
    gulp.watch(config.paths.js, ['js','lint']);
});

gulp.task('default',['html','js','css','lint','open','watch']);

我的 eslint.config.json 文件:

{
  "ecmaFeatures": {
    "jsx": true
  },
  "env": {
    "browser": true,
    "node": true,
    "jquery": true
  },
  "rules": {
    "quotes": 0,
    "no-trailing-spaces": 0,
    "eol-last": 0,
    "no-unused-vars": 0,
    "no-underscore-dangle": 0,
    "no-alert": 0,
    "no-lone-blocks": 0
  },
  "globals": {
    "jQuery": true,
    "$": true
  }
}

我尝试将 test: 1; 添加到 main.js 文件,该文件位于我项目的 src 文件夹中,然后在保存 lint 任务后 运行 再次返回但是没有'在终端中给出任何错误:

还有自动重新加载时的页面,所以当我手动重新加载它时它一直在加载和加载,所以它停止了重新加载,这在这个 eslint 之前没有发生过..! 那么谁能告诉我这里的问题是什么?

没有记录错误的原因是您没有启用任何 rules:

No rules are enabled by default. The "extends": "eslint:recommended" property in a configuration file enables rules that report common problems.

以及您配置中的所有规则are switched off

  • "off" or 0 - turn the rule off
  • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)
  • "error" or 2 - turn the rule on as an error (exit code is 1 when triggered)

以下将启用所有推荐的 eslint 规则,以及您 eslint.config.json 文件中已有的规则:

"extends": "eslint:recommended",
"rules": {
  "quotes": 2,
  "no-trailing-spaces": 2,
  "eol-last": 2,
  "no-unused-vars": 2,
  "no-underscore-dangle": 2,
  "no-alert": 2,
  "no-lone-blocks": 2
},