Skip to content

Commit

Permalink
use Buffer.from instead of new Buffer
Browse files Browse the repository at this point in the history
Buffer.from is backported to v4.5.0. nodejs/node@350e8c6...34776ec
  • Loading branch information
shinnn committed Jun 12, 2017
1 parent e6c67a2 commit c0e82ce
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,9 +2,10 @@

## 4.0.0

* Drop support for linting `Stream` contents
* Drop support for linting [`Stream`](https://nodejs.org/api/stream.html#stream_stream) [contents](https://github.com/gulpjs/vinyl#optionscontents)
* Because almost all, at popular, tools to handle JavaScript files today doesn't support `Streams`. They only support either `String` or `Buffer`.
*
* Use [`Buffer.from(<string>)`](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding) instead of the deprecated [`new Buffer(<string>)`](https://nodejs.org/dist/latest-v8.x/docs/api/buffer.html#buffer_new_buffer_string_encoding)
* Note that `Buffer.from` is only available on Node.js >= [4.5.0](https://nodejs.org/en/blog/release/v4.5.0/).

## 3.0.1

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -60,7 +60,7 @@ function gulpEslint(options) {
file.eslint = verify(file.contents.toString(), filePath);
// Update the fixed output; otherwise, fixable messages are simply ignored.
if (file.eslint.hasOwnProperty('output')) {
file.contents = new Buffer(file.eslint.output);
file.contents = Buffer.from(file.eslint.output);
file.eslint.fixed = true;
}
cb(null, file);
Expand Down
14 changes: 7 additions & 7 deletions test/fail.js
Expand Up @@ -29,7 +29,7 @@ describe('gulp-eslint failOnError', () => {

lintStream.write(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
}));

lintStream.end();
Expand All @@ -45,15 +45,15 @@ describe('gulp-eslint failOnError', () => {

lintStream.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 0;')
contents: Buffer.from('x = 0;')
}));
});

it('should handle ESLint reports without messages', done => {

const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
file.eslint = {};

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('gulp-eslint failAfterError', () => {

lintStream.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
}));
});

Expand All @@ -107,7 +107,7 @@ describe('gulp-eslint failAfterError', () => {

lintStream.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 1; a = false;')
contents: Buffer.from('x = 1; a = false;')
}));
});

Expand All @@ -120,14 +120,14 @@ describe('gulp-eslint failAfterError', () => {

lintStream.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 0;')
contents: Buffer.from('x = 0;')
}));
});

it('should handle ESLint reports without messages', done => {
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
file.eslint = {};

Expand Down
6 changes: 3 additions & 3 deletions test/format.js
Expand Up @@ -17,15 +17,15 @@ function getFiles() {
}),
new File({
path: 'test/fixtures/use-strict.js',
contents: new Buffer('(function () {\n\n\tvoid 0;\n\n}());\n\n')
contents: Buffer.from('(function () {\n\n\tvoid 0;\n\n}());\n\n')
}),
new File({
path: 'test/fixtures/undeclared.js',
contents: new Buffer('(function () {\n\t"use strict";\n\n\tx = 0;\n\n}());\n')
contents: Buffer.from('(function () {\n\t"use strict";\n\n\tx = 0;\n\n}());\n')
}),
new File({
path: 'test/fixtures/passing.js',
contents: new Buffer('(function () {\n\n\t"use strict";\n\n}());\n')
contents: Buffer.from('(function () {\n\n\t"use strict";\n\n}());\n')
})
];
}
Expand Down
20 changes: 10 additions & 10 deletions test/linting.js
Expand Up @@ -35,12 +35,12 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/stage0-class-property.js',
contents: new Buffer('class MyClass {prop = a + "b" + c;}')
contents: Buffer.from('class MyClass {prop = a + "b" + c;}')
}));
});

it('should support sharable config', done => {
eslint(path.resolve(__dirname, 'fixtures/eslintrc-sharable-config.js'))
eslint(path.resolve(__dirname, 'fixtures', 'eslintrc-sharable-config.js'))
.on('error', done)
.on('data', file => {
should.exist(file);
Expand All @@ -59,7 +59,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/no-newline.js',
contents: new Buffer('console.log(\'Hi\');')
contents: Buffer.from('console.log(\'Hi\');')
}));
});

Expand All @@ -84,7 +84,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/use-strict.js',
contents: new Buffer('var x = 1;')
contents: Buffer.from('var x = 1;')
}));
});

Expand Down Expand Up @@ -132,7 +132,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/ignored.js',
contents: new Buffer('(function () {ignore = abc;}});')
contents: Buffer.from('(function () {ignore = abc;}});')
}));
});

Expand All @@ -151,7 +151,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'node_modules/test/index.js',
contents: new Buffer('(function () {ignore = abc;}});')
contents: Buffer.from('(function () {ignore = abc;}});')
}));
});

Expand All @@ -165,7 +165,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/ignored.js',
contents: new Buffer('(function () {ignore = abc;}});')
contents: Buffer.from('(function () {ignore = abc;}});')
}));
});

Expand All @@ -185,7 +185,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('function z() { x = 0; }')
contents: Buffer.from('function z() { x = 0; }')
}));
});

Expand All @@ -204,7 +204,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('function z() { x = 0; }')
contents: Buffer.from('function z() { x = 0; }')
}));
});

Expand All @@ -227,7 +227,7 @@ describe('gulp-eslint plugin', () => {
})
.end(new File({
path: 'test/fixtures/fixable.js',
contents: new Buffer('var x = 0; ')
contents: Buffer.from('var x = 0; ')
}));
});
});
Expand Down
26 changes: 13 additions & 13 deletions test/result.js
Expand Up @@ -34,17 +34,17 @@ describe('gulp-eslint result', () => {

lintStream.write(new File({
path: 'test/fixtures/invalid-1.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
}));

lintStream.write(new File({
path: 'test/fixtures/invalid-2.js',
contents: new Buffer('x = 2;')
contents: Buffer.from('x = 2;')
}));

lintStream.write(new File({
path: 'test/fixtures/invalid-3.js',
contents: new Buffer('x = 3;')
contents: Buffer.from('x = 3;')
}));

lintStream.end();
Expand All @@ -53,7 +53,7 @@ describe('gulp-eslint result', () => {
it('should catch thrown errors', done => {
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
file.eslint = {};

Expand All @@ -79,7 +79,7 @@ describe('gulp-eslint result', () => {
it('should catch thrown null', done => {
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
file.eslint = {};

Expand Down Expand Up @@ -121,7 +121,7 @@ describe('gulp-eslint result', () => {

const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});

eslint.result(() => {
Expand All @@ -139,7 +139,7 @@ describe('gulp-eslint result', () => {
let asyncComplete = false;
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
const resultStub = {};
file.eslint = resultStub;
Expand Down Expand Up @@ -202,17 +202,17 @@ describe('gulp-eslint results', () => {

lintStream.write(new File({
path: 'test/fixtures/invalid-1.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
}));

lintStream.write(new File({
path: 'test/fixtures/invalid-2.js',
contents: new Buffer('x = 2;')
contents: Buffer.from('x = 2;')
}));

lintStream.write(new File({
path: 'test/fixtures/invalid-3.js',
contents: new Buffer('x = 3;')
contents: Buffer.from('x = 3;')
}));

lintStream.end();
Expand All @@ -221,7 +221,7 @@ describe('gulp-eslint results', () => {
it('should catch thrown errors', done => {
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
file.eslint = {};

Expand Down Expand Up @@ -263,7 +263,7 @@ describe('gulp-eslint results', () => {
let resultsCalled = false;
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});

function finished() {
Expand All @@ -288,7 +288,7 @@ describe('gulp-eslint results', () => {
let asyncComplete = false;
const file = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('#invalid!syntax}')
contents: Buffer.from('#invalid!syntax}')
});
const resultStub = {};
file.eslint = resultStub;
Expand Down
10 changes: 5 additions & 5 deletions test/util.js
Expand Up @@ -14,7 +14,7 @@ describe('utility methods', () => {
let passedFile = false;
const streamFile = new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
});
const testStream = util.transform((file, enc, cb) => {
should.exist(file);
Expand All @@ -37,11 +37,11 @@ describe('utility methods', () => {
const files = [
new File({
path: 'test/fixtures/invalid.js',
contents: new Buffer('x = 1;')
contents: Buffer.from('x = 1;')
}),
new File({
path: 'test/fixtures/undeclared.js',
contents: new Buffer('x = 0;')
contents: Buffer.from('x = 0;')
})
];
const testStream = util.transform((file, enc, cb) => {
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('utility methods', () => {
it('should create a warning that the file is ignored by ".eslintignore"', () => {
const file = new File({
path: 'test/fixtures/ignored.js',
contents: new Buffer('')
contents: Buffer.from('')
});
const result = util.createIgnoreResult(file);
should.exist(result);
Expand All @@ -89,7 +89,7 @@ describe('utility methods', () => {
it('should create a warning for paths that include "node_modules"', () => {
const file = new File({
path: 'node_modules/test/index.js',
contents: new Buffer('')
contents: Buffer.from('')
});
const result = util.createIgnoreResult(file);
should.exist(result);
Expand Down

0 comments on commit c0e82ce

Please sign in to comment.