From 7c1550cbe952a14837b0ec4ed3f46365e29ed14e Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 13 Feb 2022 16:57:09 -0800 Subject: [PATCH] Remove RegExp lookbehind assertions used to fix "Polynomial regular expression used on uncontrolled data" because they are not supported in Safari, add eslint-plugin-es rule no-regexp-lookbehind-assertions to prevent regressions. --- .eslintrc.json | 3 +++ demo/markdownlint-browser.js | 4 ++-- helpers/helpers.js | 4 ++-- package.json | 1 + test/rules/lint-javascript.js | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ce631029..75dbebbb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -53,6 +53,7 @@ "sourceType": "script" }, "plugins": [ + "es", "jsdoc", "node", "unicorn" @@ -105,6 +106,8 @@ "vars-on-top": "off", "wrap-regex": "off", + "es/no-regexp-lookbehind-assertions": "error", + "jsdoc/check-access": "error", "jsdoc/check-alignment": "error", "jsdoc/check-examples": "off", diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index c7762a0d..b7ca1ad6 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -50,11 +50,11 @@ module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; // Regular expression for all instances of emphasis markers var emphasisMarkersRe = /[_*]/g; // Regular expression for inline links and shortcut reference links -var linkRe = /(?:|(?)\)/; + /\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/; // Regular expression for link reference definition lines module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/; // All punctuation characters (normal and full-width) diff --git a/helpers/helpers.js b/helpers/helpers.js index 03a941ac..873c978b 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -28,12 +28,12 @@ const emphasisMarkersRe = /[_*]/g; // Regular expression for inline links and shortcut reference links const linkRe = - /(?:|(?)\)/; + /\[(?:[^[\]]?(?:\[[^[\]]*\])?)*\]\((?:|#|<>)\)/; // Regular expression for link reference definition lines module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/; diff --git a/package.json b/package.json index becda3d4..c97070f0 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "ava": "3.15.0", "c8": "7.10.0", "eslint": "8.5.0", + "eslint-plugin-es": "4.1.0", "eslint-plugin-jsdoc": "37.4.0", "eslint-plugin-node": "11.1.0", "eslint-plugin-unicorn": "39.0.0", diff --git a/test/rules/lint-javascript.js b/test/rules/lint-javascript.js index 0c8f4d1f..0462b2a6 100644 --- a/test/rules/lint-javascript.js +++ b/test/rules/lint-javascript.js @@ -17,7 +17,7 @@ const languageJavaScript = /js|javascript/i; function cleanJsdocRulesFromEslintConfig(config) { const cleanedConfig = { ...config }; for (const rule in config.rules) { - if (/^(jsdoc|node|unicorn)\//.test(rule)) { + if (/^(es|jsdoc|node|unicorn)\//.test(rule)) { delete cleanedConfig.rules[rule]; } }