question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint doesn't exit on failOnError();

See original GitHub issue

So I’m creating gulp tasks dynamically like this

var gulp           = require('gulp');
var eslint         = require('gulp-eslint');
var apps           = require('../config').browserify;
var createPaths    = require('../helpers/create-paths');
var lintTasks      = [];
var watchLintTasks = [];

var lint = function( project ) {
    return function() {
        var srcFiles = createPaths.watchPath(project, 'js');

        return gulp.src(srcFiles)
            .pipe(eslint())
            .pipe(eslint.format())
            .pipe(eslint.failOnError());
    };
};

apps.map(function(app){
    lintTasks.push('lint:' + app);
    watchLintTasks.push('watch:lint:' + app);

    gulp.task('lint:' + app, lint(app));
    gulp.task('watch:lint:' + app, function(){
        gulp.watch(createPaths.watchPath(app, 'js'), ['lint:'+ app]);
    });
});

gulp.task('lintScripts', lintTasks);
gulp.task('watch:lintScripts', watchLintTasks);

And then in my build task I’m running gulp.task('build', ['lintScripts', ...]);

When I run gulp build it doesn’t exit on errors I tried many solutions from #12 but still not exiting when it fails any idea how to fix this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MatthewHerbstcommented, Feb 29, 2016

I’m having this same issue when running the lint task from a watch task.

In my gulpfile.js

gulp.task('lint:server', lintServer);

function lintServer() {
  return gulp.src([paths.app.server])
      .pipe(eslint())
      .pipe(eslint.format())
      .pipe(eslint.failAfterError());
}

function watchServer() {
  gulp.watch([paths.app.server], ['lint:server']);
}

The command lint reruns, but doesn’t even report, let alone exit on, errors.

1reaction
adametrycommented, Jun 5, 2015

It looks like you’re running your lint and build tasks in parallel. If you want tasks to wait for the lintScripts task to pass (and not run if it fails), make sure those tasks are dependent on lintScripts (gulp will keep.

Here’s an example of tasks running in (dependency) sequence:

// ...after the lintTasks are prepared
gulp.task('lintScripts', lintTasks, function () {
     console.log('All lint tasks succeeded');
});

gulp.task('postLintTask', ['lintScripts'], function () {
    console.log('running post-link task now...');
});

gulp.task('build', ['lintScripts','postLintTask'], function () {
    console.log('running build task now...');
});

Otherwise, your code works fine for me (with a bit of a guess at what createPaths.watchPath does); though, because all the linting happens in parallel, the process may get more than one error before exiting with a code of 1. One way to control that is to merge the the streams between eslint() and eslint.format() (can provide detail, if interested).

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-process-exit - ESLint - Pluggable JavaScript Linter
The process.exit() method in Node.js is used to immediately stop the Node.js ... This doesn't give the application any chance to respond to...
Read more >
Gulp eslint doesn't find my .eslintrc file - Stack Overflow
According to the docs you need to fail on error in the pipe. gulp.task('lint', function () { // ESLint ignores files with "node_modules"...
Read more >
Compiling CSS breaks/stops when an eslint rule is broken
Personally, I think stylelint is just kind of janky like this. My recommendation is to disable stylelint-webpack-plugin 's failOnError in development: app.
Read more >
A gulp plugin for processing files with ESLint
failOnError() Stop a task/stream if an ESLint error has been reported for any file. ```javascript // Cause the stream to stop(/fail) before copying...
Read more >
@zebrajaeger/gulp-eslint - npm
formatEach() (see Docs). .pipe(eslint.format()) // To have the process exit with an error code (1) on // lint error, return the stream and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found