Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): redeclared rules should always be re-enabled #2138

Merged
merged 1 commit into from Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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