2017-02-22 36 views
1

Невозможно распознать и запустить ESLint с помощью Gulp. Код для gulpfile.js является:Ошибка: Конфигурация ESLint не найдена

"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 streams with Gulp 
 
var concat = require('gulp-concat'); //Concatenates files 
 
var lint = require('gulp-eslint'); //Lint JS files, including JSX 
 

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

 
//Start a local development server 
 
gulp.task('connect', function() { 
 
\t connect.server({ 
 
\t \t root: ['dist'], 
 
\t \t port: config.port, 
 
\t \t base: config.devBaseUrl, 
 
\t \t livereload: true 
 
\t }); 
 
}); 
 

 
gulp.task('open', ['connect'], function() { 
 
\t gulp.src('dist/index.html') 
 
\t \t .pipe(open({ url: config.devBaseUrl + ':' + config.port + '/'})); 
 
}); 
 

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

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

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

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

 
gulp.task('watch', function() { 
 
\t gulp.watch(config.paths.html, ['html']); 
 
\t 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 
 
    } 
 
}

и, наконец, package.json зависимостей:

"dependencies": { 
 
    "bootstrap": "^3.3.7", 
 
    "browserify": "^14.1.0", 
 
    "gulp": "^3.9.1", 
 
    "gulp-concat": "^2.6.1", 
 
    "gulp-connect": "^5.0.0", 
 
    "gulp-eslint": "^3.0.1", 
 
    "gulp-open": "^2.0.0", 
 
    "jquery": "^3.1.1", 
 
    "reactify": "^1.1.1", 
 
    "vinyl-source-stream": "^1.1.0" 
 
    }

Что я могу изменить, чтобы получить один или более из трех файлов для работы?

+0

Вы пробовали настройки корневого пути '.pipe (пух ({конфигурация:«./eslint.config.json»}))', потому что я полагаю, что оба файла находится в том же праве каталога? – JoseAPL

ответ

1

Как вы можете прочитать в https://github.com/adametry/gulp-eslint#optionsconfigfile

Key имя изменилось на configFile

+0

Я также следил за курсом Pluralsight React, но с последними пакетами узлов на эту дату, и это исправило это для меня – Tyler

3

Переименуйте eslint.config.json имя файла для .eslintrc.
Затем измените lint Задача gulp как следующая.

 

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

+0

Полностью просто сработал для меня. Я считаю, что человек, задающий этот вопрос, следует вместе с учебным видеороликом Pluralsight, таким же, как я, поскольку их файл выглядит так, как будто у меня есть на данный момент. Несмотря на это, это решение сработало для меня. – MattD