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

Add match regex attribute #1760

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

Flemmli97
Copy link

Adds an attribute match_regex that allows for regex validation for string fields.
Regex config is required but error is not. If error is not provided will use a default error message instead.
#[match_regex=(regex=foo, error="error")]

Copy link
Contributor

@NeunEinser NeunEinser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, only thing is, I am not sure if the error message would actually work like this if we are thinking of translatable mcdoc. But I guess the attribute is not that relevant for vanilla-mcdoc anyways.

I do have some usecases for this attribute in my map, so I would love this feature :D

@misode
Copy link
Member

misode commented Feb 17, 2025

I think it's acceptible that the custom error message is not translatable

const regex = RegExp(pattern)
if (!regex.test(value)) {
if (config.message) {
ctx.err.report(config.message, node, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx.err.report(config.message, node, 2)
ctx.err.report(config.message, node, core.ErrorSeverity.Warning)

You missed this :p

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

Successfully merging this pull request may close these issues.

4 participants