Skip to content

Commit 4e9338a

Browse files
authoredAug 27, 2021
ESLint: Added regexp/no-super-linear-backtracking rule (#3040)
1 parent 44456b2 commit 4e9338a

8 files changed

+19
-6
lines changed
 

‎.eslintrc.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@ module.exports = {
5656
'jsdoc/require-property-name': 'warn',
5757

5858
// regexp
59-
'regexp/no-empty-capturing-group': 'error',
6059
'regexp/no-dupe-disjunctions': 'error',
6160
'regexp/no-empty-alternative': 'error',
61+
'regexp/no-empty-capturing-group': 'error',
6262
'regexp/no-empty-lookarounds-assertion': 'error',
6363
'regexp/no-lazy-ends': 'error',
6464
'regexp/no-obscure-range': 'error',
6565
'regexp/no-optional-assertion': 'error',
6666
'regexp/no-standalone-backslash': 'error',
67+
'regexp/no-super-linear-backtracking': 'error',
68+
'regexp/no-unused-capturing-group': 'error',
6769
'regexp/no-zero-quantifier': 'error',
6870
'regexp/optimal-lookaround-quantifier': 'error',
69-
'regexp/no-unused-capturing-group': 'error',
7071

7172
'regexp/match-any': 'warn',
7273
'regexp/negation': 'warn',

‎components/prism-core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ var Prism = (function (_self) {
201201
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
202202
// at Global code (http://localhost/components/prism-core.js:606:1)
203203

204-
var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
204+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
205205
if (src) {
206206
var scripts = document.getElementsByTagName('script');
207207
for (var i in scripts) {

‎components/prism-core.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components/prism-kumir.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
/** Should be performed after searching for reserved words. */
7878
'name': {
79+
// eslint-disable-next-line regexp/no-super-linear-backtracking
7980
pattern: wrapId(/(^|[<nonId>])[^\d<nonId>][^<nonId>]*(?:\x20+[^<nonId>]+)*(?=[<nonId>]|$)/.source),
8081
lookbehind: true
8182
},

‎components/prism-textile.js

+10
Original file line numberDiff line numberDiff line change
@@ -91,51 +91,59 @@
9191
},
9292

9393
'inline': {
94+
// eslint-disable-next-line regexp/no-super-linear-backtracking
9495
pattern: withModifier(/(^|[^a-zA-Z\d])(\*\*|__|\?\?|[*_%@+\-^~])<MOD>*.+?\2(?![a-zA-Z\d])/.source),
9596
lookbehind: true,
9697
inside: {
9798
// Note: superscripts and subscripts are not handled specifically
9899

99100
// *bold*, **bold**
100101
'bold': {
102+
// eslint-disable-next-line regexp/no-super-linear-backtracking
101103
pattern: withModifier(/(^(\*\*?)<MOD>*).+?(?=\2)/.source),
102104
lookbehind: true
103105
},
104106

105107
// _italic_, __italic__
106108
'italic': {
109+
// eslint-disable-next-line regexp/no-super-linear-backtracking
107110
pattern: withModifier(/(^(__?)<MOD>*).+?(?=\2)/.source),
108111
lookbehind: true
109112
},
110113

111114
// ??cite??
112115
'cite': {
116+
// eslint-disable-next-line regexp/no-super-linear-backtracking
113117
pattern: withModifier(/(^\?\?<MOD>*).+?(?=\?\?)/.source),
114118
lookbehind: true,
115119
alias: 'string'
116120
},
117121

118122
// @code@
119123
'code': {
124+
// eslint-disable-next-line regexp/no-super-linear-backtracking
120125
pattern: withModifier(/(^@<MOD>*).+?(?=@)/.source),
121126
lookbehind: true,
122127
alias: 'keyword'
123128
},
124129

125130
// +inserted+
126131
'inserted': {
132+
// eslint-disable-next-line regexp/no-super-linear-backtracking
127133
pattern: withModifier(/(^\+<MOD>*).+?(?=\+)/.source),
128134
lookbehind: true
129135
},
130136

131137
// -deleted-
132138
'deleted': {
139+
// eslint-disable-next-line regexp/no-super-linear-backtracking
133140
pattern: withModifier(/(^-<MOD>*).+?(?=-)/.source),
134141
lookbehind: true
135142
},
136143

137144
// %span%
138145
'span': {
146+
// eslint-disable-next-line regexp/no-super-linear-backtracking
139147
pattern: withModifier(/(^%<MOD>*).+?(?=%)/.source),
140148
lookbehind: true
141149
},
@@ -168,9 +176,11 @@
168176
// "text":http://example.com
169177
// "text":link-ref
170178
'link': {
179+
// eslint-disable-next-line regexp/no-super-linear-backtracking
171180
pattern: withModifier(/"<MOD>*[^"]+":.+?(?=[^\w/]?(?:\s|$))/.source),
172181
inside: {
173182
'text': {
183+
// eslint-disable-next-line regexp/no-super-linear-backtracking
174184
pattern: withModifier(/(^"<MOD>*)[^"]+(?=")/.source),
175185
lookbehind: true
176186
},

‎docs/prism-core.js.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ <h1 class="page-title">prism-core.js</h1>
254254
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
255255
// at Global code (http://localhost/components/prism-core.js:606:1)
256256

257-
var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
257+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
258258
if (src) {
259259
var scripts = document.getElementsByTagName('script');
260260
for (var i in scripts) {

‎gulpfile.js/changelog.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function createSortedArray(compareFn) {
5858
* @typedef {"A" | "C" | "D" | "M" | "R" | "T" | "U" | "X" | "B"} ChangeMode
5959
*/
6060
async function getCommitInfo(line) {
61+
// eslint-disable-next-line regexp/no-super-linear-backtracking
6162
const [, hash, message] = /^([a-f\d]+)\s+(.*)$/i.exec(line);
6263

6364
/* The output looks like this:

‎prism.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ var Prism = (function (_self) {
206206
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
207207
// at Global code (http://localhost/components/prism-core.js:606:1)
208208

209-
var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
209+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
210210
if (src) {
211211
var scripts = document.getElementsByTagName('script');
212212
for (var i in scripts) {

0 commit comments

Comments
 (0)
Please sign in to comment.