Skip to content

Commit 8d503dd

Browse files
authored
feat: use eslint-compat-utils (#265)
1 parent 19501c6 commit 8d503dd

32 files changed

+153
-153
lines changed

.changeset/proud-cameras-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-jsonc": minor
3+
---
4+
5+
feat: use eslint-compat-utils

.eslintrc.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,57 @@ module.exports = {
3838
],
3939
},
4040
],
41+
"no-restricted-properties": [
42+
"error",
43+
{
44+
object: "context",
45+
property: "getSourceCode",
46+
message:
47+
"Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.",
48+
},
49+
{
50+
object: "context",
51+
property: "sourceCode",
52+
message:
53+
"Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.",
54+
},
55+
{
56+
object: "context",
57+
property: "getFilename",
58+
message:
59+
"Please use `eslint-compat-utils` module's `getFilename(context)` instead.",
60+
},
61+
{
62+
object: "context",
63+
property: "filename",
64+
message:
65+
"Please use `eslint-compat-utils` module's `getFilename(context)` instead.",
66+
},
67+
{
68+
object: "context",
69+
property: "getCwd",
70+
message:
71+
"Please use `eslint-compat-utils` module's `getCwd(context)` instead.",
72+
},
73+
{
74+
object: "context",
75+
property: "cwd",
76+
message:
77+
"Please use `eslint-compat-utils` module's `getCwd(context)` instead.",
78+
},
79+
{
80+
object: "context",
81+
property: "getScope",
82+
message:
83+
"Please use `eslint-compat-utils` module's `getSourceCode(context).getScope()` instead.",
84+
},
85+
{
86+
object: "context",
87+
property: "parserServices",
88+
message:
89+
"Please use `eslint-compat-utils` module's `getSourceCode(context).parserServices` instead.",
90+
},
91+
],
4192
},
4293
overrides: [
4394
{

lib/rules/auto.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getFilename, getSourceCode } from "eslint-compat-utils";
12
import type { RuleListener, RuleModule } from "../types";
23
import { createRule } from "../utils";
34
import { getAutoConfig } from "../utils/get-auto-jsonc-rules-config";
@@ -17,10 +18,11 @@ export default createRule("auto", {
1718
type: "suggestion",
1819
},
1920
create(context, params) {
20-
if (!context.parserServices.isJSON) {
21+
const sourceCode = getSourceCode(context);
22+
if (!sourceCode.parserServices.isJSON) {
2123
return {};
2224
}
23-
const autoConfig = getAutoConfig(context.getFilename());
25+
const autoConfig = getAutoConfig(getFilename(context));
2426

2527
const visitor: RuleListener = {};
2628
for (const ruleId of Object.keys(autoConfig)) {

lib/rules/key-name-casing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { AST } from "jsonc-eslint-parser";
2-
import type { RuleListener } from "../types";
32
import { createRule } from "../utils";
43
import type { CasingKind } from "../utils/casing";
54
import { getChecker, allowedCaseOptions } from "../utils/casing";
5+
import { getSourceCode } from "eslint-compat-utils";
66

77
type Option = {
88
[key in CasingKind]?: boolean;
@@ -61,10 +61,10 @@ export default createRule("key-name-casing", {
6161
type: "suggestion",
6262
},
6363
create(context) {
64-
if (!context.parserServices.isJSON) {
65-
return {} as RuleListener;
64+
const sourceCode = getSourceCode(context);
65+
if (!sourceCode.parserServices.isJSON) {
66+
return {};
6667
}
67-
const sourceCode = context.getSourceCode();
6868
const option: Option = { ...context.options[0] };
6969
if (option.camelCase !== false) {
7070
option.camelCase = true;

lib/rules/no-bigint-literals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AST } from "jsonc-eslint-parser";
22
import { createRule } from "../utils";
3+
import { getSourceCode } from "eslint-compat-utils";
34

45
export default createRule("no-bigint-literals", {
56
meta: {
@@ -16,7 +17,8 @@ export default createRule("no-bigint-literals", {
1617
type: "problem",
1718
},
1819
create(context) {
19-
if (!context.parserServices.isJSON) {
20+
const sourceCode = getSourceCode(context);
21+
if (!sourceCode.parserServices.isJSON) {
2022
return {};
2123
}
2224
return {

lib/rules/no-binary-expression.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { AST } from "jsonc-eslint-parser";
22
import { getStaticJSONValue } from "jsonc-eslint-parser";
33
import { createRule } from "../utils";
4+
import { getSourceCode } from "eslint-compat-utils";
45

56
export default createRule("no-binary-expression", {
67
meta: {
@@ -19,7 +20,8 @@ export default createRule("no-binary-expression", {
1920
type: "problem",
2021
},
2122
create(context) {
22-
if (!context.parserServices.isJSON) {
23+
const sourceCode = getSourceCode(context);
24+
if (!sourceCode.parserServices.isJSON) {
2325
return {};
2426
}
2527

lib/rules/no-binary-numeric-literals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AST } from "jsonc-eslint-parser";
22
import { createRule } from "../utils";
3+
import { getSourceCode } from "eslint-compat-utils";
34

45
const binaryNumericLiteralPattern = /^0[Bb]/u;
56

@@ -19,7 +20,8 @@ export default createRule("no-binary-numeric-literals", {
1920
type: "problem",
2021
},
2122
create(context) {
22-
if (!context.parserServices.isJSON) {
23+
const sourceCode = getSourceCode(context);
24+
if (!sourceCode.parserServices.isJSON) {
2325
return {};
2426
}
2527
return {

lib/rules/no-comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RuleListener } from "../types";
1+
import { getSourceCode } from "eslint-compat-utils";
22
import { createRule } from "../utils";
33

44
export default createRule("no-comments", {
@@ -16,10 +16,10 @@ export default createRule("no-comments", {
1616
type: "problem",
1717
},
1818
create(context) {
19-
if (!context.parserServices.isJSON) {
20-
return {} as RuleListener;
19+
const sourceCode = getSourceCode(context);
20+
if (!sourceCode.parserServices.isJSON) {
21+
return {};
2122
}
22-
const sourceCode = context.getSourceCode();
2323
return {
2424
Program() {
2525
for (const comment of sourceCode.getAllComments()) {

lib/rules/no-escape-sequence-in-identifier.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { AST } from "jsonc-eslint-parser";
22
import { createRule } from "../utils";
33
import { PatternMatcher } from "@eslint-community/eslint-utils";
4+
import { getSourceCode } from "eslint-compat-utils";
45

56
export default createRule("no-escape-sequence-in-identifier", {
67
meta: {
@@ -18,10 +19,10 @@ export default createRule("no-escape-sequence-in-identifier", {
1819
type: "problem",
1920
},
2021
create(context) {
21-
if (!context.parserServices.isJSON) {
22+
const sourceCode = getSourceCode(context);
23+
if (!sourceCode.parserServices.isJSON) {
2224
return {};
2325
}
24-
const sourceCode = context.getSourceCode();
2526
return {
2627
JSONIdentifier(node: AST.JSONIdentifier) {
2728
verify(node);

lib/rules/no-hexadecimal-numeric-literals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AST } from "jsonc-eslint-parser";
22
import { createRule } from "../utils";
3+
import { getSourceCode } from "eslint-compat-utils";
34

45
const hexadecimalNumericLiteralPattern = /^0[Xx]/u;
56

@@ -19,7 +20,8 @@ export default createRule("no-hexadecimal-numeric-literals", {
1920
type: "problem",
2021
},
2122
create(context) {
22-
if (!context.parserServices.isJSON) {
23+
const sourceCode = getSourceCode(context);
24+
if (!sourceCode.parserServices.isJSON) {
2325
return {};
2426
}
2527
return {

0 commit comments

Comments
 (0)