-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
refactor: introduce Rule #1112
refactor: introduce Rule #1112
Conversation
@@ -39,7 +39,7 @@ export const buildTestSpectralWithAsyncApiRule = async (ruleName: string): Promi | |||
expect(Object.keys(s.rules)).toEqual([ruleName]); | |||
|
|||
const rule = s.rules[ruleName]; | |||
expect(rule.recommended).not.toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bringing back memories! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's going backwards. I was pointing this out as a mistake, sorry for not being clear, We removed enabled so why does this test talk about enabled instead of recommended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enabled
is internal, nothing exposed to end user.
Basically, it's a combination of recommended + severity, but it's something end user will be unaware of.
This is a check we had to do in the lining process to verify whether a given rule should be executed or not, so I simply extracted it to a single spot for our own convenience.
tl;dr I didn't re-add the enabled
on ruleset rule, it's an internal rule instance (former IRunRule). User has no access to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philsturgeon I think @P0lip's change is sound. recommended
is a rule property in the context of the ruleset. Once loaded, it's of little use. However, enabled
is needed from the rule engine standpoint.
And that's one of thing I do like with this PR. It disambiguates a RulesetRule from a loaded one.
FWIW, I'd have taken this one step further and kept the initial severity
level from the ruleset (without turning it off when not recommended
), which would help on the test standpoint and avoid code like
...((rule as IRule).recommended === false && { severity: -1 }), |
6bbe0f4
to
71d9925
Compare
71d9925
to
c40094b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
@@ -20,17 +19,17 @@ const removeAllRulesBut = (spectral: Spectral, ruleName: string) => { | |||
|
|||
const rawRule = asyncApiRules[ruleName]; | |||
|
|||
const patchedRule: IRule = Object.assign(rule1, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we wanted to try and avoid casting, but this removes a type declaration and introduces a cast.
@@ -735,7 +735,7 @@ console.log(this.cache.get('test') || this.cache.set('test', []).get('test')); | |||
|
|||
expect(Object.keys(spectral.rules)).toHaveLength(3); | |||
|
|||
expect(Object.entries(spectral.rules).map(([name, rule]) => [name, rule.recommended])).toEqual([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AGH
Ok!
|
Checklist
Does this PR introduce a breaking change?
Additional context
There are not so amny changes taking aplce here.
The only actual notable changes are:
enabled
,matchesFormat
, etc. Plus, the data types are more strict, so less duck-typing or other checks are requiredThis one of the chunks of "json-path on rails" (#437) chore.
I'll split it into smaller pieces, as certain changes are not directly related.