【问题标题】:My gulp-eslint is not working?我的 gulp-eslint 不工作?
【发布时间】:2016-10-12 22:28:43
【问题描述】:

我正在尝试使用 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; 添加到位于我项目中src 文件夹中的main.js 文件,然后在保存lint 任务后再次运行,但在终端中没有给出任何错误:

自动重新加载时的页面也是如此,所以当我手动重新加载它时它会继续加载和加载,所以它停止重新加载,这在这个 eslint 之前没有发生..! 那么有人可以告诉我这里有什么问题吗?

【问题讨论】:

  • 检查下面的答案,如果没有帮助,我会删除它

标签: node.js gulp eslint


【解决方案1】:

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

默认情况下不启用任何规则。配置文件中的"extends": "eslint:recommended" 属性启用报告常见问题的规则。

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

  • "off"0 - 关闭规则
  • "warn"1 - 打开规则作为警告(不影响退出代码)
  • "error"2 - 将规则作为错误打开(触发时退出代码为 1)

以下将启用所有推荐的 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
},

【讨论】:

  • 另外请您告诉我为什么页面一直在我的浏览器中加载,并且当 lint 任务和 js 在第一次后再次运行时永远不会停止???
  • 我不明白这个问题。你是做什么的?会发生什么?如果你没有给出问题的清晰描述和重现问题的步骤,我真的帮不了你。
  • 我认为它现在似乎工作正常:recordit.co/uMvd1aQORU
  • 嗯..问题是当我从 JS 文件中添加或删除某些内容时,我的 localhost 页面会继续加载和加载..你可以看看上面的链接..!跨度>
  • 我认为您的lint 任务不会对此负责。执行 connect.reload() 任务的是您的 js 任务,而不是您的 lint 任务。可能是 livereload 的一个怪癖。如果它不再发生,就不会担心它。
猜你喜欢
  • 2016-07-08
  • 2018-04-19
  • 1970-01-01
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多