Skip to content

Commit

Permalink
Move function metadata logic to setMetadata function
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje authored and dpobel committed Jun 14, 2020
1 parent 0d68049 commit 8e957e0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ var Matcher = require('minimatch').Minimatch;
* @param metadata {Object}
* @private
*/
function setMetadata(file, rule) {
function setMetadata(file, global, rule) {
if (typeof rule.metadata === 'function') {
rule = Object.assign({}, rule, { metadata: rule.metadata(file, global) });
}
Object.keys(rule.metadata).forEach(function (key) {
if (rule.preserve && key in file) {
return;
Expand Down Expand Up @@ -45,10 +48,7 @@ module.exports = function (rules) {

matchers.forEach(function (rule) {
if ( rule.matcher.match(file) ) {
if (typeof rule.metadata === 'function') {
rule = Object.assign({}, rule, { metadata: rule.metadata(fileObject, globalMetadata) });
}
setMetadata(fileObject, rule);
setMetadata(fileObject, globalMetadata, rule);
}
});
});
Expand Down

0 comments on commit 8e957e0

Please sign in to comment.