Add eslint-plugin-regexp (#24361)

Add
[`eslint-plugin-regexp`](https://github.com/ota-meshi/eslint-plugin-regexp)
and fix discovered issues. Config is mostly the recommended one, but I
relaxed a few rules.
This commit is contained in:
silverwind 2023-04-27 04:08:16 +02:00 committed by GitHub
parent cf465b4721
commit 50133b02bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 160 additions and 4 deletions

View File

@ -15,6 +15,7 @@ plugins:
- eslint-plugin-no-jquery - eslint-plugin-no-jquery
- eslint-plugin-sonarjs - eslint-plugin-sonarjs
- eslint-plugin-custom-elements - eslint-plugin-custom-elements
- eslint-plugin-regexp
env: env:
es2022: true es2022: true
@ -472,6 +473,80 @@ rules:
quote-props: [0] quote-props: [0]
quotes: [2, single, {avoidEscape: true, allowTemplateLiterals: true}] quotes: [2, single, {avoidEscape: true, allowTemplateLiterals: true}]
radix: [2, as-needed] radix: [2, as-needed]
regexp/confusing-quantifier: [2]
regexp/control-character-escape: [2]
regexp/hexadecimal-escape: [0]
regexp/letter-case: [0]
regexp/match-any: [2]
regexp/negation: [2]
regexp/no-contradiction-with-assertion: [0]
regexp/no-control-character: [0]
regexp/no-dupe-characters-character-class: [2]
regexp/no-dupe-disjunctions: [2]
regexp/no-empty-alternative: [2]
regexp/no-empty-capturing-group: [2]
regexp/no-empty-character-class: [0]
regexp/no-empty-group: [2]
regexp/no-empty-lookarounds-assertion: [2]
regexp/no-escape-backspace: [2]
regexp/no-extra-lookaround-assertions: [0]
regexp/no-invalid-regexp: [2]
regexp/no-invisible-character: [2]
regexp/no-lazy-ends: [2]
regexp/no-legacy-features: [2]
regexp/no-misleading-capturing-group: [0]
regexp/no-misleading-unicode-character: [0]
regexp/no-missing-g-flag: [2]
regexp/no-non-standard-flag: [2]
regexp/no-obscure-range: [2]
regexp/no-octal: [2]
regexp/no-optional-assertion: [2]
regexp/no-potentially-useless-backreference: [2]
regexp/no-standalone-backslash: [2]
regexp/no-super-linear-backtracking: [0]
regexp/no-super-linear-move: [0]
regexp/no-trivially-nested-assertion: [2]
regexp/no-trivially-nested-quantifier: [2]
regexp/no-unused-capturing-group: [0]
regexp/no-useless-assertions: [2]
regexp/no-useless-backreference: [2]
regexp/no-useless-character-class: [2]
regexp/no-useless-dollar-replacements: [2]
regexp/no-useless-escape: [2]
regexp/no-useless-flag: [2]
regexp/no-useless-lazy: [2]
regexp/no-useless-non-capturing-group: [2]
regexp/no-useless-quantifier: [2]
regexp/no-useless-range: [2]
regexp/no-useless-two-nums-quantifier: [2]
regexp/no-zero-quantifier: [2]
regexp/optimal-lookaround-quantifier: [2]
regexp/optimal-quantifier-concatenation: [0]
regexp/prefer-character-class: [0]
regexp/prefer-d: [0]
regexp/prefer-escape-replacement-dollar-char: [0]
regexp/prefer-lookaround: [0]
regexp/prefer-named-backreference: [0]
regexp/prefer-named-capture-group: [0]
regexp/prefer-named-replacement: [0]
regexp/prefer-plus-quantifier: [2]
regexp/prefer-predefined-assertion: [2]
regexp/prefer-quantifier: [0]
regexp/prefer-question-quantifier: [2]
regexp/prefer-range: [2]
regexp/prefer-regexp-exec: [2]
regexp/prefer-regexp-test: [2]
regexp/prefer-result-array-groups: [0]
regexp/prefer-star-quantifier: [2]
regexp/prefer-unicode-codepoint-escapes: [2]
regexp/prefer-w: [0]
regexp/require-unicode-regexp: [0]
regexp/sort-alternatives: [0]
regexp/sort-character-class-elements: [0]
regexp/sort-flags: [0]
regexp/strict: [2]
regexp/unicode-escape: [0]
regexp/use-ignore-case: [0]
require-atomic-updates: [0] require-atomic-updates: [0]
require-await: [0] require-await: [0]
require-unicode-regexp: [0] require-unicode-regexp: [0]

View File

@ -138,8 +138,8 @@ function populateResults(result) {
function render(templateString, data) { function render(templateString, data) {
let conditionalMatches, copy; let conditionalMatches, copy;
const conditionalPattern = /\$\{\s*isset ([a-zA-Z]*) \s*\}(.*)\$\{\s*end\s*}/g; const conditionalPattern = /\$\{\s*isset ([a-zA-Z]*) \s*\}(.*)\$\{\s*end\s*\}/g;
// since loop below depends on re.lastInxdex, we use a copy to capture any manipulations whilst inside the loop // since loop below depends on re.lastIndex, we use a copy to capture any manipulations whilst inside the loop
copy = templateString; copy = templateString;
while ((conditionalMatches = conditionalPattern.exec(templateString)) !== null) { while ((conditionalMatches = conditionalPattern.exec(templateString)) !== null) {
if (data[conditionalMatches[1]]) { if (data[conditionalMatches[1]]) {

80
package-lock.json generated
View File

@ -65,6 +65,7 @@
"eslint-plugin-import": "2.27.5", "eslint-plugin-import": "2.27.5",
"eslint-plugin-jquery": "1.5.1", "eslint-plugin-jquery": "1.5.1",
"eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-no-jquery": "2.7.0",
"eslint-plugin-regexp": "1.14.0",
"eslint-plugin-sonarjs": "0.19.0", "eslint-plugin-sonarjs": "0.19.0",
"eslint-plugin-unicorn": "46.0.0", "eslint-plugin-unicorn": "46.0.0",
"eslint-plugin-vue": "9.11.0", "eslint-plugin-vue": "9.11.0",
@ -2927,6 +2928,15 @@
"node": ">= 12" "node": ">= 12"
} }
}, },
"node_modules/comment-parser": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.3.1.tgz",
"integrity": "sha512-B52sN2VNghyq5ofvUsqZjmk6YkihBX5vMSChmSK9v4ShjKf3Vk5Xcmgpw4o+iIgtrnM/u5FiMpz9VKb8lpBveA==",
"dev": true,
"engines": {
"node": ">= 12.0.0"
}
},
"node_modules/commondir": { "node_modules/commondir": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
@ -4560,6 +4570,28 @@
"eslint": ">=2.3.0" "eslint": ">=2.3.0"
} }
}, },
"node_modules/eslint-plugin-regexp": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-regexp/-/eslint-plugin-regexp-1.14.0.tgz",
"integrity": "sha512-5+bBSsRTTtkSf8+/iNSjiOW6qbjAdGyqv88HxPaBNFKxROK+UAdOGDl5Jr+csV5wW2BuOOvaG82zsvTriQBRFA==",
"dev": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.4.0",
"comment-parser": "^1.1.2",
"grapheme-splitter": "^1.0.4",
"jsdoctypeparser": "^9.0.0",
"refa": "^0.11.0",
"regexp-ast-analysis": "^0.6.0",
"scslre": "^0.2.0"
},
"engines": {
"node": "^12 || >=14"
},
"peerDependencies": {
"eslint": ">=6.0.0"
}
},
"node_modules/eslint-plugin-sonarjs": { "node_modules/eslint-plugin-sonarjs": {
"version": "0.19.0", "version": "0.19.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.19.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.19.0.tgz",
@ -6038,6 +6070,18 @@
"js-yaml": "bin/js-yaml.js" "js-yaml": "bin/js-yaml.js"
} }
}, },
"node_modules/jsdoctypeparser": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-9.0.0.tgz",
"integrity": "sha512-jrTA2jJIL6/DAEILBEh2/w9QxCuwmvNXIry39Ay/HVfhE3o2yVV0U44blYkqdHA/OKloJEqvJy0xU+GSdE2SIw==",
"dev": true,
"bin": {
"jsdoctypeparser": "bin/jsdoctypeparser"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jsdom": { "node_modules/jsdom": {
"version": "21.1.1", "version": "21.1.1",
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.1.1.tgz", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.1.1.tgz",
@ -7934,11 +7978,36 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/refa": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/refa/-/refa-0.11.0.tgz",
"integrity": "sha512-486O8/pQXwj9jV0mVvUnTsxq0uknpBnNJ0eCUhkZqJRQ8KutrT1PhzmumdCeM1hSBF2eMlFPmwECRER4IbKXlQ==",
"dev": true,
"dependencies": {
"@eslint-community/regexpp": "^4.5.0"
},
"engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
}
},
"node_modules/regenerator-runtime": { "node_modules/regenerator-runtime": {
"version": "0.13.11", "version": "0.13.11",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
}, },
"node_modules/regexp-ast-analysis": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/regexp-ast-analysis/-/regexp-ast-analysis-0.6.0.tgz",
"integrity": "sha512-OLxjyjPkVH+rQlBLb1I/P/VTmamSjGkvN5PTV5BXP432k3uVz727J7H29GA5IFiY0m7e1xBN7049Wn59FY3DEQ==",
"dev": true,
"dependencies": {
"@eslint-community/regexpp": "^4.5.0",
"refa": "^0.11.0"
},
"engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
}
},
"node_modules/regexp-tree": { "node_modules/regexp-tree": {
"version": "0.1.25", "version": "0.1.25",
"resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.25.tgz", "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.25.tgz",
@ -8247,6 +8316,17 @@
"url": "https://opencollective.com/webpack" "url": "https://opencollective.com/webpack"
} }
}, },
"node_modules/scslre": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/scslre/-/scslre-0.2.0.tgz",
"integrity": "sha512-4hc49fUMmX3jM0XdFUAPBrs1xwEcdHa0KyjEsjFs+Zfc66mpFpq5YmRgDtl+Ffo6AtJIilfei+yKw8fUn3N88w==",
"dev": true,
"dependencies": {
"@eslint-community/regexpp": "^4.5.0",
"refa": "^0.11.0",
"regexp-ast-analysis": "^0.6.0"
}
},
"node_modules/semver": { "node_modules/semver": {
"version": "7.5.0", "version": "7.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.0.tgz",

View File

@ -65,6 +65,7 @@
"eslint-plugin-import": "2.27.5", "eslint-plugin-import": "2.27.5",
"eslint-plugin-jquery": "1.5.1", "eslint-plugin-jquery": "1.5.1",
"eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-no-jquery": "2.7.0",
"eslint-plugin-regexp": "1.14.0",
"eslint-plugin-sonarjs": "0.19.0", "eslint-plugin-sonarjs": "0.19.0",
"eslint-plugin-unicorn": "46.0.0", "eslint-plugin-unicorn": "46.0.0",
"eslint-plugin-vue": "9.11.0", "eslint-plugin-vue": "9.11.0",

View File

@ -136,7 +136,7 @@ function togglePreviewDisplay(previewable) {
if (!previewTab) return; if (!previewTab) return;
if (previewable) { if (previewable) {
const newUrl = (previewTab.getAttribute('data-url') || '').replace(/(.*)\/.*/i, `$1/markup`); const newUrl = (previewTab.getAttribute('data-url') || '').replace(/(.*)\/.*/, `$1/markup`);
previewTab.setAttribute('data-url', newUrl); previewTab.setAttribute('data-url', newUrl);
previewTab.style.display = ''; previewTab.style.display = '';
} else { } else {

View File

@ -32,7 +32,7 @@ export function isDarkTheme() {
// strip <tags> from a string // strip <tags> from a string
export function stripTags(text) { export function stripTags(text) {
return text.replace(/<[^>]*>?/gm, ''); return text.replace(/<[^>]*>?/g, '');
} }
// searches the inclusive range [minValue, maxValue]. // searches the inclusive range [minValue, maxValue].