Skip to content

Commit a6c0bc9

Browse files
authored
fix: add type tests (#65)
1 parent 1fd0452 commit a6c0bc9

File tree

8 files changed

+54
-6
lines changed

8 files changed

+54
-6
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ jobs:
4545
run: npm install
4646
- name: Run tests
4747
run: npm run test
48+
test_types:
49+
name: Test Types
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Setup Node.js
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: "lts/*"
57+
- name: Install dependencies
58+
run: npm install
59+
- name: Build
60+
run: npm run build
61+
- name: Check Types
62+
run: npm run test:types
4863
jsr_test:
4964
name: Verify JSR Publish
5065
runs-on: ubuntu-latest

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"fmt": "prettier --write .",
5252
"fmt:check": "prettier --check .",
5353
"test": "mocha tests/**/*.js",
54-
"test:coverage": "c8 npm test"
54+
"test:coverage": "c8 npm test",
55+
"test:types": "tsc -p tests/types/tsconfig.json"
5556
},
5657
"keywords": [
5758
"eslint",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ const plugin = {
3535
configs: {
3636
recommended: {
3737
plugins: {},
38-
rules: {
38+
rules: /** @type {const} */ ({
3939
"json/no-duplicate-keys": "error",
4040
"json/no-empty-keys": "error",
4141
"json/no-unsafe-values": "error",
42-
},
42+
}),
4343
},
4444
},
4545
};

src/rules/no-duplicate-keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
export default {
1111
meta: {
12-
type: "problem",
12+
type: /** @type {const} */ ("problem"),
1313

1414
docs: {
1515
description: "Disallow duplicate keys in JSON objects",

src/rules/no-empty-keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
export default {
77
meta: {
8-
type: "problem",
8+
type: /** @type {const} */ ("problem"),
99

1010
docs: {
1111
description: "Disallow empty keys in JSON objects",

src/rules/no-unsafe-values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
export default {
77
meta: {
8-
type: "problem",
8+
type: /** @type {const} */ ("problem"),
99

1010
docs: {
1111
description: "Disallow JSON values that are unsafe for interchange",

tests/types/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"rootDir": "../..",
6+
"strict": true
7+
},
8+
"files": ["../../dist/esm/index.d.ts", "types.test.ts"]
9+
}

tests/types/types.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json from "@eslint/json";
2+
import { ESLint } from "eslint";
3+
4+
json satisfies ESLint.Plugin;
5+
json.meta.name satisfies string;
6+
json.meta.version satisfies string;
7+
8+
// Check that these languages are defined:
9+
json.languages.json satisfies object;
10+
json.languages.json5 satisfies object;
11+
json.languages.jsonc satisfies object;
12+
13+
// Check that `plugins` in the recommended config is defined:
14+
json.configs.recommended.plugins satisfies object;
15+
16+
{
17+
type RecommendedRuleName = keyof typeof json.configs.recommended.rules;
18+
type RuleName = `json/${keyof typeof json.rules}`;
19+
type AssertAllNamesIn<T1 extends T2, T2> = never;
20+
21+
// Check that all recommended rule names match the names of existing rules in this plugin.
22+
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
23+
}

0 commit comments

Comments
 (0)