Skip to content

Commit a416f0a

Browse files
fasttimenzakas
andauthored
chore: enable $ExpectType comments in .ts files (#18869)
* chore: enable `$ExpectType` comments in .ts files * Update eslint.config.js Co-authored-by: Nicholas C. Zakas <[email protected]> * ignore .ts files in lib/types --------- Co-authored-by: Nicholas C. Zakas <[email protected]>
1 parent adcc50d commit a416f0a

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

eslint.config.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const eslintConfigESLintCJS = require("eslint-config-eslint/cjs");
1818
const eslintConfigESLintFormatting = require("eslint-config-eslint/formatting");
1919
const eslintPluginYml = require("eslint-plugin-yml");
2020
const json = require("@eslint/json").default;
21+
const expectType = require("eslint-plugin-expect-type");
22+
const tsParser = require("@typescript-eslint/parser");
2123

2224
//-----------------------------------------------------------------------------
2325
// Helpers
@@ -87,14 +89,14 @@ module.exports = [
8789
"docs/!(src|tools)/",
8890
"docs/src/!(_data)",
8991
"jsdoc/**",
92+
"lib/types/**/*.ts",
9093
"templates/**",
9194
"tests/bench/**",
9295
"tests/fixtures/**",
9396
"tests/performance/**",
9497
"tmp/**",
9598
"**/test.js",
96-
".vscode",
97-
"**/*.ts"
99+
".vscode"
98100
]
99101
},
100102
{
@@ -279,5 +281,21 @@ module.exports = [
279281
...eslintPluginYml.configs["flat/recommended"].map(config => ({
280282
...config,
281283
files: [ALL_YAML_FILES]
282-
}))
284+
})),
285+
{
286+
name: "eslint/ts-rules",
287+
files: ["tests/lib/types/*.ts"],
288+
languageOptions: {
289+
parser: tsParser,
290+
parserOptions: {
291+
project: "tests/lib/types/tsconfig.json"
292+
}
293+
},
294+
plugins: {
295+
"expect-type": expectType
296+
},
297+
rules: {
298+
"expect-type/expect": "error"
299+
}
300+
}
283301
];

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"@types/estree": "^1.0.5",
122122
"@types/json-schema": "^7.0.15",
123123
"@types/node": "^20.11.5",
124+
"@typescript-eslint/parser": "^8.4.0",
124125
"@wdio/browser-runner": "^9.0.5",
125126
"@wdio/cli": "^9.0.5",
126127
"@wdio/concise-reporter": "^9.0.4",
@@ -135,6 +136,7 @@
135136
"eslint": "file:.",
136137
"eslint-config-eslint": "file:packages/eslint-config-eslint",
137138
"eslint-plugin-eslint-plugin": "^6.0.0",
139+
"eslint-plugin-expect-type": "^0.4.0",
138140
"eslint-plugin-yml": "^1.14.0",
139141
"eslint-release": "^3.2.2",
140142
"eslint-rule-composer": "^0.3.0",

tests/lib/types/types.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ loc.column; // $ExpectType number
105105
sourceCode.getIndexFromLoc({ line: 0, column: 0 });
106106

107107
sourceCode.getTokenByRangeStart(0); // $ExpectType Token | null
108-
sourceCode.getTokenByRangeStart(0, { includeComments: true }); // $ExpectType Comment | Token | null || Token | Comment | null
108+
sourceCode.getTokenByRangeStart(0, { includeComments: true }); // $ExpectType Comment | Token | null
109109
sourceCode.getTokenByRangeStart(0, { includeComments: false }); // $ExpectType Token | null
110-
sourceCode.getTokenByRangeStart(0, { includeComments: false as boolean }); // $ExpectType Comment | Token | null || Token | Comment | null
110+
sourceCode.getTokenByRangeStart(0, { includeComments: false as boolean }); // $ExpectType Comment | Token | null
111111

112112
sourceCode.getFirstToken(AST); // $ExpectType Token | null
113113
sourceCode.getFirstToken(AST, 0);
114114
sourceCode.getFirstToken(AST, { skip: 0 });
115115
sourceCode.getFirstToken(AST, (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier"); // $ExpectType (Token & { type: "Identifier"; }) | null
116116
sourceCode.getFirstToken(AST, { filter: (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier" }); // $ExpectType (Token & { type: "Identifier"; }) | null
117117
sourceCode.getFirstToken(AST, { skip: 0, filter: t => t.type === "Identifier" });
118-
sourceCode.getFirstToken(AST, { includeComments: true }); // $ExpectType Comment | Token | null || Token | Comment | null
118+
sourceCode.getFirstToken(AST, { includeComments: true }); // $ExpectType Comment | Token | null
119119
sourceCode.getFirstToken(AST, { includeComments: true, skip: 0 });
120120
// prettier-ignore
121121
sourceCode.getFirstToken(AST, { // $ExpectType (Token & { type: "Identifier"; }) | null
@@ -223,7 +223,7 @@ sourceCode.getFirstTokenBetween(AST, AST, {
223223
skip: 0,
224224
filter: (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier",
225225
});
226-
sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true }); // $ExpectType Comment | Token | null || Token | Comment | null
226+
sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true }); // $ExpectType Comment | Token | null
227227
sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true, skip: 0 });
228228
// prettier-ignore
229229
sourceCode.getFirstTokenBetween(AST, AST, { // $ExpectType (Token & { type: "Identifier"; }) | null
@@ -241,7 +241,7 @@ sourceCode.getFirstTokensBetween(AST, AST, { // $ExpectType (Token & { type: "Id
241241
filter: (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier",
242242
});
243243
sourceCode.getFirstTokensBetween(AST, AST, { count: 0, filter: t => t.type === "Identifier" });
244-
sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true }); // $ExpectType (Comment | Token)[] || (Token | Comment)[]
244+
sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true }); // $ExpectType (Comment | Token)[]
245245
sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true, count: 0 });
246246
// prettier-ignore
247247
sourceCode.getFirstTokensBetween(AST, AST, { // $ExpectType (Token & { type: "Identifier"; })[]
@@ -278,7 +278,7 @@ sourceCode.getTokens(AST, 0);
278278
sourceCode.getTokens(AST, 0, 0);
279279
sourceCode.getTokens(AST, (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier"); // $ExpectType (Token & { type: "Identifier"; })[]
280280
sourceCode.getTokens(AST, { filter: (t): t is AST.Token & { type: "Identifier" } => t.type === "Identifier" }); // $ExpectType (Token & { type: "Identifier"; })[]
281-
sourceCode.getTokens(AST, { includeComments: true }); // $ExpectType (Comment | Token)[] || (Token | Comment)[]
281+
sourceCode.getTokens(AST, { includeComments: true }); // $ExpectType (Comment | Token)[]
282282
// prettier-ignore
283283
sourceCode.getTokens(AST, { // $ExpectType (Token & { type: "Identifier"; })[]
284284
includeComments: true,

0 commit comments

Comments
 (0)