8000 feat: add types for the `@eslint/js` package (#19010) · eslint/eslint@b0faee3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0faee3

Browse files
feat: add types for the @eslint/js package (#19010)
* feat: add types for `@eslint/js` package * fix: add eslint as a dependency for types * chore: add test for types * chore: add test for types * ci: fix path * chore: remove eslint dependency * chore: update knip & trunk configs * chore: update eslint.config.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 151c965 commit b0faee3

File tree

7 files changed

+118
-6
lines changed

7 files changed

+118
-6
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,8 @@ jobs:
123123
node-version: "lts/*"
124124
- name: Install Packages
125125
run: npm install
126-
- name: Test
126+
- name: Test eslint types
127+
run: npm run test:types
128+
- name: Test @eslint/js types
127129
run: npm run test:types
130+
working-directory: packages/js

eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ module.exports = [
292292
})),
293293
{
294294
name: "eslint/ts-rules",
295-
files: ["tests/lib/types/*.ts"],
295+
files: ["tests/lib/types/*.ts", "packages/**/*.{ts,mts,cts,tsx}"],
296296
languageOptions: {
297297
parser: tsParser,
298298
parserOptions: {
299-
project: "tests/lib/types/tsconfig.json"
299+
project: ["tests/lib/types/tsconfig.json", "packages/js/tests/types/tsconfig.json"]
300300
}
301301
},
302302
plugins: {

knip.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"ignore": ["src/assets/js/search.js", "_examples/**"]
3535
},
3636
// Workspaces with default configs:
37-
"packages/*": {},
37+
"packages/*": {
38+
"ignore": ["tests/types/**"]
39+
},
3840
"tools/internal-rules": {}
3941
}
4042
}

packages/js/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
"version": "9.13.0",
44
"description": "ESLint JavaScript language implementation",
55
"main": "./src/index.js",
6-
"scripts": {},
6+
"types": "./types/index.d.ts",
7+
"scripts": {
8+
"test:types": "tsc -p tests/types/tsconfig.json"
9+
},
710
"files": [
811
"LICENSE",
912
"README.md",
10-
"src"
13+
"src",
14+
"types"
1115
],
1216
"publishConfig": {
1317
"access": "public"

packages/js/tests/types/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"dom",
6+
"es6"
7+
],
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictNullChecks": true,
11+
"strictFunctionTypes": true,
12+
"types": [],
13+
"noEmit": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"exactOptionalPropertyTypes": true
16+
},
17+
"files": [
18+
"../../types/index.d.ts",
19+
"types.test.ts"
20+
]
21+
}

packages/js/tests/types/types.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @fileoverview This file contains code intended to test our types.
3+
* It was initially extracted from the `@types/eslint__js` package.
4+
*/
5+
6+
/*
7+
* MIT License
8+
* Copyright (c) Microsoft Corporation.
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE
26+
*/
27+
28+
import type { Linter } from "eslint";
29+
import js from "../../";
30+
31+
let config: Linter.Config[];
32+
33+
config = [js.configs.recommended];
34+
35+
config = [js.configs.all];
36+
37+
config = [js.configs.recommended, js.configs.all];
38+
39+
config = [
40+
{
41+
...js.configs.recommended,
42+
files: ["blah"],
43+
},
44+
{
45+
...js.configs.all,
46+
files: ["meh"],
47+
},
48+
{
49+
files: ["foo"],
50+
},
51+
];
52+
53+
config = [
54+
{
55+
files: ["**/*.js"],
56+
rules: js.configs.recommended.rules,
57+
},
58+
{
59+
files: ["**/*.js"],
60+
rules: {
61+
...js.configs.recommended.rules,
62+
"no-unused-vars": "warn",
63+
},
64+
},
65+
{
66+
files: ["**/*.js"],
67+
rules: {
68+
...js.configs.all.rules,
69+
"no-unused-vars": "warn",
70+
},
71+
},
72+
];

packages/js/types/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Linter } from "eslint";
2+
3+
declare const js: {
4+
readonly configs: {
5+
readonly recommended: { readonly rules: Readonly<Linter.RulesRecord> };
6+
readonly all: { readonly rules: Readonly<Linter.RulesRecord> };
7+
};
8+
};
9+
10+
export = js;

0 commit comments

Comments
 (0)
0