Skip to content

Commit 96f922c

Browse files
authored
Add support for y flag to regexp/no-useless-flag rule. (#224)
1 parent 7f9e924 commit 96f922c

File tree

3 files changed

+475
-113
lines changed

3 files changed

+475
-113
lines changed

docs/rules/no-useless-flag.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,37 @@ str.search(/foo/g);
116116

117117
</eslint-code-block>
118118

119+
### `y` flag (sticky)
120+
121+
The `y` flag is used when you need to do a sticky search. If not, it will be unnecessary.
122+
123+
<eslint-code-block fix>
124+
125+
```js
126+
/* eslint regexp/no-useless-flag: "error" */
127+
128+
/* ✓ GOOD */
129+
const regex1 = /foo/y;
130+
const str = 'table football, foosball';
131+
regex1.lastIndex = 6
132+
var array = regex1.exec(str)
133+
134+
const regex2 = /foo/y;
135+
regex2.test(string);
136+
regex2.test(string);
137+
138+
str.replace(/foo/y, 'bar');
139+
str.replaceAll(/foo/gy, 'bar');
140+
141+
const regexp3 = /foo/y
142+
str.search(regexp3)
143+
144+
/* ✗ BAD */
145+
str.split(/foo/y);
146+
```
147+
148+
</eslint-code-block>
149+
119150
### other flags
120151

121152
No other flags will be checked.
@@ -126,7 +157,7 @@ No other flags will be checked.
126157
{
127158
"regexp/no-useless-flag": ["error",
128159
{
129-
"ignore": [] // An array of "i", "m", "s" and "g".
160+
"ignore": [] // An array of "i", "m", "s", "g" and "y".
130161
}
131162
]
132163
}

0 commit comments

Comments
 (0)