Skip to content

Commit

Permalink
Add callback option
Browse files Browse the repository at this point in the history
This allows another plugin, such as postcss-messages, to use
postcss-log-warnings as a library and display the warnings in a different way.

See davidtheclark#7.
  • Loading branch information
lydell committed May 30, 2015
1 parent 52a4e23 commit 270854f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ gulp.task('css', function() {
- **throwError** (boolean, default = `false`)

If `true`, after the plugin logs your warnings it will throw an error if it found any warnings.

- **callback** (function, default = `warnings => console.log(warnings)`)

Receives a formatted string containing all warnings, as well as a PostCSS
`Result` instance. This allows another plugin to use postcss-log-warnings as a
library and display the warnings in a different way.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ module.exports = postcss.plugin('postcss-log-warnings', function(options) {

if (!warningLog) return;

console.log(warningLog);
var callback = options.callback || defaultCallback;
callback(warningLog, result);

if (options.throwError) {
throw new Error(chalk.red.bold('\n** postcss-log-warnings: warnings were found **'));
}
};
});

function defaultCallback(warningLog) {
console.log(warningLog);
}

0 comments on commit 270854f

Please sign in to comment.