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

Ability to suppress false positives #2457

Closed
tillig opened this issue Apr 18, 2023 · 4 comments
Closed

Ability to suppress false positives #2457

tillig opened this issue Apr 18, 2023 · 4 comments

Comments

@tillig
Copy link
Contributor

tillig commented Apr 18, 2023

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...

  • Another section in the .spectral.yml file with suppressions.
  • A separate .spectral.exclusions.yml or similar file, so you can decouple the ruleset from the suppressions.
  • Meta-markup like { "$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 a path (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.

@anikitin
Copy link

anikitin commented Aug 7, 2023

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.

@tillig
Copy link
Contributor Author

tillig commented Aug 7, 2023

This is an interesting idea. Let me try it tomorrow and I'll post back here with an update. Thanks!

@tillig
Copy link
Contributor Author

tillig commented Aug 8, 2023

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 tillig closed this as completed Aug 8, 2023
@anikitin
Copy link

anikitin commented Aug 8, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants