Skip to content

Commit

Permalink
fix(core): redeclared rules should always be re-enabled (#2138)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Apr 27, 2022
1 parent 99c3c8f commit 6def6be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
@@ -0,0 +1,15 @@
import { RulesetDefinition } from '@stoplight/spectral-core';
import shared from './shared';
import { truthy } from '@stoplight/spectral-functions/src';

export default {
extends: [[shared, 'off']],
rules: {
'overridable-rule': {
given: '$.foo',
then: {
function: truthy,
},
},
},
} as RulesetDefinition;
12 changes: 12 additions & 0 deletions packages/core/src/ruleset/__tests__/ruleset.test.ts
Expand Up @@ -68,6 +68,18 @@ describe('Ruleset', () => {
expect(getEnabledRules(rules)).toEqual(['overridable-rule']);
});

it('given ruleset with extends set to off, should disable all rules but explicitly redeclared', async () => {
const { rules } = await loadRuleset(import('./__fixtures__/severity/off-redeclared'));
expect(Object.keys(rules)).toEqual([
'description-matches-stoplight',
'title-matches-stoplight',
'contact-name-matches-stoplight',
'overridable-rule',
]);

expect(getEnabledRules(rules)).toEqual(['overridable-rule']);
});

it('given nested extends with severity set to off', async () => {
const { rules } = await loadRuleset(import('./__fixtures__/severity/off-proxy'));
expect(Object.keys(rules)).toEqual([
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/ruleset/mergers/rules.ts
Expand Up @@ -39,7 +39,10 @@ export function mergeRule(
break;
case 'object':
if (existingRule !== void 0) {
Object.assign(existingRule, rule, { owner: existingRule.owner });
Object.assign(existingRule, rule, {
enabled: true,
owner: existingRule.owner,
});
} else {
assertValidRule(rule);
return new Rule(name, rule, ruleset);
Expand Down

0 comments on commit 6def6be

Please sign in to comment.