Skip to content

Explore configuration with real regex instead of strings #165

Open
@lydell

Description

@lydell

Now that ESLint 9 is here with Flat config written in JavaScript, it would be cool if it was possible to use regex literals instead of string literals when configuring this plugin.

Pros:

  • No double escaping. Can write /\w/ instead of "\\w".
  • Can choose flags. Like adding i for case in-sensitive.
  • Can get more help from an IDE since it knows you are writing a regex.

What needs to be done:

  • See if this is possible at all in Flat config.
  • Figure out the eslintrc compatibility story.
  • Update docs.
  • Update tests.
  • Support strings forever since it’s easy and then doesn’t force people to do boring update chores?

Example (the default groups):

import simpleImportSort from "eslint-plugin-simple-import-sort";

export default [
  {
    plugins: {
      "simple-import-sort": simpleImportSort,
    },
    rules: {
      "simple-import-sort/imports": ["error", {
        groups: [
          // Side effect imports.
          [/^\u0000/u],
          // Node.js builtins prefixed with `node:`.
          [/^node:/u],
          // Packages.
          // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
          [/^@?\w/u],
          // Absolute imports and other imports such as Vue-style `@/foo`.
          // Anything not matched in another group.
          [/^/u],
          // Relative imports.
          // Anything that starts with a dot.
          [/^\./u],
        ]
      }],
    },
  },
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions