Use real regex instead of strings
Fixes #165
Doesn't break tests, which seems good. Haven't tested a custom config yet.
Ok, I discovered the examples folder. The patch seems to work well.
Cool! We have this:
module.exports = {
meta: {
type: "layout",
fixable: "code",
schema: [
{
type: "object",
properties: {
groups: {
type: "array",
items: {
type: "array",
items: {
type: "string", // ????
},
},
},
},
additionalProperties: false,
},
],
},
Do you know how this stuff works? We’re not passing strings now like the schema says, we’re passing RegExp instances.
Other things that I’m noting that needs to be done (either by me or someone else):
- Probably have tests/examples with both regex and strings.
- Update docs, including mentioning something about .json config maybe?
- Maybe validate that the user does not use the
gflag, I think that’ll break things?
unicorn doesn't specify it, so I didn't. There's probably a way, but I'm not a JSON schema expert.
Ok, so I just discovered that you can pass a regex into the new Regex constructor, and it'll overwrite the flags. That prevents the "I forgot the u flag" pitfall and the "I added the g flag pitfall", but prevents adding the i flag, and might be too much magic?
I think the u flag doesn’t matter to many people, but thanks to the power of copy-paste I think most will use it anyway. So no need to force it in, I would say.