2016-06-12 54 views
-1

我正在嘗試使用gulp-eslint顯示終端中的錯誤,但它不工作..!我的大嘴巴不工作?

我的項目的源代碼在GitHubhttps://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在我的項目文件夾,然後保存後皮棉任務又跑了回來,但在終端沒有給出任何錯誤爲:

enter image description here

而且頁面時自動重新加載,因此它保持載荷和載荷時,我手動重新加載它,然後它停止重裝其中WASN在此之前發生的事情!! 所以任何人都可以讓我知道這裏有什麼問題?

+0

檢查答案,如果它不能幫助,我會刪除它 –

回答

1

原因未記錄錯誤是因爲您沒有啓用任何rules

沒有規則默認情況下啓用。配置文件中的"extends": "eslint:recommended"屬性可啓用報告常見問題的規則。關閉規則關閉

  • "warn"1 - - 把規則作爲警告(不影響

    • "off"0

    和所有配置中的are switched off規則退出代碼)

  • "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 
    }, 
    
    +0

    也請你讓我知道爲什麼頁面不斷加載在我的瀏覽器,然後永不停止當皮棉任務和js第一次運行時再次運行? –

    +0

    我不明白這個問題。你做了什麼?會發生什麼?如果你沒有給出清楚的問題描述和重現問題的步驟,我無法真正幫助你。 –

    +0

    我認爲它現在好像工作正常:http://recordit.co/uMvd1aQORU –