Skip to content

Commit 5ac88c2

Browse files
authored
1 parent b3f51b2 commit 5ac88c2

26 files changed

+120
-79
lines changed

.changeset/strong-carrots-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": patch
3+
---
4+
5+
Use new ESLint API

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@ module.exports = {
4343
],
4444
},
4545
],
46+
// See https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/
47+
"no-restricted-properties": [
48+
"error",
49+
{
50+
object: "context",
51+
property: "getSourceCode",
52+
message: "Please use `context.sourceCode` instead.",
53+
},
54+
{
55+
object: "context",
56+
property: "getFilename",
57+
message: "Please use `context.filename` instead.",
58+
},
59+
{
60+
object: "context",
61+
property: "getCwd",
62+
message: "Please use `context.cwd` instead.",
63+
},
64+
{
65+
object: "context",
66+
property: "getScope",
67+
message: "Please use `sourceCode.getScope(node)` instead.",
68+
},
69+
{
70+
object: "context",
71+
property: "parserServices",
72+
message: "Please use `sourceCode.parserServices` instead.",
73+
},
74+
],
4675

4776
// regexp next recommended
4877
"regexp/no-contradiction-with-assertion": "error",

lib/rules/match-any.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default createRule("match-any", {
5757
type: "suggestion", // "problem",
5858
},
5959
create(context) {
60-
const sourceCode = context.getSourceCode()
60+
const sourceCode = context.sourceCode
6161
const allowList: Allowed[] = context.options[0]?.allows ?? [
6262
OPTION_SS1,
6363
OPTION_DOTALL,

lib/rules/no-control-character.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default createRule("no-control-character", {
6666
// We are only interested in control escapes in RegExp literals
6767
const range = patternSource.getReplaceRange(char)?.range
6868
const sourceRaw = range
69-
? context.getSourceCode().text.slice(...range)
69+
? context.sourceCode.text.slice(...range)
7070
: char.raw
7171

7272
if (

lib/rules/no-invisible-character.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default createRule("no-invisible-character", {
2424
type: "suggestion", // "problem",
2525
},
2626
create(context) {
27-
const sourceCode = context.getSourceCode()
27+
const sourceCode = context.sourceCode
2828

2929
function createLiteralVisitor({
3030
node,

lib/rules/no-legacy-features.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export default createRule("no-legacy-features", {
9191
return {
9292
...(staticProperties.length
9393
? {
94-
Program() {
95-
const scope = context.getScope()
94+
Program(program) {
95+
const scope = context.sourceCode.getScope(program)
9696
const tracker = new ReferenceTracker(scope)
9797

9898
const regexpTraceMap: TYPES.TraceMap = {}

lib/rules/no-useless-dollar-replacements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default createRule("no-useless-dollar-replacements", {
4242
},
4343
create(context) {
4444
const typeTracer = createTypeTracker(context)
45-
const sourceCode = context.getSourceCode()
45+
const sourceCode = context.sourceCode
4646

4747
function verify(
4848
patternNode: Pattern | RegExpLiteral,

lib/rules/no-useless-flag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ function createRegExpReferenceExtractVisitor(
713713
* Create visitor for verify unnecessary flags of owned RegExp literals
714714
*/
715715
function createOwnedRegExpFlagsVisitor(context: Rule.RuleContext) {
716-
const sourceCode = context.getSourceCode()
716+
const sourceCode = context.sourceCode
717717

718718
/** Remove the flags of the given literal */
719719
function removeFlags(node: RegExpLiteral): void {

lib/rules/prefer-escape-replacement-dollar-char.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default createRule("prefer-escape-replacement-dollar-char", {
1919
},
2020
create(context) {
2121
const typeTracer = createTypeTracker(context)
22-
const sourceCode = context.getSourceCode()
22+
const sourceCode = context.sourceCode
2323

2424
function verify(replacement: Literal) {
2525
for (const element of parseReplacements(context, replacement)) {

lib/rules/prefer-named-replacement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default createRule("prefer-named-replacement", {
2626
},
2727
create(context) {
2828
const strictTypes = context.options[0]?.strictTypes ?? true
29-
const sourceCode = context.getSourceCode()
29+
const sourceCode = context.sourceCode
3030

3131
function createVisitor(
3232
regexpContext: RegExpContext,

0 commit comments

Comments
 (0)