Skip to content

Commit

Permalink
fix(function-rule): return success if the function rule is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbruijn committed Apr 17, 2022
1 parent 84e415f commit 82047c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/function-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('returns a value from an implementation function', (t) => {
t.deepEqual(returnValue, ruleOutcome);
});

test.failing('returns successful for an undefined implementation', (t) => {
test('returns successful for an undefined implementation', (t) => {
const returnValue = functionRule({} as Commit, 'always', undefined);
t.deepEqual(returnValue, [true]);
});
Expand Down
9 changes: 6 additions & 3 deletions src/function-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ type FunctionRule = (
const functionRule: Rule<FunctionRule> = (
parsed: Commit,
when: RuleConfigCondition = 'always',
value: FunctionRule | undefined,
functionRule: FunctionRule | undefined,
) => {
if (typeof value !== 'function') {
if (functionRule === undefined) {
return [true];
}
if (typeof functionRule !== 'function') {
throw new Error('Not a valid function!');
}

return value(parsed, when);
return functionRule(parsed, when);
};

export default functionRule;
Expand Down

0 comments on commit 82047c3

Please sign in to comment.