Skip to content

Commit

Permalink
fix: add type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Nov 21, 2024
1 parent 1fd0452 commit a0f47b4
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ jobs:
run: npm install
- name: Run tests
run: npm run test
test_types:
name: Test Types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Check Types
run: npm run test:types
jsr_test:
name: Verify JSR Publish
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"fmt": "prettier --write .",
"fmt:check": "prettier --check .",
"test": "mocha tests/**/*.js",
"test:coverage": "c8 npm test"
"test:coverage": "c8 npm test",
"test:types": "tsc -p tests/types/tsconfig.json"
},
"keywords": [
"eslint",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const plugin = {
configs: {
recommended: {
plugins: {},
rules: {
rules: /** @type {const} */ ({
"json/no-duplicate-keys": "error",
"json/no-empty-keys": "error",
"json/no-unsafe-values": "error",
},
}),
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-duplicate-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

export default {
meta: {
type: "problem",
type: /** @type {const} */ ("problem"),

docs: {
description: "Disallow duplicate keys in JSON objects",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-empty-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export default {
meta: {
type: "problem",
type: /** @type {const} */ ("problem"),

docs: {
description: "Disallow empty keys in JSON objects",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unsafe-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export default {
meta: {
type: "problem",
type: /** @type {const} */ ("problem"),

docs: {
description: "Disallow JSON values that are unsafe for interchange",
Expand Down
9 changes: 9 additions & 0 deletions tests/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"rootDir": "../..",
"strict": true
},
"files": ["../../dist/esm/index.d.ts", "types.test.ts"]
}
23 changes: 23 additions & 0 deletions tests/types/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json from "@eslint/json";
import { ESLint } from "eslint";

json satisfies ESLint.Plugin;
json.meta.name satisfies string;
json.meta.version satisfies string;

// Check that these languages are defined:
json.languages.json satisfies object;
json.languages.json5 satisfies object;
json.languages.jsonc satisfies object;

// Check that `plugins` in the recommended config is defined:
json.configs.recommended.plugins satisfies object;

{
type RecommendedRuleName = keyof typeof json.configs.recommended.rules;
type RuleName = `json/${keyof typeof json.rules}`;
type AssertAllNamesIn<T1 extends T2, T2> = never;

// Check that all recommended rule names match the names of existing rules in this plugin.
null as AssertAllNamesIn<RecommendedRuleName, RuleName>;
}

0 comments on commit a0f47b4

Please sign in to comment.