Skip to content

Commit

Permalink
fix: make recommended config a valid flat config (#462)
Browse files Browse the repository at this point in the history
<!-- 👋 Hi, thanks for sending a PR to eslint-plugin-expect-type! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## 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

<!-- Description of what is changed and how the code change does that.
-->

This PR updates the `recommended` config to make it a valid flat config.
Currently, the `recommended` config's `plugins` field is an array, and
thus this config cannot be used in flat mode, where `plugins` is
expected to be an object.

It looks like the readme file already contains instructions for
embedding the `recommended` config in a flat config file, but the
`recommended` config itself hasn't been updated yet.

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

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

I noticed this problem while working on eslint/eslint#18869.
  • Loading branch information
fasttime committed Sep 9, 2024
1 parent cd24682 commit 3e89c46
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { recommendedRuleSettings } from "./plugin.js";
import { plugin, recommendedRuleSettings } from "./plugin.js";

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

export const configs = {
recommended: {
plugins: ["expect-type"],
plugins: {
"expect-type": plugin,
},
rules: recommendedRuleSettings,
},
};
20 changes: 0 additions & 20 deletions src/rules/twoslash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,6 @@ import { filename, ruleTester } from "./ruleTester.js";

ruleTester.run("expect", expect, {

Check failure on line 6 in src/rules/twoslash.test.ts

View workflow job for this annotation

GitHub Actions / type_check

Argument of type 'import("/home/runner/work/eslint-plugin-expect-type/eslint-plugin-expect-type/node_modules/.pnpm/@typescript-eslint+utils@7.14.1_eslint@8.57.0_typescript@5.5.2/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"ExpectedErrorNotFound" | "FileIsNotIncludedInTSConfig" | "Multiple$ExpectTypeAssertio...' is not assignable to parameter of type 'import("/home/runner/work/eslint-plugin-expect-type/eslint-plugin-expect-type/node_modules/.pnpm/@typescript-eslint+utils@7.11.0_eslint@8.57.0_typescript@5.5.2/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"ExpectedErrorNotFound" | "FileIsNotIncludedInTSConfig" | "Multiple$ExpectTypeAssertio...'.
invalid: [
{
code: dedent`
const square = (x: number) => x * x;
const four = square(2);
// ^? const four: string
`,
errors: [
{
column: 7,
line: 2,
messageId: "TypesDoNotMatch",
},
],
filename,
output: dedent`
const square = (x: number) => x * x;
const four = square(2);
// ^? const four: number
`,
},
// Offers a fix for an empty assertion (the usual starting point)
{
code: dedent`
Expand Down
7 changes: 2 additions & 5 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export type SetRequiredNonNullable<
BaseType,
Keys extends keyof BaseType,
> = Omit<BaseType, Keys> & {
export type SetRequiredNonNullable<BaseType, Keys extends keyof BaseType> = {
[K in Keys]: NonNullable<BaseType[K]>;
};
} & Omit<BaseType, Keys>;

0 comments on commit 3e89c46

Please sign in to comment.