stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.51k stars 240 forks source link

Add support for pre-commit #2401

Closed Corbie-42 closed 1 year ago

Corbie-42 commented 1 year ago

User story. As a developer, I can make sure the API specifications I wrote are automatically checked, before I commit them.

Is your feature request related to a problem? I'm always frustrated when a pipeline that checks the API specification fails, because I did not run spectral before pushing my changes.

Describe the solution you'd like I would like to create a pre-commit hook in my project like this:

- repo: https://github.com/stoplightio/spectral
  rev: v6.9.0
  hooks:
  - id: spectral
    args: ["-f", ".my-rules.yaml"]

Additional context Vacuum (that is using spectral) has defined a .pre-commit-hooks.yaml in their project. This could be used as reference.

mnaumanali94 commented 1 year ago

@Corbie-42 Were you not able to create a pre commit hook or are you looking for an example?

TribuneX commented 2 months ago

Why was this closed? The author asked for a pre-commit support which would require a pre-commit-hooks.yaml in this repository.

We are also looking for this without the need to define it ourselves.