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

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

Closed
philsturgeon opened this issue Jan 21, 2024 · 4 comments · Fixed by #2579
Closed

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

philsturgeon opened this issue Jan 21, 2024 · 4 comments · Fixed by #2579
Assignees
Labels
enhancement New feature or request released

Comments

@philsturgeon
Copy link
Contributor

philsturgeon commented Jan 21, 2024

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 stoplightio/spectral-owasp-ruleset#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.

@philsturgeon philsturgeon added the enhancement New feature or request label Jan 21, 2024
@P0lip
Copy link
Contributor

P0lip commented Jan 22, 2024

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

philsturgeon added a commit that referenced this issue Jan 22, 2024
fixes #2578 - this was already possible, just not documented.
@philsturgeon
Copy link
Contributor Author

@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
Copy link
Contributor

P0lip commented Jan 23, 2024

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

@stoplight-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 1.19.0 🎉

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

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants