Skip to content

Commit

Permalink
Merge 0e75712 into b5c0a12
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 16, 2020
2 parents b5c0a12 + 0e75712 commit 26945e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"import-modules": "^2.0.0",
"lodash": "^4.17.15",
"read-pkg-up": "^7.0.1",
"regexp-tree": "^0.1.20",
"regexp-tree": "^0.1.21",
"reserved-words": "^0.1.2",
"safe-regex": "^2.1.1",
"semver": "^7.1.2"
Expand Down
26 changes: 25 additions & 1 deletion test/better-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const disableSortCharacterClassesOptions = [
}
];

const testCase = (original, optimized) => ({
code: original,
output: optimized,
errors: createError(original, optimized)
});

ruleTester.run('better-regex', rule, {
valid: [
// Literal regex
Expand Down Expand Up @@ -243,11 +249,29 @@ ruleTester.run('better-regex', rule, {
errors: createError('/[0-9]/', '/\\d/'),
output: 'const foo = new RegExp(/\\d/, 0)'
},
// `\s` rewrite
testCase(
'/[ \\f\\n\\r\\t\\v\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]+/',
'/\\s+/'
),
// #499
{
code: '/^[a-z][a-z0-9\\-]{5,29}$/',
errors: createError('/^[a-z][a-z0-9\\-]{5,29}$/', '/^[a-z][\\da-z\\-]{5,29}$/'),
output: '/^[a-z][\\da-z\\-]{5,29}$/'
}
},
// #477
testCase(
'/[ \\n\\t\\r\\]]/g',
'/[\\t\\n\\r \\]]/g'
),
testCase(
'/[ \\n\\t\\r\\f"#\'()/;[\\\\\\]{}]/g',
'/[\\t\\n\\f\\r "#\'()/;[\\\\\\]{}]/g'
),
testCase(
'/[ \\n\\t\\r\\f(){}:;@!\'"\\\\\\][#]|\\/(?=\\*)/g',
'/[\\t\\n\\f\\r !"#\'():;@[\\\\\\]{}]|\\/(?=\\*)/g'
)
]
});

0 comments on commit 26945e6

Please sign in to comment.