diff --git a/.eslintrc.json b/.eslintrc.json index 100f9c243..52fd93e40 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -49,9 +49,11 @@ "import/no-duplicates": "error", "import/order": "error", "prettier/prettier": "error", + "unicorn/better-regex": "error", "unicorn/no-abusive-eslint-disable": "error", "unicorn/prefer-module": "error", "unicorn/prefer-node-protocol": "error", + "unicorn/prefer-regexp-test": "error", "unicorn/prefer-string-replace-all": "error" }, "overrides": [ diff --git a/packages/inquirer/examples/input.js b/packages/inquirer/examples/input.js index 5e06a92ce..7736f5c0c 100644 --- a/packages/inquirer/examples/input.js +++ b/packages/inquirer/examples/input.js @@ -5,7 +5,7 @@ import chalk from 'chalk'; import inquirer from '../lib/inquirer.js'; -const hexRegEx = /([0-9]|[a-f])/gim; +const hexRegEx = /(\d|[a-f])/gim; const isHex = (value) => (value.match(hexRegEx) || []).length === value.length && (value.length === 3 || value.length === 6); @@ -43,7 +43,7 @@ const questions = [ message: "What's your phone number", validate(value) { const pass = value.match( - /^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i, + /^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i, ); if (pass) { return true; diff --git a/packages/inquirer/examples/pizza.js b/packages/inquirer/examples/pizza.js index bedf579f6..80365402b 100644 --- a/packages/inquirer/examples/pizza.js +++ b/packages/inquirer/examples/pizza.js @@ -21,7 +21,7 @@ const questions = [ message: "What's your phone number?", validate(value) { const pass = value.match( - /^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i, + /^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i, ); if (pass) { return true; diff --git a/packages/inquirer/examples/regex-validate-input.js b/packages/inquirer/examples/regex-validate-input.js index ad9eb6ad1..90bce8338 100644 --- a/packages/inquirer/examples/regex-validate-input.js +++ b/packages/inquirer/examples/regex-validate-input.js @@ -10,7 +10,7 @@ const questions = [ name: 'api_key', message: 'Please enter a valid API key.', validate(input) { - if (/([a-f0-9]{40})/g.test(input)) { + if (/([\da-f]{40})/g.test(input)) { return true; } diff --git a/packages/inquirer/examples/rx-observable-array.js b/packages/inquirer/examples/rx-observable-array.js index d22e685f0..2f6c964e1 100644 --- a/packages/inquirer/examples/rx-observable-array.js +++ b/packages/inquirer/examples/rx-observable-array.js @@ -21,7 +21,7 @@ const questions = [ message: "What's your phone number", validate(value) { const pass = value.match( - /^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i, + /^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i, ); if (pass) { return true; diff --git a/packages/inquirer/examples/rx-observable-create.js b/packages/inquirer/examples/rx-observable-create.js index d07f83de3..22fd6c632 100644 --- a/packages/inquirer/examples/rx-observable-create.js +++ b/packages/inquirer/examples/rx-observable-create.js @@ -23,7 +23,7 @@ const observe = Observable.create((obs) => { message: "What's your phone number", validate(value) { const pass = value.match( - /^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i, + /^([01])?[\s.-]?\(?(\d{3})\)?[\s.-]?(\d{3})[\s.-]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?)(?:\d+)?)?$/i, ); if (pass) { return true; diff --git a/packages/inquirer/lib/ui/bottom-bar.js b/packages/inquirer/lib/ui/bottom-bar.js index 12673958c..de5e9c652 100644 --- a/packages/inquirer/lib/ui/bottom-bar.js +++ b/packages/inquirer/lib/ui/bottom-bar.js @@ -68,7 +68,7 @@ export default class BottomBar extends Base { */ enforceLF(str) { - return str.match(/[\r\n]$/) ? str : str + '\n'; + return /[\n\r]$/.test(str) ? str : str + '\n'; } /** diff --git a/packages/inquirer/test/specs/utils/paginator.test.js b/packages/inquirer/test/specs/utils/paginator.test.js index b1869fff7..0d01bf7df 100644 --- a/packages/inquirer/test/specs/utils/paginator.test.js +++ b/packages/inquirer/test/specs/utils/paginator.test.js @@ -33,7 +33,7 @@ const endIndex = output.split('\n').length - 1; const getPage = (paginator, index) => { const lines = paginator.paginate(output, index, pageSize).split('\n'); const lastLine = lines.pop(); - if (!lastLine.match(/Move up and down/)) { + if (!/Move up and down/.test(lastLine)) { lines.push(lastLine); } return lines.join('\n'); diff --git a/packages/rawlist/src/index.mts b/packages/rawlist/src/index.mts index 4ab5bfb53..c9304dab4 100644 --- a/packages/rawlist/src/index.mts +++ b/packages/rawlist/src/index.mts @@ -11,7 +11,7 @@ import { import type { PartialDeep } from '@inquirer/type'; import chalk from 'chalk'; -const numberRegex = /[0-9]+/; +const numberRegex = /\d+/; type Choice = { value: Value;