Skip to content

Commit

Permalink
feat: support ESLint 9 and typescript-eslint 7 (#249)
Browse files Browse the repository at this point in the history
## PR Checklist

- [x] Addresses an existing open issue: fixes #142
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Adds an `eslint-plugin-expect-type/configs/recommended` export with the
new shape. Touches up the README.md to emphasize flat config over legacy
too.

Also prefers `context.filename` over `context.getFilename()` per
https://eslint.org/blog/2023/05/eslint-v8.40.0-released.
  • Loading branch information
JoshuaKGoldberg committed Mar 26, 2024
1 parent d8dbbec commit 039e3d8
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 74 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,31 @@ npm i -D eslint-plugin-expect-type
## Usage

Add the following options to your [ESLint configuration file](https://eslint.org/docs/latest/user-guide/configuring/configuration-files):
Add the following options to your [ESLint configuration file](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new):

```ts
import expectType from "eslint-plugin-expect-type/configs/recommended";

export default [
// your other ESLint configurations
expectType,
];
```

Then, you'll be able to use `^?`, `$ExpectError`, `$ExpectType`, and `$ExpectTypeSnapshot` comments in code assert on types.

### Usage (Legacy Config)

If you're still using the [legacy ESLint configuration file format](https://eslint.org/docs/latest/user-guide/configuring/configuration-files):

```json
{
"extends": ["plugin:expect-type/recommended"],
"plugins": ["eslint-plugin-expect-type"]
"plugins": ["expect-type"]
}
```

Then, you'll be able to use `^?`, `$ExpectError`, `$ExpectType`, and `$ExpectTypeSnapshot` comments in code assert on types.
## Rules

<!-- prettier-ignore-start -->
<!-- begin auto-generated rules list -->
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
},
"import": "./lib/index.mjs",
"require": "./lib/index.js"
},
"./configs/recommended": {
"types": {
"import": "./lib/configs/recommended.d.mts",
"require": "./lib/configs/recommended.d.ts"
},
"import": "./lib/configs/recommended.mjs",
"require": "./lib/configs/recommended.js"
}
},
"main": "./lib/index.js",
Expand Down Expand Up @@ -69,7 +77,7 @@
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"@typescript-eslint/utils": "^6.10.0",
"@typescript-eslint/utils": "^6.10.0 || ^7.0.1",
"fs-extra": "^11.1.1"
},
"devDependencies": {
Expand All @@ -78,9 +86,10 @@
"@types/eslint": "^8.44.7",
"@types/fs-extra": "^11.0.0",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@typescript-eslint/rule-tester": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@typescript-eslint/rule-tester": "^7.4.0",
"@typescript-eslint/utils": "^7.4.0",
"@vitest/coverage-v8": "^1.0.0",
"console-fail-test": "^0.2.3",
"cspell": "^8.0.0",
Expand Down
114 changes: 56 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { plugin, recommendedRuleSettings } from "../plugin.js";

const recommended = {
plugins: {
"expect-type": plugin,
},
rules: recommendedRuleSettings,
};

export default recommended;
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { rules } from "./rules/index.js";
import { recommendedRuleSettings } from "./plugin.js";

export { rules } from "./rules/index.js";

export const configs = {
recommended: {
rules: Object.keys(rules).reduce<Record<string, "error">>(
(acc, name) => ({ ...acc, [`expect-type/${name}`]: "error" as const }),
{},
),
plugins: ["expect-type"],
rules: recommendedRuleSettings,
},
};

0 comments on commit 039e3d8

Please sign in to comment.