diff --git a/.editorconfig b/.editorconfig index 86c8f59..98a761d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[{package.json,*.yml}] indent_style = space indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index 176a458..391f0a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 804f8af..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/.travis.yml b/.travis.yml index dedfc07..b18bae5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ sudo: false language: node_js node_js: - - 'iojs' - - '0.12' - - '0.10' + - '6' + - '4' diff --git a/gulpfile.js b/gulpfile.js index d575d89..634cbce 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,8 @@ 'use strict'; -var gulp = require('gulp'); -var debug = require('./'); +const gulp = require('gulp'); +const debug = require('./'); -gulp.task('default', function () { - return gulp.src('*').pipe(debug()); -}); +gulp.task('default', () => + gulp.src('*') + .pipe(debug()) +); diff --git a/index.js b/index.js index ae0b6cf..e2675cd 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,16 @@ 'use strict'; -var path = require('path'); -var gutil = require('gulp-util'); -var through = require('through2'); -var tildify = require('tildify'); -var stringifyObject = require('stringify-object'); -var chalk = require('chalk'); -var objectAssign = require('object-assign'); -var plur = require('plur'); -var prop = chalk.blue; - -module.exports = function (opts) { - opts = objectAssign({ +const path = require('path'); +const gutil = require('gulp-util'); +const through = require('through2'); +const tildify = require('tildify'); +const stringifyObject = require('stringify-object'); +const chalk = require('chalk'); +const plur = require('plur'); + +const prop = chalk.blue; + +module.exports = opts => { + opts = Object.assign({ title: 'gulp-debug:', minimal: true }, opts); @@ -20,10 +20,10 @@ module.exports = function (opts) { opts.minimal = false; } - var count = 0; + let count = 0; - return through.obj(function (file, enc, cb) { - var full = + return through.obj((file, enc, cb) => { + const full = '\n' + (file.cwd ? 'cwd: ' + prop(tildify(file.cwd)) : '') + (file.base ? '\nbase: ' + prop(tildify(file.base)) : '') + @@ -31,14 +31,14 @@ module.exports = function (opts) { (file.stat && opts.verbose ? '\nstat: ' + prop(stringifyObject(file.stat, {indent: ' '}).replace(/[{}]/g, '').trim()) : '') + '\n'; - var output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full; + const output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full; count++; gutil.log(opts.title + ' ' + output); cb(null, file); - }, function (cb) { + }, cb => { gutil.log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count))); cb(); }); diff --git a/package.json b/package.json index ecf109e..f1d4cc4 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "http://sindresorhus.com" + "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { - "test": "mocha" + "test": "xo && mocha" }, "files": [ "index.js" @@ -33,7 +33,6 @@ "dependencies": { "chalk": "^1.0.0", "gulp-util": "^3.0.0", - "object-assign": "^4.0.1", "plur": "^2.0.0", "stringify-object": "^3.0.0", "through2": "^2.0.0", @@ -44,6 +43,10 @@ "mocha": "*", "proxyquire": "^1.0.1", "sinon": "^1.9.1", - "strip-ansi": "^3.0.0" + "strip-ansi": "^3.0.0", + "xo": "*" + }, + "xo": { + "esnext": true } } diff --git a/test.js b/test.js index e86480a..67d6cb1 100644 --- a/test.js +++ b/test.js @@ -1,67 +1,69 @@ +/* eslint-env mocha */ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); -var sinon = require('sinon'); -var gutil = require('gulp-util'); -var proxyquire = require('proxyquire'); -var stripAnsi = require('strip-ansi'); - -var gutilStub = { - log: function () { +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); +const sinon = require('sinon'); +const gutil = require('gulp-util'); +const proxyquire = require('proxyquire'); +const stripAnsi = require('strip-ansi'); + +const gutilStub = { + log() { // uncomment the next line to see the log messages written by gulp-debug // during test (by default they are swallowed by the sinon stub replacing the log method) // gutil.log.apply(gutil.log, arguments); } }; -var debug = proxyquire('./', { +const debug = proxyquire('./', { 'gulp-util': gutilStub }); -var file; +let file; -beforeEach(function () { +beforeEach(() => { sinon.spy(gutilStub, 'log'); file = new gutil.File({ cwd: __dirname, base: __dirname, - path: __dirname + '/foo.js', + path: path.join(__dirname, 'foo.js'), stat: fs.statSync('test.js'), contents: new Buffer('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') }); }); -afterEach(function () { +afterEach(() => { gutilStub.log.restore(); }); -it('should output debug info', function (cb) { - var stream = debug({title: 'unicorn:'}); +it('should output debug info', cb => { + const stream = debug({title: 'unicorn:'}); - stream.write(file, 'utf8', function () { + stream.write(file, 'utf8', () => { assert(gutilStub.log.calledOnce); - assert.strictEqual(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js'); + assert.strictEqual(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js'); cb(); }); }); -it('should output singular item count', function (cb) { - var stream = debug({title: 'unicorn:'}); +it('should output singular item count', cb => { + const stream = debug({title: 'unicorn:'}); - stream.on('finish', function () { + stream.on('finish', () => { assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item'); cb(); }); - stream.write(file, function () { + stream.write(file, () => { stream.end(); }); }); -it('should output zero item count', function (cb) { - var stream = debug({title: 'unicorn:'}); +it('should output zero item count', cb => { + const stream = debug({title: 'unicorn:'}); - stream.on('finish', function () { + stream.on('finish', () => { assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items'); cb(); }); @@ -69,16 +71,16 @@ it('should output zero item count', function (cb) { stream.end(); }); -it('should output plural item count', function (cb) { - var stream = debug({title: 'unicorn:'}); +it('should output plural item count', cb => { + const stream = debug({title: 'unicorn:'}); - stream.on('finish', function () { + stream.on('finish', () => { assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items'); cb(); }); - stream.write(file, function () { - stream.write(file, function () { + stream.write(file, () => { + stream.write(file, () => { stream.end(); }); });