Skip to content

Commit 7228608

Browse files
committed
Bump ESLint to v3.x and ES2015ify
[breaking change] fix #160
1 parent 946e0e9 commit 7228608

File tree

19 files changed

+448
-472
lines changed

19 files changed

+448
-472
lines changed

.eslintrc.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
parserOptions:
2+
ecmaVersion: 7
3+
14
env:
25
node: true
36

@@ -52,3 +55,6 @@ rules:
5255
semi-spacing: 1
5356
key-spacing: [1, {beforeColon: false, afterColon: true, mode: "minimum"}]
5457
space-in-parens: [1, "never"]
58+
no-var: 2
59+
prefer-const: 2
60+

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 3.0.0
4+
5+
* Bump eslint dependency to ^3.0.0 <http://eslint.org/blog/2016/07/eslint-v3.0.0-released>
6+
* Use ES2015 syntax
7+
38
## 2.1.0
49

510
* Remove now obsolete error handling for formatter loading

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ npm install gulp-eslint
1313
## Usage
1414

1515
```javascript
16-
var gulp = require('gulp'),
17-
eslint = require('gulp-eslint');
16+
const gulp = require('gulp');
17+
const eslint = require('gulp-eslint');
1818

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

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

@@ -292,5 +292,6 @@ ESLint will also detect an `.eslintignore` file at the cwd or a parent directory
292292
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.
293293

294294
#### Gulp-Eslint Extensions:
295+
295296
* [gulp-eslint-if-fixed](https://github.com/lukeapage/gulp-eslint-if-fixed)
296297
* [gulp-eslint-threshold](https://github.com/krmbkt/gulp-eslint-threshold)

example/config.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
// npm install gulp gulp-eslint
44

5-
var gulp = require('gulp');
6-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const eslint = require('..');
77

88
/**
99
* Simple example of using ESLint and a formatter
1010
* Note: ESLint does not write to the console itself.
1111
* Use format or formatEach to print ESLint results.
1212
* @returns {stream} gulp file stream
1313
*/
14-
gulp.task('basic', function() {
14+
gulp.task('basic', () => {
1515
return gulp.src('../test/fixtures/**/*.js')
1616
// default: use local linting config
1717
.pipe(eslint())
@@ -23,7 +23,7 @@ gulp.task('basic', function() {
2323
* Inline ESLint configuration
2424
* @returns {stream} gulp file stream
2525
*/
26-
gulp.task('inline-config', function() {
26+
gulp.task('inline-config', () => {
2727
return gulp.src('../test/fixtures/**/*.js')
2828
.pipe(eslint({
2929
// gulp-eslint's config works much like .eslintrc with a dash of ESLint's CLI
@@ -65,7 +65,7 @@ gulp.task('inline-config', function() {
6565
'$': false
6666
},
6767

68-
'env': {
68+
'envs': {
6969
'node': true
7070
}
7171

@@ -77,11 +77,11 @@ gulp.task('inline-config', function() {
7777
* Load configuration file
7878
* @returns {stream} gulp file stream
7979
*/
80-
gulp.task('load-config', function() {
80+
gulp.task('load-config', () => {
8181
return gulp.src('../test/fixtures/**/*.js')
8282
.pipe(eslint({
8383
// Load a specific ESLint config
84-
config: 'config.json'
84+
configFile: 'config.json'
8585
}))
8686
.pipe(eslint.format());
8787
});
@@ -90,7 +90,7 @@ gulp.task('load-config', function() {
9090
* Shorthand way to load a configuration file
9191
* @returns {stream} gulp file stream
9292
*/
93-
gulp.task('load-config-shorthand', function() {
93+
gulp.task('load-config-shorthand', () => {
9494
return gulp.src('../test/fixtures/**/*.js')
9595
// Load a specific ESLint config
9696
.pipe(eslint('config.json'))
@@ -106,6 +106,6 @@ gulp.task('default', [
106106
'load-config',
107107
'load-config-shorthand'
108108

109-
], function() {
109+
], () => {
110110
console.log('All tasks completed successfully.');
111111
});

example/fail.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
// npm install gulp gulp-eslint
44

5-
var gulp = require('gulp');
6-
var gulpUtil = require('gulp-util');
7-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const gulpUtil = require('gulp-util');
7+
const eslint = require('../');
88

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

23-
gulp.task('fail-at-end', function() {
22+
gulp.task('fail-at-end', () => {
2423
return gulp.src('../test/fixtures/**/*.js')
2524
.pipe(eslint())
2625
// Format all results at once, at the end

example/fix.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
// npm install gulp gulp-eslint gulp-if
44

5-
var gulp = require('gulp');
6-
var gulpIf = require('gulp-if');
7-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const gulpIf = require('gulp-if');
7+
const eslint = require('..');
88

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

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

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

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

3030
return gulp.src('../test/fixtures/*.js')
3131
.pipe(eslint({

example/format.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// npm install gulp gulp-eslint
44

5-
var gulp = require('gulp');
6-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const eslint = require('..');
77

88

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

2020

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

2726
function pluralish(count, text) {
28-
return count + ' ' + text + (count === 1 ? '' : 's');
27+
return `${count} ${text}${count === 1 ? '' : 's'}`;
2928
}
3029

3130
return gulp.src('../test/fixtures/**/*.js')
3231
.pipe(eslint())
33-
.pipe(eslint.format(function(results) {
32+
.pipe(eslint.format(results => {
3433

3534
// return formatted text to display
3635
return embolden('[Custom ESLint Summary]')

example/quiet.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
// npm install gulp gulp-eslint
44

5-
var gulp = require('gulp');
6-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const eslint = require('..');
77

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

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

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

example/result.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
// npm install gulp gulp-eslint
44

5-
var gulp = require('gulp');
6-
var eslint = require('../');
5+
const gulp = require('gulp');
6+
const eslint = require('..');
77

8-
var MAX_WARNINGS = 1;
8+
const MAX_WARNINGS = 1;
99

1010

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

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

2121
if (count > MAX_WARNINGS) {
@@ -31,19 +31,18 @@ gulp.task('lint-result', function() {
3131
}));
3232
});
3333

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

3737
return gulp.src('../test/fixtures/*.js')
3838
.pipe(eslint())
3939
.pipe(eslint.formatEach())
40-
.pipe(eslint.result(function(result, done) {
41-
40+
.pipe(eslint.result((result, done) => {
4241
// As a basic example, we'll use process.nextTick as an async process.
4342
process.nextTick(function asyncStub() {
4443
count += result.warningCount;
4544

46-
var error = null;
45+
const error = null;
4746
if (count > MAX_WARNINGS) {
4847
// Define the error. Any non-null/undefined value will work
4948
error = {
@@ -60,11 +59,11 @@ gulp.task('lint-resu1lt-async', function() {
6059
}));
6160
});
6261

63-
gulp.task('lint-results', function() {
62+
gulp.task('lint-results', () => {
6463
return gulp.src('../test/fixtures/*.js')
6564
.pipe(eslint())
6665
.pipe(eslint.format())
67-
.pipe(eslint.results(function(results) {
66+
.pipe(eslint.results(results => {
6867
// results.warningCount is an array of file result
6968
// that includes warningsCount and errorCount totals.
7069
if (results.warningCount > MAX_WARNINGS) {
@@ -74,16 +73,14 @@ gulp.task('lint-results', function() {
7473
}));
7574
});
7675

77-
gulp.task('lint-results-async', function() {
76+
gulp.task('lint-results-async', () => {
7877
return gulp.src('../test/fixtures/*.js')
7978
.pipe(eslint())
8079
.pipe(eslint.format())
81-
.pipe(eslint.results(function(results, done) {
82-
80+
.pipe(eslint.results((results, done) => {
8381
// Another async example...
8482
process.nextTick(function asyncStub() {
85-
86-
var error = null;
83+
const error = null;
8784
if (results.warningCount > MAX_WARNINGS) {
8885
error = new Error('Too many warnings!');
8986
}

0 commit comments

Comments
 (0)