Skip to content

Commit cdc9ddd

Browse files
committed
feat: use real regex instead of strings
Fixes #165
1 parent 57708e4 commit cdc9ddd

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const error = "error";
44
const warn = process.argv.includes("--report-unused-disable-directives")
55
? "error"
66
: "warn";
7+
const off = "off";
78

89
module.exports = {
910
root: true,
@@ -61,6 +62,7 @@ module.exports = {
6162
eqeqeq: [error, "always", { null: "ignore" }],
6263
strict: error,
6364
yoda: warn,
65+
"no-control-regex": off,
6466
},
6567
overrides: [
6668
{

examples/.eslintrc.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ module.exports = {
7777
// Note that if you use the `node:` prefix for Node.js builtins,
7878
// you can avoid this complexity: You can simply use "^node:".
7979
[
80-
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)",
80+
/^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(\/.*|$)/u,
8181
],
8282
// Packages. `react` related packages come first.
83-
["^react", "^@?\\w"],
83+
[/^react/u, /^@?\w/u],
8484
// Internal packages.
85-
["^(@|@company|@ui|components|utils|config|vendored-lib)(/.*|$)"],
85+
[/^(@|@company|@ui|components|utils|config|vendored-lib)(\/.*|$)/u],
8686
// Side effect imports.
87-
["^\\u0000"],
87+
[/^\u0000/u],
8888
// Parent imports. Put `..` last.
89-
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
89+
[/^\.\.(?!\/?$)/u, /^\.\.\/?$/u],
9090
// Other relative imports. Put same-folder imports and `.` last.
91-
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
91+
[/^\.\/(?=.*\/)(?!\/?$)/u, /^\.(?!\/?$)/u, /^\.\/?$/u],
9292
// Style imports.
93-
["^.+\\.s?css$"],
93+
[/^.+\.s?css$/u],
9494
],
9595
},
9696
],

src/imports.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"use strict";
2+
// @ts-check
3+
// @ts-check
24

35
const shared = require("./shared");
46

57
const defaultGroups = [
68
// Side effect imports.
7-
["^\\u0000"],
9+
[/^\u0000/u],
810
// Node.js builtins prefixed with `node:`.
9-
["^node:"],
11+
[/^node:/u],
1012
// Packages.
1113
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
12-
["^@?\\w"],
14+
[/^@?\w/u],
1315
// Absolute imports and other imports such as Vue-style `@/foo`.
1416
// Anything not matched in another group.
15-
["^"],
17+
[/^/u],
1618
// Relative imports.
1719
// Anything that starts with a dot.
18-
["^\\."],
20+
[/^\./u],
1921
];
2022

2123
module.exports = {
@@ -30,9 +32,7 @@ module.exports = {
3032
type: "array",
3133
items: {
3234
type: "array",
33-
items: {
34-
type: "string",
35-
},
35+
uniqueItems: true,
3636
},
3737
},
3838
},
@@ -51,7 +51,7 @@ module.exports = {
5151
const { groups: rawGroups = defaultGroups } = context.options[0] || {};
5252

5353
const outerGroups = rawGroups.map((groups) =>
54-
groups.map((item) => RegExp(item, "u")),
54+
groups.map((item) => (item instanceof RegExp ? item : RegExp(item, "u"))),
5555
);
5656

5757
const parents = new Set();

0 commit comments

Comments
 (0)