diff --git a/packages/core/src/ruleset/__tests__/__fixtures__/severity/off-redeclared.ts b/packages/core/src/ruleset/__tests__/__fixtures__/severity/off-redeclared.ts new file mode 100644 index 000000000..b9c256a56 --- /dev/null +++ b/packages/core/src/ruleset/__tests__/__fixtures__/severity/off-redeclared.ts @@ -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; diff --git a/packages/core/src/ruleset/__tests__/ruleset.test.ts b/packages/core/src/ruleset/__tests__/ruleset.test.ts index bd23bd79f..24d8bdba0 100644 --- a/packages/core/src/ruleset/__tests__/ruleset.test.ts +++ b/packages/core/src/ruleset/__tests__/ruleset.test.ts @@ -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([ diff --git a/packages/core/src/ruleset/mergers/rules.ts b/packages/core/src/ruleset/mergers/rules.ts index fd6747737..5140a3e9c 100644 --- a/packages/core/src/ruleset/mergers/rules.ts +++ b/packages/core/src/ruleset/mergers/rules.ts @@ -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);