Skip to content

Commit

Permalink
fix(rule): allow impact to be configured (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jul 28, 2020
1 parent 0aab922 commit f325c75
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,14 @@ Rule.prototype.configure = function(spec) {
if (spec.hasOwnProperty('matches')) {
this.matches = createExecutionContext(spec.matches);
}

if (spec.impact) {
assert(
constants.impact.includes(spec.impact),
`Impact ${spec.impact} is not a valid impact`
);
this.impact = spec.impact;
}
};

export default Rule;
14 changes: 14 additions & 0 deletions test/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -1967,5 +1967,19 @@ describe('Rule', function() {
'Function ID does not exist in the metadata-function-map: does-not-exist'
);
});
it('should override impact', function() {
var rule = new Rule({ impact: 'minor' });

assert.equal(rule._get('impact'), 'minor');
rule.configure({ impact: 'serious' });
assert.equal(rule._get('impact'), 'serious');
});
it('should throw if impact impact', function() {
var rule = new Rule({ impact: 'minor' });

assert.throws(function() {
rule.configure({ impact: 'hello' });
});
});
});
});

0 comments on commit f325c75

Please sign in to comment.