Skip to content

Commit

Permalink
Add tests to cover "result" and "results" methods;
Browse files Browse the repository at this point in the history
Update README example to include "parser", "extends", and "ecmaFeatures" options;
Add ability to define PluginError plugin name;
Change "eslint" to "ESLint" wherever referencing the project (rather than a variable);
  • Loading branch information
adametry committed Nov 5, 2015
1 parent d2a992f commit 412098f
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 51 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var gulp = require('gulp'),

gulp.task('lint', function () {
return gulp.src(['js/**/*.js'])
// eslint() attaches the lint output to the eslint property
// 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.
Expand All @@ -39,6 +39,13 @@ Or use the plugin API to do things like:
```javascript
gulp.src('js/**/*.js')
.pipe(eslint({
// "expree" is installed with ESLint.
// Any other parser will need to be installed.
parser: 'espree',
extends: 'eslint:recommended',
ecmaFeatures: {
'modules': true
},
rulePaths: [
'custom-rules/'
],
Expand Down Expand Up @@ -163,7 +170,7 @@ gulp.src('**/*.js')
Stop a task/stream if an ESLint error has been reported for any file, but wait for all of them to be processed first.

```javascript
// Cause the stream to stop(/fail) when the stream ends if any eslint error(s) occurred.
// Cause the stream to stop(/fail) when the stream ends if any ESLint error(s) occurred.
gulp.src('**/*.js')
.pipe(eslint())
.pipe(eslint.failAfterError())
Expand All @@ -172,15 +179,15 @@ gulp.src('**/*.js')

### 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.
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](https://github.com/eslint/eslint/tree/master/lib/formatters). If `undefined`, the ESLint “stylish” formatter will be resolved. A `Function` will be called with an `Array` of file linting results to format.

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

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

// use the "eslint-path-formatter" module formatter
Expand Down
16 changes: 8 additions & 8 deletions example/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ var gulp = require('gulp');
var eslint = require('../');

/**
* Simple example of using eslint and a formatter
* Note: eslint does not write to the console itself.
* Use format or formatEach to print eslint results.
* Simple example of using ESLint and a formatter
* Note: ESLint does not write to the console itself.
* Use format or formatEach to print ESLint results.
* @returns {stream} gulp file stream
*/
gulp.task('basic', function() {
return gulp.src('../test/fixtures/**/*.js')
// default: use local linting config
.pipe(eslint())
// format eslint results and print them to the console
// format ESLint results and print them to the console
.pipe(eslint.format());
});

/**
* Inline eslint configuration
* Inline ESLint configuration
* @returns {stream} gulp file stream
*/
gulp.task('inline-config', function() {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint({
// gulp-eslint's config works much like .eslintrc with a dash of eslint's CLI
// gulp-eslint's config works much like .eslintrc with a dash of ESLint's CLI

'extends':'eslint:recommended',

Expand Down Expand Up @@ -80,7 +80,7 @@ gulp.task('inline-config', function() {
gulp.task('load-config', function() {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint({
// Load a specific eslint config
// Load a specific ESLint config
config: 'config.json'
}))
.pipe(eslint.format());
Expand All @@ -92,7 +92,7 @@ gulp.task('load-config', function() {
*/
gulp.task('load-config-shorthand', function() {
return gulp.src('../test/fixtures/**/*.js')
// Load a specific eslint config
// Load a specific ESLint config
.pipe(eslint('config.json'))
.pipe(eslint.format());
});
Expand Down
2 changes: 1 addition & 1 deletion example/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var gulpIf = require('gulp-if');
var eslint = require('../');

function isFixed(file) {
// Has eslint fixed the file contents?
// Has ESLint fixed the file contents?
return file.eslint != null && file.eslint.fixed;
}

Expand Down
34 changes: 17 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var util = require('./util');
var path = require('path');

/**
* Append eslint result to each file
* Append ESLint result to each file
*
* @param {(Object|String)} [options] - Configure rules, env, global, and other options for running eslint
* @param {(Object|String)} [options] - Configure rules, env, global, and other options for running ESLint
* @returns {stream} gulp file stream
*/
function gulpEslint(options) {
Expand Down Expand Up @@ -38,20 +38,20 @@ function gulpEslint(options) {

} else if (linter.isPathIgnored(filePath)) {
// Note:
// Vinyl files can have an independently defined cwd, but eslint works relative to `process.cwd()`.
// Vinyl files can have an independently defined cwd, but ESLint works relative to `process.cwd()`.
// (https://github.com/gulpjs/gulp/blob/master/docs/recipes/specifying-a-cwd.md)
// Also, eslint doesn't adjust file paths relative to an ancestory .eslintignore path.
// E.g., If ../.eslintignore has "foo/*.js", eslint will ignore ./foo/*.js, instead of ../foo/*.js.
// Also, ESLint doesn't adjust file paths relative to an ancestory .eslintignore path.
// E.g., If ../.eslintignore has "foo/*.js", ESLint will ignore ./foo/*.js, instead of ../foo/*.js.
// Eslint rolls this into `CLIEngine.executeOnText`. So, gulp-eslint must account for this limitation.

if (linter.options.ignore && options.warnFileIgnored) {
// Warn that gulp.src is needlessly reading files that eslint ignores
// Warn that gulp.src is needlessly reading files that ESLint ignores
file.eslint = util.createIgnoreResult(file);
}
cb(null, file);

} else if (file.isStream()) {
// eslint is synchronous, so wait for the complete contents
// ESLint is synchronous, so wait for the complete contents
// replace content stream with new readable content stream
file.contents = file.contents.pipe(new BufferStreams(function(err, buf, done) {
file.eslint = verify(String(buf), filePath);
Expand All @@ -77,9 +77,9 @@ function gulpEslint(options) {
}

/**
* Handle each eslint result as it passes through the stream.
* Handle each ESLint result as it passes through the stream.
*
* @param {Function} action - A function to handle each eslint result
* @param {Function} action - A function to handle each ESLint result
* @returns {stream} gulp file stream
*/
gulpEslint.result = function(action) {
Expand All @@ -97,9 +97,9 @@ gulpEslint.result = function(action) {
};

/**
* Handle all eslint results at the end of the stream.
* Handle all ESLint results at the end of the stream.
*
* @param {Function} action - A function to handle all eslint results
* @param {Function} action - A function to handle all ESLint results
* @returns {stream} gulp file stream
*/
gulpEslint.results = function(action) {
Expand All @@ -126,7 +126,7 @@ gulpEslint.results = function(action) {
};

/**
* Fail when an eslint error is found in eslint results.
* Fail when an ESLint error is found in ESLint results.
*
* @returns {stream} gulp file stream
*/
Expand All @@ -148,7 +148,7 @@ gulpEslint.failOnError = function() {
};

/**
* Fail when the stream ends if any eslint error(s) occurred
* Fail when the stream ends if any ESLint error(s) occurred
*
* @returns {stream} gulp file stream
*/
Expand All @@ -170,8 +170,8 @@ gulpEslint.failAfterError = function() {
/**
* Format the results of each file individually.
*
* @param {(String|Function)} [formatter=stylish] - The name or function for a eslint result formatter
* @param {(Function|Stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted eslint results.
* @param {(String|Function)} [formatter=stylish] - The name or function for a ESLint result formatter
* @param {(Function|Stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted ESLint results.
* @returns {stream} gulp file stream
*/
gulpEslint.formatEach = function(formatter, writable) {
Expand All @@ -186,8 +186,8 @@ gulpEslint.formatEach = function(formatter, writable) {
/**
* Wait until all files have been linted and format all results at once.
*
* @param {(String|Function)} [formatter=stylish] - The name or function for a eslint result formatter
* @param {(Function|stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted eslint results.
* @param {(String|Function)} [formatter=stylish] - The name or function for a ESLint result formatter
* @param {(Function|stream)} [writable=gulp-util.log] - A funtion or stream to write the formatted ESLint results.
* @returns {stream} gulp file stream
*/
gulpEslint.format = function(formatter, writable) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gulp-eslint",
"version": "1.1.0-rc-2",
"description": "A gulp plugin for processing files with eslint",
"description": "A gulp plugin for processing files with ESLint",
"repository": "adametry/gulp-eslint",
"files": [
"index.js",
Expand Down
4 changes: 2 additions & 2 deletions test/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('gulp-eslint failOnError', function() {
}));
});

it('should handle eslint reports without messages', function(done) {
it('should handle ESLint reports without messages', function(done) {

var file = new File({
path: 'test/fixtures/invalid.js',
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('gulp-eslint failAfterError', function() {
}));
});

it('should handle eslint reports without messages', function(done) {
it('should handle ESLint reports without messages', function(done) {

var file = new File({
path: 'test/fixtures/invalid.js',
Expand Down
12 changes: 6 additions & 6 deletions test/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('gulp-eslint format', function() {
var formatCount, writeCount;

/**
* Custom eslint formatted result writer for counting write attempts
* Custom ESLint formatted result writer for counting write attempts
* rather than writing to the console.
*
* @param {String} message - a message to count as written
Expand All @@ -46,7 +46,7 @@ describe('gulp-eslint format', function() {
}

/**
* Custom eslint formatted result writer that will throw an exception
* Custom ESLint formatted result writer that will throw an exception
*
* @throws Error Always thrown to test error handling in writers
* @param {String} message - a message to trigger an error
Expand All @@ -59,10 +59,10 @@ describe('gulp-eslint format', function() {

describe('format all results', function() {
/**
* Custom eslint result formatter for counting format passes and
* Custom ESLint result formatter for counting format passes and
* returning a expected formatted result message.
*
* @param {Array} results - eslint results
* @param {Array} results - ESLint results
* @param {Object} config - format config
* @returns {String} formatted results
*/
Expand All @@ -84,7 +84,7 @@ describe('gulp-eslint format', function() {
writeCount = 0;
});

it('should format all eslint results at once', function(done) {
it('should format all ESLint results at once', function(done) {
var files = getFiles();

var lintStream = eslint().on('error', done);
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('gulp-eslint format', function() {
}, 0) + ' messages';
}

it('should format individual eslint results', function(done) {
it('should format individual ESLint results', function(done) {
formatCount = 0;
writeCount = 0;

Expand Down
2 changes: 1 addition & 1 deletion test/linting.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var BufferStreams = require('bufferstreams');

require('mocha');

describe('Gulp eslint plugin', function() {
describe('gulp-eslint plugin', function() {

it('should produce expected message via buffer', function(done) {
eslint({
Expand Down

0 comments on commit 412098f

Please sign in to comment.