Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for --quiet option #57

Closed
wants to merge 1 commit into from
Closed

Adds support for --quiet option #57

wants to merge 1 commit into from

Conversation

anddoutoi
Copy link

The command line interface of ESLint supports --quiet to only report errors and ignore warnings. The ESLint CLIEngine do not expose this option because quiet only has to do with output and CLIEngine is designed specifically to not output anything.

This is is useful when you lint something where warnings don't matter e.g. a git pre-commit hook. It can be confusing to see a lot of warnings and still see the commit run.

Let me know if there is a better place or a better way to do this =)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.96%) to 75.56% when pulling b003247 on anddoutoi:master into 5a61730 on adametry:master.

@adametry
Copy link
Owner

I can see your point and appreciate the PR; though, I believe this may be better implemented via format or formatEach since the aim is to change reporting.

Here's a quick example of what works now:

gulp.task('warnless', function() {
    return gulp.src(['**/*.js', '!node_modules/**', '!coverage/**'])
        .pipe(eslint())
        // format/formatEach can be used to transform reports as well
        .pipe(eslint.format(function (reports) {
            // count & remove warning messages from each eslint file report
            reports.forEach(function (report) {
                report.messages = report.messages.filter(function isError(message) {
                    return message.fatal || message.severity > 1;
                });
            });
            // The returned value goes to the console (by default)
            // If nothing is returned, nothing is written.
            return '(Eslint Report Silenced)';
        }))
        // Now, we'll print what remains of the eslint reports
        .pipe(eslint.format());
});

Does this work for you or what else might be done?

@anddoutoi
Copy link
Author

That would do the work and produce the result I want. I can definitely live with that solution.

One could however argue that the formats job should be to only format the data for different consumers and respect data integrity. The fact that grunt-eslint supports it maybe also is a carrot? ;)

Making it an option also makes it easier to receive argvs from outside gulp land.

You could do things like:

npm run lint-staged -- --quiet

and in gulp task do:

var argvs = minimist(process.argv.slice(2));
...
.pipe(gulpESLint({
    quiet: argvs.quiet
}))

Anyway, thanks for getting back on this.

@idolize
Copy link

idolize commented May 29, 2015

@adametry Thanks for the snippit. I have to agree with @anddoutoi though - this would be nice to have as a baked-in feature rather than a special formatter (my guess is that most people would not know to find this GitHub Issue, and just assume it is impossible if it isn't in the docs).

@adametry
Copy link
Owner

adametry commented Jun 5, 2015

What do you think about having an option severity parameter for format and formatEach? This could allow reporting warnings and errors independently/optionally. It might looks something like:

var fileOut = fs.createWriteStream('lint-errors.log');
gulp.src('**/*.js')
    .pipe(eslint())
    .pipe(eslint.format()); // print errors and warnings to stdout
    .pipe(eslint.format(2, 'compact', fileOut)); // print errors (severity = 2) to file

Note: the severity numbers are the same as the ones used when configuring eslint rules.

This would be more flexible in how the data is consumed and maintain data integrity (with no reduction).

@icirellik
Copy link

Has there been any progress on this?

@adametry
Copy link
Owner

A release candidate has been published that includes a "quiet" option. If set to true, it will remove warning messages from Eslint results. If set to a function(message) results will only include messages that return a truthy value. For example:

gulp.task('lint-quiet', function () {
    return gulp.src('src/**/*.js')
        .pipe(eslint({quiet: true}))
        .pipe(eslint.format());
});

...or only warnings:

function isWarning(message) {
    return message.severity === 1;
}
gulp.task('lint-warn', function () {
    return gulp.src('src/**/*.js')
        .pipe(eslint({quiet: isWarning}))
        .pipe(eslint.format());
});

Try the release candidate out and let me know how well it works for you.

npm install gulp-eslint@rc

@adametry
Copy link
Owner

The option is now in the latest version of gulp-eslint (1.1.0).

@adametry adametry closed this Nov 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants