Skip to content

Commit e576987

Browse files
Added suggestions for regexp/no-escape-backspace (#622)
* Added suggestions for `regexp/no-escape-backspace` * Create twenty-snails-chew.md
1 parent f719c81 commit e576987

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

.changeset/twenty-snails-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Added suggestions for `regexp/no-escape-backspace`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The `plugin:regexp/all` config enables all rules. It's meant for testing, not fo
117117
| [no-empty-character-class](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-character-class.html) | disallow character classes that match no characters || | | |
118118
| [no-empty-group](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-group.html) | disallow empty group || | | |
119119
| [no-empty-lookarounds-assertion](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-lookarounds-assertion.html) | disallow empty lookahead assertion or empty lookbehind assertion || | | |
120-
| [no-escape-backspace](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-escape-backspace.html) | disallow escape backspace (`[\b]`) || | | |
120+
| [no-escape-backspace](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-escape-backspace.html) | disallow escape backspace (`[\b]`) || | | 💡 |
121121
| [no-invalid-regexp](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invalid-regexp.html) | disallow invalid regular expression strings in `RegExp` constructors || | | |
122122
| [no-lazy-ends](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-lazy-ends.html) | disallow lazy quantifiers at the end of an expression | || | |
123123
| [no-misleading-capturing-group](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-misleading-capturing-group.html) | disallow capturing groups that do not behave as one would expect || | | 💡 |

docs/rules/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sidebarDepth: 0
2424
| [no-empty-character-class](no-empty-character-class.md) | disallow character classes that match no characters || | | |
2525
| [no-empty-group](no-empty-group.md) | disallow empty group || | | |
2626
| [no-empty-lookarounds-assertion](no-empty-lookarounds-assertion.md) | disallow empty lookahead assertion or empty lookbehind assertion || | | |
27-
| [no-escape-backspace](no-escape-backspace.md) | disallow escape backspace (`[\b]`) || | | |
27+
| [no-escape-backspace](no-escape-backspace.md) | disallow escape backspace (`[\b]`) || | | 💡 |
2828
| [no-invalid-regexp](no-invalid-regexp.md) | disallow invalid regular expression strings in `RegExp` constructors || | | |
2929
| [no-lazy-ends](no-lazy-ends.md) | disallow lazy quantifiers at the end of an expression | || | |
3030
| [no-misleading-capturing-group](no-misleading-capturing-group.md) | disallow capturing groups that do not behave as one would expect || | | 💡 |

docs/rules/no-escape-backspace.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ since: "v0.1.0"
99

1010
💼 This rule is enabled in the ✅ `plugin:regexp/recommended` config.
1111

12+
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
13+
1214
<!-- end auto-generated rule header -->
1315

1416
> disallow escape backspace (`[\b]`)

lib/rules/no-escape-backspace.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ export default createRule("no-escape-backspace", {
1010
recommended: true,
1111
},
1212
schema: [],
13+
hasSuggestions: true,
1314
messages: {
1415
unexpected: "Unexpected '[\\b]'. Use '\\u0008' instead.",
16+
suggest: "Use '\\u0008'.",
1517
},
1618
type: "suggestion", // "problem",
1719
},
1820
create(context) {
1921
function createVisitor({
2022
node,
2123
getRegexpLocation,
24+
fixReplaceNode,
2225
}: RegExpContext): RegExpVisitor.Handlers {
2326
return {
2427
onCharacterEnter(cNode) {
@@ -27,6 +30,12 @@ export default createRule("no-escape-backspace", {
2730
node,
2831
loc: getRegexpLocation(cNode),
2932
messageId: "unexpected",
33+
suggest: [
34+
{
35+
messageId: "suggest",
36+
fix: fixReplaceNode(cNode, "\\u0008"),
37+
},
38+
],
3039
})
3140
}
3241
},

tests/lib/rules/no-escape-backspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tester.run("no-escape-backspace", rule as any, {
1818
message: "Unexpected '[\\b]'. Use '\\u0008' instead.",
1919
column: 3,
2020
endColumn: 5,
21+
suggestions: [{ output: "/[\\u0008]/" }],
2122
},
2223
],
2324
},

0 commit comments

Comments
 (0)