Skip to content

dylang/grunt-eslint

 
 

Repository files navigation

grunt-eslint Build Status

Validate files with ESLint.

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:

  • ESLint uses Esprima for JavaScript parsing.
  • ESLint uses an AST to evaluate patterns in code.
  • ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.

screenshot

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:

npm install --save-dev grunt-eslint

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-eslint');

Documentation

See the grunt docs on how to configure tasks and more advanced usage.

Example

grunt.initConfig({
	eslint: {					// task
		target: ['file.js']		// array of files
	}
});

grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);

Example with custom config and rules

grunt.initConfig({
	eslint: {								// task
		options: {
			config: 'conf/eslint.json',		// custom config
			rulesdir: 'conf/rules'			// custom rules
		},
		target: ['file.js']					// array of files
	}
});

grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);

Example with custom formatter

grunt.initConfig({
	eslint: {								// task
		options: {
			format: require('eslint-tap')
		},
		target: ['file.js']					// array of files
	}
});

grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('default', ['eslint']);

Options

config

Type: String
Default: built-in eslint.json

Path to your ESLint config file (eslint.json).

rulesdir

Type: String
Default: built-in rules directory

Path to a directory with custom rules. Your custom rules will be used in addition to the built-in ones.

Recommended read: Working with Rules

format

Type: String
Default: require('eslint-stylish')

Name of a built-in formatter or path to a custom one.

Some formatters you might find useful: eslint-stylish (see screenshot), eslint-json, eslint-tap.

License

MIT © Sindre Sorhus

Packages

No packages published

Languages

  • JavaScript 100.0%