Skip to content

Commit fdde59d

Browse files
committed
fix: Update types from @eslint/core
1 parent 90396b4 commit fdde59d

10 files changed

+51
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@humanwhocodes/momoa": "^3.3.3"
6868
},
6969
"devDependencies": {
70-
"@eslint/core": "^0.6.0",
70+
"@eslint/core": "^0.9.0",
7171
"@types/eslint": "^8.56.10",
7272
"c8": "^9.1.0",
7373
"dedent": "^1.5.3",

src/languages/json-language.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ import { visitorKeys } from "@humanwhocodes/momoa";
2121
/** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
2222
/** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
2323
/** @typedef {import("@eslint/core").File} File */
24-
/**
25-
* @typedef {Object} JSONLanguageOptions
26-
* @property {boolean} [allowTrailingCommas] Whether to allow trailing commas.
27-
*/
2824
/** @typedef {import("../types.ts").IJSONLanguage} IJSONLanguage */
25+
/** @typedef {import("../types.ts").JSONLanguageOptions} JSONLanguageOptions */
2926

3027
//-----------------------------------------------------------------------------
3128
// Exports

src/languages/json-source-code.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,6 @@ export class JSONSourceCode extends TextSourceCodeBase {
119119
: [];
120120
}
121121

122-
/* eslint-disable class-methods-use-this -- Required to complete interface. */
123-
124-
/**
125-
* Returns the loc information for the given node or token.
126-
* @param {JSONSyntaxElement} nodeOrToken The node or token to get the loc information for.
127-
* @returns {SourceLocation} The loc information for the node or token.
128-
*/
129-
getLoc(nodeOrToken) {
130-
return nodeOrToken.loc;
131-
}
132-
133-
/**
134-
* Returns the range information for the given node or token.
135-
* @param {JSONSyntaxElement} nodeOrToken The node or token to get the range information for.
136-
* @returns {SourceRange} The range information for the node or token.
137-
*/
138-
getRange(nodeOrToken) {
139-
return nodeOrToken.range;
140-
}
141-
142122
/**
143123
* Returns the value of the given comment.
144124
* @param {JSONToken} comment The comment to get the value of.
@@ -169,7 +149,7 @@ export class JSONSourceCode extends TextSourceCodeBase {
169149
);
170150
}
171151

172-
return this.#inlineConfigComments;
152+
return this.#inlineConfigComments ?? [];
173153
}
174154

175155
/**

src/rules/no-duplicate-keys.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
// Type Definitions
88
//-----------------------------------------------------------------------------
99

10-
/** @typedef {import("../types.ts").JSONRuleVisitor} JSONRuleVisitor */
11-
/** @typedef {import("../../../rewrite/packages/core/src/types.ts").RuleDefinition<JSONRuleVisitor>} RuleDefinition */
10+
/** @typedef {"duplicateKey"} NoDuplicateKeysMessageIds */
11+
/** @typedef {import("../types.ts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>} NoDuplicateKeysRuleDefinition */
1212

1313
//-----------------------------------------------------------------------------
1414
// Rule Definition
1515
//-----------------------------------------------------------------------------
1616

17-
/** @type {RuleDefinition} */
17+
/** @type {NoDuplicateKeysRuleDefinition} */
1818
export default {
1919
meta: {
20-
type: /** @type {const} */ ("problem"),
20+
type: "problem",
2121

2222
docs: {
2323
description: "Disallow duplicate keys in JSON objects",

src/rules/no-empty-keys.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
// Type Definitions
88
//-----------------------------------------------------------------------------
99

10-
/** @typedef {import("../types.ts").JSONRuleVisitor} JSONRuleVisitor */
11-
/** @typedef {import("../../../rewrite/packages/core/src/types.ts").RuleDefinition<JSONRuleVisitor>} RuleDefinition */
10+
/** @typedef {"emptyKey"} NoEmptyKeysMessageIds */
11+
/** @typedef {import("../types.ts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>} NoEmptyKeysRuleDefinition */
1212

1313
//-----------------------------------------------------------------------------
1414
// Rule Definition
1515
//-----------------------------------------------------------------------------
1616

17-
/** @type {RuleDefinition} */
17+
/** @type {NoEmptyKeysRuleDefinition} */
1818
export default {
1919
meta: {
20-
type: /** @type {const} */ ("problem"),
20+
type: "problem",
2121

2222
docs: {
2323
description: "Disallow empty keys in JSON objects",

src/rules/no-unsafe-values.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
* @author Bradley Meck Farias
44
*/
55

6+
//-----------------------------------------------------------------------------
7+
// Type Definitions
8+
//-----------------------------------------------------------------------------
9+
10+
/** @typedef {"unsafeNumber"|"loneSurrogate"} NoUnsafeValuesMessageIds */
11+
/** @typedef {import("../types.ts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>} NoUnsafeValuesRuleDefinition */
12+
13+
//-----------------------------------------------------------------------------
14+
// Rule Definition
15+
//-----------------------------------------------------------------------------
16+
17+
/** @type {NoUnsafeValuesRuleDefinition} */
618
export default {
719
meta: {
8-
type: /** @type {const} */ ("problem"),
20+
type: "problem",
921

1022
docs: {
1123
description: "Disallow JSON values that are unsafe for interchange",

src/types.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import type {
1111
RuleVisitor,
1212
TextSourceCode,
1313
Language,
14-
} from "../../rewrite/packages/core/src/types.ts";
14+
LanguageOptions,
15+
RuleDefinition,
16+
} from "@eslint/core";
1517
import {
1618
DocumentNode,
1719
MemberNode,
@@ -43,7 +45,12 @@ export type JSONSyntaxElement = Token | AnyNode;
4345
/**
4446
* Language options provided for JSON files.
4547
*/
46-
export type JSONLanguageOptions = Record<string, unknown>;
48+
export interface JSONLanguageOptions extends LanguageOptions {
49+
/**
50+
* Whether to allow trailing commas. Only valid in JSONC.
51+
*/
52+
allowTrailingCommas?: boolean;
53+
}
4754

4855
/**
4956
* The visitor format returned from rules in this package.
@@ -82,9 +89,8 @@ export interface JSONRuleVisitor extends RuleVisitor {
8289
export type IJSONSourceCode = TextSourceCode<{
8390
LangOptions: JSONLanguageOptions;
8491
RootNode: DocumentNode;
85-
Node: JSONSyntaxElement;
8692
SyntaxElementWithLoc: JSONSyntaxElement;
87-
ConfigNode: null;
93+
ConfigNode: Token;
8894
}>;
8995

9096
export type IJSONLanguage = Language<{
@@ -93,3 +99,16 @@ export type IJSONLanguage = Language<{
9399
RootNode: DocumentNode;
94100
Node: AnyNode;
95101
}>;
102+
103+
export type JSONRuleDefinition<
104+
JSONRuleOptions extends unknown[],
105+
JSONRuleMessageIds extends string = "",
106+
> = RuleDefinition<{
107+
LangOptions: JSONLanguageOptions;
108+
Code: IJSONSourceCode;
109+
RuleOptions: JSONRuleOptions;
110+
Visitor: JSONRuleVisitor;
111+
Node: AnyNode;
112+
MessageIds: JSONRuleMessageIds;
113+
ExtRuleDocs: {};
114+
}>;

tests/types/types.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json from "@eslint/json";
2-
import { ESLint } from "eslint";
2+
// import { ESLint } from "eslint";
33

4-
json satisfies ESLint.Plugin;
4+
// json satisfies ESLint.Plugin;
55
json.meta.name satisfies string;
66
json.meta.version satisfies string;
77

tools/dedupe-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ files.forEach(filePath => {
4242
// replace references to ../types.ts with types.ts
4343
const text = remainingLines
4444
.join("\n")
45-
.replace(/\.\.\/types\.ts/gu, "types.ts");
45+
.replace(/\.\.\/types\.ts/gu, "./types.ts");
4646

4747
fs.writeFileSync(filePath, text, "utf8");
4848
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"allowJs": true,
77
"checkJs": true,
88
"outDir": "dist/esm",
9-
"target": "ES2022",
9+
"target": "ESNext",
1010
"moduleResolution": "NodeNext",
1111
"module": "NodeNext",
1212
"allowImportingTsExtensions": true

0 commit comments

Comments
 (0)