Git Product home page Git Product logo

gulp-eslint's Introduction

gulp-eslint Build Status Coverage Status

A gulp plugin for ESLint.

Installation

Use npm.

npm install gulp-eslint

Usage

var gulp = require('gulp'),
    eslint = require('gulp-eslint');

gulp.task('lint', function () {
    return gulp.src(['js/**/*.js'])
        // eslint() attaches the lint output to the eslint property
        // of the file object so it can be used by other modules.
        .pipe(eslint())
        // eslint.format() outputs the lint results to the console.
        // Alternatively use eslint.formatEach() (see Docs).
        .pipe(eslint.format())
        // To have the process exit with an error code (1) on
        // lint error, return the stream and pipe to failOnError last.
        .pipe(eslint.failOnError());
});

gulp.task('default', ['lint'], function () {
    // This will only run if the lint task is successful...
});

Or use the plugin API to do things like:

gulp.src('js/**/*.js')
	.pipe(eslint({
		rulePaths: [
			'custom-rules/'
		],
		rules: {
			'my-custom-rule': 1,
			'strict': 2
		},
		globals: {
			'jQuery':false,
			'$':true
		},
		envs: [
			'browser'
		]
	}))
	.pipe(eslint.formatEach('compact', process.stderr));

API

eslint()

No explicit configuration. A .eslintrc file may be resolved relative to each linted file.

eslint(options)

options.rulePaths

Type: Array

A list of rules file paths rules to import. For more information about rules, see the eslint rules doc.

Type: String (deprecated)

Load a single rules file.

Alias: rulesdir (deprecated)

options.configFile

Type: String

Path to the eslint rules configuration file. For more information, see the eslint CLI configFile option and configFile file info. Note: This file must have a “.json” file extension.

options.reset

Type: Boolean

When true, eslint will not include its default set of rules when configured.

options.useEslintrc

Type: Boolean

When false, eslint will not load .eslintrc.

Alias: eslintrc (deprecated)

options.rules

Type: Object

Set configuration of rules.

{
	"rules":{
		"camelcase": 1,
		"no-comma-dangle": 2,
		"quotes": 0
	}
}

options.globals

Type: Object

Specify globals.

{
	"globals":{
		"jQuery": false,
		"$": true
	}
}

options.envs

Type: Array

Specify a list of environments to be applied.

Type: Object

Specify environments. Each key must match an existing env definition, and the key determines whether the env’s rules are applied (true) or not (false).

Alias: env (deprecated)

eslint(configFilePath)

Type: String

Shorthand for defining options.configFile.

eslint.failOnError()

Stop a task/stream if an eslint error has been reported for any file.

// Cause the stream to stop(/fail) before copying an invalid JS file to the output directory
gulp.src('**/*.js')
	.pipe(eslint())
	.pipe(eslint.failOnError())
	.pipe(gulp.dest('../output'));

eslint.failAfterError()

Stop a task/stream if an eslint error has been reported for any file, but wait for all of them to be processed first.

// Cause the stream to stop(/fail) when the stream ends if any eslint error(s) occurred.
gulp.src('**/*.js')
	.pipe(eslint())
	.pipe(eslint.failAfterError())
	.pipe(gulp.dest('../output'));

eslint.format(formatter, output)

Format all linted files once. This should be used in the stream after piping through eslint; otherwise, this will find no eslint results to format.

The formatter argument may be a String, Function, or undefined. As a String, a formatter module by that name or path will be resolved as a module, relative to process.cwd(), or as one of the eslint-provided formatters. If undefined, the eslint “stylish” formatter will be resolved. A Function will be called with an Array of file linting results to format.

// use the default "stylish" eslint formatter
eslint.format()

// use the "checkstyle" eslint formatter
eslint.format('checkstyle')

// use the "eslint-path-formatter" module formatter
// (@see https://github.com/Bartvds/eslint-path-formatter)
eslint.format('eslint-path-formatter')

The output argument may be a WritableStream, Function, or undefined. As a WritableStream, the formatter results will be written to the stream. If undefined, the formatter results will be written to gulp’s log. A Function will be called with the formatter results as the only parameter.

// write to gulp's log (default)
eslint.format();

// write messages to stdout
eslint.format('junit', process.stdout)

eslint.formatEach(formatter, output)

Format each linted file individually. This should be used in the stream after piping through eslint; otherwise, this will find no eslint results to format.

The arguments for formatEach are the same as the arguments for format.

##Configuration

Eslint may be theured explicity by using any of the following plugin options: config, rules, globals, or env. When not configured in this way, eslint will attempt to resolve a file by the name of .eslintrc within the same directory as the file to be linted. If not found there, parent directories will be searched until .eslintrc is found or the directory root is reached. Any configuration will expand upon the default eslint configuration.

##Ignore Files

Eslint will ignore files that do not have a .js file extension at the point of linting (some plugins may change file extensions mid-stream). This avoids unintentional linting of non-JavaScript files.

Eslint will also detect an .eslintignore file when a directory passes through the pipeline. All subsequent files that pass through may be skipped if they match any pattern found in this file. The file may contain multiple globs as strings within a JSON array:

['**/*.min.js','output/**/*']

gulp-eslint's People

Contributors

adametry avatar shinnn avatar kingdutch avatar alyssaq avatar aruberto avatar arnaudrinquin avatar jakobo avatar jrf0110 avatar jlandure avatar bobthecow avatar ncuillery avatar mightyiam avatar tcoopman avatar boo1ean avatar gabeno avatar wltsmrz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.