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.48k stars 233 forks source link

[Feature] Pass pattern some regex modifiers as a function option #2578

Closed philsturgeon closed 8 months ago

philsturgeon commented 8 months ago

User story. As a ruleset developer, I can pass regex modifiers to the pattern function, so that I can make more advanced rulesets with everything regex has to offer instead of just the default mode.

Is your feature request related to a problem?

Working on https://github.com/stoplightio/spectral-owasp-ruleset/pull/51 I had to write some fairly hectic regex due to not being able to set the /i modifier for case insenstivity.

      then: {
        field: "description",
        function: pattern,
        functionOptions: {
          match: "((l|L)ocal|(a|A)lpha|(b|B)eta|(t|T)est|(t|T)esting|(s|S)tag|(s|S)taging|(p|P)rod|(p|P)roduction|(n|N)ext|(p|P)reprod)",
        },
      },

Describe the solution you'd like

function: pattern,
functionOptions: {
  match: "(local|alpha|beta|test|testing|stag|staging|prod|production|next|preprod)",
  modifiers: 'i'
},

Or you could make it nicer for people and make human named switches like case-insensitive: true or whatever.

P0lip commented 8 months ago

@philsturgeon Hey! Have you tried match: "/(local|alpha|beta|test|testing|stag|staging|prod|production|next|preprod)/i"?

philsturgeon commented 8 months ago

@P0lip haha well don't I feel like a numpty.

Added this to docs so it doesn't come up again.

Also hello! Hope you're doing well mate. 🙌🏻

P0lip commented 8 months ago

Thanks for the PR, I appreciate it. I am doing fine, thanks! I hope you're doing great too!

stoplight-bot commented 4 months ago

:tada: This issue has been resolved in version 1.19.0 :tada:

The release is available on @stoplight/spectral-rulesets-1.19.0

Your semantic-release bot :package::rocket: