Skip to content

Commit

Permalink
Bump ESLint to v3.x and ES2015ify
Browse files Browse the repository at this point in the history
[breaking change]

fix #160
  • Loading branch information
shinnn committed Jul 2, 2016
1 parent 946e0e9 commit 7228608
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 472 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parserOptions:
ecmaVersion: 7

env:
node: true

Expand Down Expand Up @@ -52,3 +55,6 @@ rules:
semi-spacing: 1
key-spacing: [1, {beforeColon: false, afterColon: true, mode: "minimum"}]
space-in-parens: [1, "never"]
no-var: 2
prefer-const: 2

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.0

* Bump eslint dependency to ^3.0.0 <http://eslint.org/blog/2016/07/eslint-v3.0.0-released>
* Use ES2015 syntax

## 2.1.0

* Remove now obsolete error handling for formatter loading
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ npm install gulp-eslint
## Usage

```javascript
var gulp = require('gulp'),
eslint = require('gulp-eslint');
const gulp = require('gulp');
const eslint = require('gulp-eslint');

gulp.task('lint', function () {
gulp.task('lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
Expand Down Expand Up @@ -183,12 +183,12 @@ Call a function for each ESLint file result. No returned value is expected. If a
```javascript
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.result(function (result) {
.pipe(eslint.result(result => {
// Called for each ESLint result.
console.log('ESLint result: ' + result.filePath);
console.log('# Messages: ' + result.messages.length);
console.log('# Warnings: ' + result.warningCount);
console.log('# Errors: ' + result.errorCount);
console.log(`ESLint result: ${result.filePath}`);
console.log(`# Messages: ${result.messages.length}`);
console.log(`# Warnings: ${result.warningCount}`);
console.log(`# Errors: ${result.errorCount}`);
}));
```

Expand All @@ -208,11 +208,11 @@ The results list has a "warningCount" property that is the sum of warnings in al
```javascript
gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.results(function (results) {
.pipe(eslint.results(results => {
// Called once for all ESLint results.
console.log('Total Results: ' + results.length);
console.log('Total Warnings: ' + results.warningCount);
console.log('Total Errors: ' + results.errorCount);
console.log(`Total Results: ${results.length}`);
console.log(`Total Warnings: ${results.warningCount}`);
console.log(`Total Errors: ${results.errorCount}`);
}));
```

Expand Down Expand Up @@ -292,5 +292,6 @@ ESLint will also detect an `.eslintignore` file at the cwd or a parent directory
ESLint results are attached as an "eslint" property to the vinyl files that pass through a Gulp.js stream pipeline. This is available to streams that follow the initial `eslint` stream. The [eslint.result](#result) and [eslint.results](#results) methods are made available to support extensions and custom handling of ESLint results.

#### Gulp-Eslint Extensions:

* [gulp-eslint-if-fixed](https://github.com/lukeapage/gulp-eslint-if-fixed)
* [gulp-eslint-threshold](https://github.com/krmbkt/gulp-eslint-threshold)
18 changes: 9 additions & 9 deletions example/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

// npm install gulp gulp-eslint

var gulp = require('gulp');
var eslint = require('../');
const gulp = require('gulp');
const 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.
* @returns {stream} gulp file stream
*/
gulp.task('basic', function() {
gulp.task('basic', () => {
return gulp.src('../test/fixtures/**/*.js')
// default: use local linting config
.pipe(eslint())
Expand All @@ -23,7 +23,7 @@ gulp.task('basic', function() {
* Inline ESLint configuration
* @returns {stream} gulp file stream
*/
gulp.task('inline-config', function() {
gulp.task('inline-config', () => {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint({
// gulp-eslint's config works much like .eslintrc with a dash of ESLint's CLI
Expand Down Expand Up @@ -65,7 +65,7 @@ gulp.task('inline-config', function() {
'$': false
},

'env': {
'envs': {
'node': true
}

Expand All @@ -77,11 +77,11 @@ gulp.task('inline-config', function() {
* Load configuration file
* @returns {stream} gulp file stream
*/
gulp.task('load-config', function() {
gulp.task('load-config', () => {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint({
// Load a specific ESLint config
config: 'config.json'
configFile: 'config.json'
}))
.pipe(eslint.format());
});
Expand All @@ -90,7 +90,7 @@ gulp.task('load-config', function() {
* Shorthand way to load a configuration file
* @returns {stream} gulp file stream
*/
gulp.task('load-config-shorthand', function() {
gulp.task('load-config-shorthand', () => {
return gulp.src('../test/fixtures/**/*.js')
// Load a specific ESLint config
.pipe(eslint('config.json'))
Expand All @@ -106,6 +106,6 @@ gulp.task('default', [
'load-config',
'load-config-shorthand'

], function() {
], () => {
console.log('All tasks completed successfully.');
});
13 changes: 6 additions & 7 deletions example/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

// npm install gulp gulp-eslint

var gulp = require('gulp');
var gulpUtil = require('gulp-util');
var eslint = require('../');
const gulp = require('gulp');
const gulpUtil = require('gulp-util');
const eslint = require('../');


gulp.task('fail-immediately', function() {
gulp.task('fail-immediately', () => {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint())
// format one at time since this stream may fail before it can format them all at the end
.pipe(eslint.formatEach())
// failOnError will emit an error (fail) immediately upon the first file that has an error
.pipe(eslint.failOnError())
// need to do something before the process exits? Try this:
.on('error', function(error) {
.on('error', error => {
gulpUtil.log('Stream Exiting With Error: ' + error.message);
});
});

gulp.task('fail-at-end', function() {
gulp.task('fail-at-end', () => {
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint())
// Format all results at once, at the end
Expand Down
12 changes: 6 additions & 6 deletions example/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

// npm install gulp gulp-eslint gulp-if

var gulp = require('gulp');
var gulpIf = require('gulp-if');
var eslint = require('../');
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const eslint = require('..');

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

gulp.task('lint-n-fix', function() {
gulp.task('lint-n-fix', () => {

return gulp.src('../test/fixtures/*.js')
.pipe(eslint({
Expand All @@ -22,10 +22,10 @@ gulp.task('lint-n-fix', function() {
.pipe(gulpIf(isFixed, gulp.dest('../test/fixtures')));
});

gulp.task('flag-n-fix', function() {
gulp.task('flag-n-fix', () => {
// This is a *very* basic CLI flag check.
// For a more robust method, check out [yargs](https://www.npmjs.com/package/yargs)
var hasFixFlag = (process.argv.slice(2).indexOf('--fix') >= 0);
const hasFixFlag = (process.argv.slice(2).indexOf('--fix') >= 0);

return gulp.src('../test/fixtures/*.js')
.pipe(eslint({
Expand Down
15 changes: 7 additions & 8 deletions example/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

// npm install gulp gulp-eslint

var gulp = require('gulp');
var eslint = require('../');
const gulp = require('gulp');
const eslint = require('..');


gulp.task('eslint-formatter', function() {
gulp.task('eslint-formatter', () => {
// lint each file, and format all files at once (mul)
return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint())
Expand All @@ -18,19 +18,18 @@ gulp.task('eslint-formatter', function() {
});


gulp.task('custom-formatter', function() {

gulp.task('custom-formatter', () => {
function embolden(text) {
return '\u001b[1m' + text + '\u001b[22m ';
return `\u001b[1m${text}\u001b[22m `;
}

function pluralish(count, text) {
return count + ' ' + text + (count === 1 ? '' : 's');
return `${count} ${text}${count === 1 ? '' : 's'}`;
}

return gulp.src('../test/fixtures/**/*.js')
.pipe(eslint())
.pipe(eslint.format(function(results) {
.pipe(eslint.format(results => {

// return formatted text to display
return embolden('[Custom ESLint Summary]')
Expand Down
9 changes: 4 additions & 5 deletions example/quiet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// npm install gulp gulp-eslint

var gulp = require('gulp');
var eslint = require('../');
const gulp = require('gulp');
const eslint = require('..');

gulp.task('quiet-lint', function() {
gulp.task('quiet-lint', () => {
return gulp.src('../test/fixtures/*.js')
.pipe(eslint({
// only report errors
Expand All @@ -20,7 +20,7 @@ function isWarning(message) {
return message.severity === 1;
}

gulp.task('lint-warnings', function() {
gulp.task('lint-warnings', () => {
return gulp.src('../test/fixtures/*.js')
.pipe(eslint({
quiet: isWarning
Expand All @@ -29,4 +29,3 @@ gulp.task('lint-warnings', function() {
});

gulp.task('default', ['quiet-lint','lint-warnings']);

33 changes: 15 additions & 18 deletions example/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

// npm install gulp gulp-eslint

var gulp = require('gulp');
var eslint = require('../');
const gulp = require('gulp');
const eslint = require('..');

var MAX_WARNINGS = 1;
const MAX_WARNINGS = 1;


gulp.task('lint-result', function() {
var count = 0;
gulp.task('lint-result', () => {
const count = 0;

// Be sure to return the stream; otherwise, you may not get a proper exit code.
return gulp.src('../test/fixtures/*.js')
.pipe(eslint())
.pipe(eslint.formatEach())
.pipe(eslint.result(function(result) {
.pipe(eslint.result(result => {
count += result.warningCount;

if (count > MAX_WARNINGS) {
Expand All @@ -31,19 +31,18 @@ gulp.task('lint-result', function() {
}));
});

gulp.task('lint-resu1lt-async', function() {
var count = 0;
gulp.task('lint-resu1lt-async', () => {
const count = 0;

return gulp.src('../test/fixtures/*.js')
.pipe(eslint())
.pipe(eslint.formatEach())
.pipe(eslint.result(function(result, done) {

.pipe(eslint.result((result, done) => {
// As a basic example, we'll use process.nextTick as an async process.
process.nextTick(function asyncStub() {
count += result.warningCount;

var error = null;
const error = null;
if (count > MAX_WARNINGS) {
// Define the error. Any non-null/undefined value will work
error = {
Expand All @@ -60,11 +59,11 @@ gulp.task('lint-resu1lt-async', function() {
}));
});

gulp.task('lint-results', function() {
gulp.task('lint-results', () => {
return gulp.src('../test/fixtures/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.results(function(results) {
.pipe(eslint.results(results => {
// results.warningCount is an array of file result
// that includes warningsCount and errorCount totals.
if (results.warningCount > MAX_WARNINGS) {
Expand All @@ -74,16 +73,14 @@ gulp.task('lint-results', function() {
}));
});

gulp.task('lint-results-async', function() {
gulp.task('lint-results-async', () => {
return gulp.src('../test/fixtures/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.results(function(results, done) {

.pipe(eslint.results((results, done) => {
// Another async example...
process.nextTick(function asyncStub() {

var error = null;
const error = null;
if (results.warningCount > MAX_WARNINGS) {
error = new Error('Too many warnings!');
}
Expand Down
Loading

0 comments on commit 7228608

Please sign in to comment.