Closed tillig closed 1 year ago
Doesn't https://docs.stoplight.io/docs/spectral/293426e270fac-overrides help to achieve what you are looking for? We use overrides to switch some rule severity to "off" for particular spec files/paths.
This is an interesting idea. Let me try it tomorrow and I'll post back here with an update. Thanks!
This works perfectly. In particular, the example that shows how to override a particular path and turn the rule off is what I needed.
overrides:
- files:
- "**/*.json#/paths/~1path~1to~1operation"
rules:
my-rule-that-does-not-apply: "off"
@tillig , just keep in mind that JSON pointer reference syntax is changed in latest version of spectral. You will need to escape some characters (for example curly brackets) in paths when defining your overrides. It was not required before. See #2515 for details.
User story.
As a developer, I can suppress a specific rule violation, so that I can ignore false positives or exceptions to the rules.
Is your feature request related to a problem?
There are times when you have a linting rule that you definitely want applied everywhere, except there's a schema with one operation that just can't conform. Maybe it can't be changed, maybe you can't quite get the regex right, but whatever the case is, that one violation really isn't a violation. It needs to be suppressed or otherwise ignored.
However, you don't want to turn the whole rule off, because you want to keep linting everything else with that rule. You just need the line-item suppression.
Describe the solution you'd like
A way to configure a set of suppressions for a given schema. This may take the form of...
.spectral.yml
file with suppressions..spectral.exclusions.yml
or similar file, so you can decouple the ruleset from the suppressions.{ "$suppress": "rule-name-here" }
inside the JSON schema....or some other mechanism to indicate "don't warn/err on this specific violation."
Additional context
IRuleResult
has apath
(JsonPath) property, so the source of the error is known. Perhaps that's the way to specify the exclusion - a JsonPath value along with a list of rules to suppress at that site.Alternatively, I've seen some systems generate a "fingerprint" based on the file, source location, etc., some sort of hash - that might be a second step, though I think it'd be a more far-reaching change than just using the JsonPath value.
I did see that #1145 was opened a couple years ago and then closed, but it doesn't look like anything was addressed. This is sort of a duplicate of that one.