Skip to content

Commit

Permalink
Extracted the sanity check of the warning filters to a separate funct…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
Oscar de Groot committed Jul 1, 2014
1 parent 4756fe8 commit 1d4c926
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib/handleWebpackResult.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = function handleWebpackResult(stats, webpackWarningFilters) {
if (stats) {
try {
assertFiltersValid(webpackWarningFilters);
stats.compilation.warnings = filterWebpackWarnings(stats.compilation.warnings, webpackWarningFilters);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -44,13 +45,14 @@ module.exports = function handleWebpackResult(stats, webpackWarningFilters) {

};

function filterWebpackWarnings(unfilteredWarnings, webpackWarningFilters) {
/**
* Checks the sanity of the webpackWarningFilters-configuration.
*/
function assertFiltersValid(webpackWarningFilters) {
if (!webpackWarningFilters) {
// No filters are configured. Use the complete, unfiltered list of warnings.
return unfilteredWarnings;
// No filters are configured. That's okay.
return;
}

// Check the sanity of the webpackWarningFilters-configuration.
if (!Array.isArray(webpackWarningFilters)) {
throw new TypeError("config.webpackWarningFilters must be an array.");
}
Expand All @@ -74,6 +76,13 @@ function filterWebpackWarnings(unfilteredWarnings, webpackWarningFilters) {
);
}
}
}

function filterWebpackWarnings(unfilteredWarnings, webpackWarningFilters) {
if (!webpackWarningFilters) {
// No filters are configured. Use the complete, unfiltered list of warnings.
return unfilteredWarnings;
}

// There's at least one filter and all filter configs are supported. Do the actual filtering.
var filteredWarnings = unfilteredWarnings.filter(function filterWarning(warning, index, unfilteredWarnings) {
Expand Down

0 comments on commit 1d4c926

Please sign in to comment.