twitter-bootstrap 使用 Gulp 抑制 JSHint 中的分号警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32160234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:05:02  来源:igfitidea点击:

Suppressing Semicolon Warnings in JSHint with Gulp

javascripttwitter-bootstrapgulpjshint

提问by Marc Rudkowski

I am currently using JSHint with my Gulp workflow, and would like to suppress the semicolon errors when working with JavaScript.

我目前在 Gulp 工作流程中使用 JSHint,并希望在使用 JavaScript 时抑制分号错误。

I'm currently using gulp-jshint. How do I enable the "asi" flag within Gulp to make the errors go away?

我目前正在使用 gulp-jshint。如何在 Gulp 中启用“asi”标志以使错误消失?

The type of error I am receiving is:

我收到的错误类型是:

~/bootstrap-4.0.0-alpha/js/src/modal.js: line 1, col 26, Missing semicolon.

~/bootstrap-4.0.0-alpha/js/src/modal.js:第 1 行,第 26 列,缺少分号。

Despite it being valid JavaScript. Any help would be appreciated!

尽管它是有效的 JavaScript。任何帮助,将不胜感激!

Here's my Gulp File in case it helps:

这是我的 Gulp 文件,以防万一:

    // Load Node Modules/Plugins
var gulp = require('gulp');
var concat = require('gulp-concat');
var del = require('del');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint'); 

// Process Styles
gulp.task('styles', function() {
    return gulp.src('scss/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('dist'));
});

// Process Scripts
gulp.task('scripts', function() {
       return gulp.src('js/src/*.js')
           .pipe(jshint())
           .pipe(jshint.reporter('default'))
    .pipe(concat('bootstrap.js'))
           .pipe(uglify())
           .pipe(gulp.dest('dist'));
});

gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

// Watch tasks
gulp.task('watch', function() {
       gulp.watch('scss/*.scss', 'styles');
       gulp.watch('js/src/*.js', 'scripts');
});

gulp.task('build', ['styles', 'scripts', 'watch']);

gulp.task('default', ['clean'], () => {
  gulp.start('build');
});

回答by Madness

In .jshintrc, set the following to tolerate Automatic Semicolon Insertion:

在 中.jshintrc,设置以下内容以容忍自动分号插入:

"asi" : true,

As described here, which points you to this example.

如上所述这里,这点你这个例子