Skip to content

Commit

Permalink
Update regexp-tree (sindresorhus#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 2, 2020
1 parent 875c471 commit 2e273e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lodash.snakecase": "^4.1.1",
"lodash.upperfirst": "^4.3.1",
"read-pkg-up": "^7.0.1",
"regexp-tree": "^0.1.17",
"regexp-tree": "^0.1.20",
"reserved-words": "^0.1.2",
"safe-regex": "^2.1.1",
"semver": "^7.1.2"
Expand Down
4 changes: 2 additions & 2 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const packageDependencies = {
};

const DEPENDENCY_INCLUSION_RE = /^[+-]\s*@?\S+\/?\S+/;
const VERSION_COMPARISON_RE = /^(?<name>@?\S\/?\S+)@(?<condition>>|>=)(?<version>\d+(?:\.\d+){0,2}(?:-[\d\-a-z]+(?:\.[\d\-a-z]+)*)?(?:\+[\d\-a-z]+(?:\.[\d\-a-z]+)*)?)/i;
const PKG_VERSION_RE = /^(?<condition>>|>=)(?<version>\d+(?:\.\d+){0,2}(?:-[\d-a-z]+(?:\.[\d-a-z]+)*)?(?:\+[\d-a-z]+(?:\.[\d-a-z]+)*)?)\s*$/;
const VERSION_COMPARISON_RE = /^(?<name>@?\S\/?\S+)@(?<condition>>|>=)(?<version>\d+(?:\.\d+){0,2}(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?)/i;
const PKG_VERSION_RE = /^(?<condition>>|>=)(?<version>\d+(?:\.\d+){0,2}(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?)\s*$/;
const ISO8601_DATE = /\d{4}-\d{2}-\d{2}/;

function parseTodoWithArguments(string, {terms}) {
Expand Down
15 changes: 12 additions & 3 deletions test/better-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ ruleTester.run('better-regex', rule, {
// `patter` is not `string`
'new RegExp(0)',
// No arguments
'new RegExp()'
'new RegExp()',

// #472
'/[ ;-]/g'
],
invalid: [
// Literal regex
Expand Down Expand Up @@ -160,8 +163,8 @@ ruleTester.run('better-regex', rule, {
},
{
code: 'const foo = /^by @([a-zA-Z0-9-]+)/',
errors: createError('/^by @([a-zA-Z0-9-]+)/', '/^by @([\\d-A-Za-z]+)/'),
output: 'const foo = /^by @([\\d-A-Za-z]+)/'
errors: createError('/^by @([a-zA-Z0-9-]+)/', '/^by @([\\dA-Za-z-]+)/'),
output: 'const foo = /^by @([\\dA-Za-z-]+)/'
},
{
code: '/[GgHhIiå.Z:a-f"0-8%A*ä]/',
Expand Down Expand Up @@ -239,6 +242,12 @@ ruleTester.run('better-regex', rule, {
code: 'const foo = new RegExp(/[0-9]/, 0)',
errors: createError('/[0-9]/', '/\\d/'),
output: 'const foo = new RegExp(/\\d/, 0)'
},
// #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}$/'
}
]
});

0 comments on commit 2e273e9

Please sign in to comment.