Skip to content

Commit 9ab4084

Browse files
committed
fix
1 parent c9e326e commit 9ab4084

13 files changed

+49
-15
lines changed

lib/rules/array-bracket-newline.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export default createRule("array-bracket-newline", {
5858
},
5959
create(context) {
6060
const sourceCode = getSourceCode(context);
61+
if (!sourceCode.parserServices.isJSON) {
62+
return {};
63+
}
6164

6265
/**
6366
* Normalizes a given option value.

lib/rules/array-bracket-spacing.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ export default createRule("array-bracket-spacing", {
4949
},
5050
},
5151
create(context) {
52-
const spaced = context.options[0] === "always";
5352
const sourceCode = getSourceCode(context);
53+
if (!sourceCode.parserServices.isJSON) {
54+
return {};
55+
}
56+
const spaced = context.options[0] === "always";
5457
interface Schema1 {
5558
singleValue?: boolean;
5659
objectsInArrays?: boolean;

lib/rules/array-element-newline.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export default createRule("array-element-newline", {
8484
},
8585
create(context) {
8686
const sourceCode = getSourceCode(context);
87+
if (!sourceCode.parserServices.isJSON) {
88+
return {};
89+
}
8790

8891
/**
8992
* Normalizes a given option value.

lib/rules/comma-dangle.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ export default createRule("comma-dangle", {
9696
},
9797
},
9898
create(context) {
99-
const options = normalizeOptions(context.options[0] || "never");
100-
10199
const sourceCode = getSourceCode(context);
100+
if (!sourceCode.parserServices.isJSON) {
101+
return {};
102+
}
103+
const options = normalizeOptions(context.options[0] || "never");
102104

103105
/**
104106
* Gets the last item of the given node.

lib/rules/comma-style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ export default createRule("comma-style", {
5353
},
5454
},
5555
create(context) {
56-
const style = context.options[0] || "last";
5756
const sourceCode = getSourceCode(context);
57+
if (!sourceCode.parserServices.isJSON) {
58+
return {};
59+
}
60+
const style = context.options[0] || "last";
5861
const exceptions = {} as Record<AST.JSONNode["type"], boolean>;
5962

6063
if (

lib/rules/indent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ export default createRule("indent", {
593593
},
594594
},
595595
create(context) {
596+
const sourceCode = getSourceCode(context);
597+
if (!sourceCode.parserServices.isJSON) {
598+
return {};
599+
}
596600
const DEFAULT_VARIABLE_INDENT = 1;
597601
const DEFAULT_PARAMETER_INDENT = 1;
598602
const DEFAULT_FUNCTION_BODY_INDENT = 1;
@@ -657,7 +661,6 @@ export default createRule("indent", {
657661
}
658662
}
659663

660-
const sourceCode = getSourceCode(context);
661664
const tokenInfo = new TokenInfo(sourceCode);
662665
const offsets = new OffsetStorage(
663666
tokenInfo,

lib/rules/key-spacing.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ export default createRule("key-spacing", {
330330
},
331331
},
332332
create(context) {
333+
const sourceCode = getSourceCode(context);
334+
if (!sourceCode.parserServices.isJSON) {
335+
return {};
336+
}
333337
/**
334338
* OPTIONS
335339
* "key-spacing": [2, {
@@ -344,8 +348,6 @@ export default createRule("key-spacing", {
344348
const singleLineOptions = ruleOptions.singleLine;
345349
const alignmentOptions = ruleOptions.align || null;
346350

347-
const sourceCode = getSourceCode(context);
348-
349351
/**
350352
* Determines if the given property is key-value property.
351353
* @param property Property node to check.

lib/rules/object-curly-newline.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export default createRule("object-curly-newline", {
177177
},
178178
create(context) {
179179
const sourceCode = getSourceCode(context);
180+
if (!sourceCode.parserServices.isJSON) {
181+
return {};
182+
}
180183
const normalizedOptions = normalizeOptions(context.options[0]);
181184

182185
/**

lib/rules/object-curly-spacing.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ export default createRule("object-curly-spacing", {
4949
},
5050
},
5151
create(context) {
52-
const spaced = context.options[0] === "always";
5352
const sourceCode = getSourceCode(context);
53+
if (!sourceCode.parserServices.isJSON) {
54+
return {};
55+
}
56+
const spaced = context.options[0] === "always";
5457

5558
/**
5659
* Determines whether an option is set, relative to the spacing option.

lib/rules/object-property-newline.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export default createRule("object-property-newline", {
4040
},
4141
},
4242
create(context) {
43+
const sourceCode = getSourceCode(context);
44+
if (!sourceCode.parserServices.isJSON) {
45+
return {};
46+
}
4347
const allowSameLine =
4448
context.options[0] &&
4549
(context.options[0].allowAllPropertiesOnSameLine ||
@@ -48,8 +52,6 @@ export default createRule("object-property-newline", {
4852
? "propertiesOnNewlineAll"
4953
: "propertiesOnNewline";
5054

51-
const sourceCode = getSourceCode(context);
52-
5355
return {
5456
JSONObjectExpression(node) {
5557
if (allowSameLine) {

0 commit comments

Comments
 (0)