eslint-plugin-simple-import-sort icon indicating copy to clipboard operation
eslint-plugin-simple-import-sort copied to clipboard

Use real regex instead of strings

Open lishaduck opened this issue 1 year ago • 5 comments

Fixes #165

Doesn't break tests, which seems good. Haven't tested a custom config yet.

lishaduck avatar Jul 10 '24 16:07 lishaduck

Ok, I discovered the examples folder. The patch seems to work well.

lishaduck avatar Jul 10 '24 17:07 lishaduck

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 g flag, I think that’ll break things?

lydell avatar Jul 11 '24 06:07 lydell

unicorn doesn't specify it, so I didn't. There's probably a way, but I'm not a JSON schema expert.

lishaduck avatar Jul 11 '24 17:07 lishaduck

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?

lishaduck avatar Jul 17 '24 02:07 lishaduck

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.

lydell avatar Jul 17 '24 06:07 lydell