diff --git a/.eslintrc b/.eslintrc index 926baae..7733133 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,10 @@ { + "parserOptions": { + "ecmaVersion": 6 + }, "env": { - "node": true + "node": true, + "es6": true }, "rules": { "comma-dangle": [2, "always-multiline"], diff --git a/lib/reporter.js b/lib/reporter.js index 8274994..cdfa793 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -1,35 +1,33 @@ -var chalk = require('chalk'); -var _ = require('lodash'); var defaultFormatter = require('./formatter'); +var chalk = require('chalk'); var util = require('./util'); +var _ = require('lodash'); -module.exports = function(opts) { - var options = opts || {}; - - var formatter = options.formatter || defaultFormatter({ - noIcon: options.noIcon, - noPlugin: options.noPlugin, +module.exports = function(opts = {}) { + var formatter = opts.formatter || defaultFormatter({ + noIcon: opts.noIcon, + noPlugin: opts.noPlugin, }); var pluginFilter; - if (!options.plugins) { + if (!opts.plugins) { // Every plugin pluginFilter = function() { return true; }; - } else if (options.plugins.every(function(plugin) { return plugin[0] === '!'; })) { + } else if (opts.plugins.every(function(plugin) { return plugin[0] === '!'; })) { // Blacklist pluginFilter = function(message) { - return options.plugins.indexOf('!' + message.plugin) === -1; + return opts.plugins.indexOf('!' + message.plugin) === -1; }; } else { // Whitelist pluginFilter = function(message) { - return options.plugins.indexOf(message.plugin) !== -1; + return opts.plugins.indexOf(message.plugin) !== -1; }; } - var messageFilter = options.filter || function(message) { return (message.type === 'warning'); }; + var messageFilter = opts.filter || (message => message.type === 'warning'); - return function(css, result) { + return (css, result) => { var messagesToLog = result.messages .filter(pluginFilter) .filter(messageFilter); @@ -49,11 +47,11 @@ module.exports = function(opts) { }); }); - if (options.clearReportedMessages) { + if (opts.clearReportedMessages) { result.messages = _.difference(result.messages, messagesToLog); } - if (options.clearAllMessages) { + if (opts.clearAllMessages) { var messagesToClear = result.messages.filter(pluginFilter); result.messages = _.difference(result.messages, messagesToClear); } @@ -63,14 +61,14 @@ module.exports = function(opts) { console.log(report); - if (options.throwError && shouldThrowError()) { + if (opts.throwError && shouldThrowError()) { throw new Error(chalk.red.bold('\n** postcss-reporter: warnings or errors were found **')); } function shouldThrowError() { return ( messagesToLog.length - && messagesToLog.some(function(message) { + && messagesToLog.some(message => { return message.type === 'warning' || message.type === 'error'; }) );