Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable @typescript-eslint/recommended-type-checked in create-next-app --typescript #52845

Open
wants to merge 17 commits into
base: canary
Choose a base branch
from

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Jul 18, 2023

Fixes #37151.

This differs a bit from the discussed approach for simplicity's sake now that typescript-eslint v6 is out. I started inline comments. This takes the approach suggested in the discussion of adding a next/typescript linter preset.

Also applies a small refactor to how the strict config is found from the prompt values. Instead of a .find, I extracted out the specific value into its own function.

@ijjk ijjk added create-next-app Related to our CLI tool for quickly starting a new Next.js application. area: documentation examples Issue/PR related to examples type: next labels Jul 18, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title feat: enable @typescript-eslint/recommended internally and -type-chec… feat: enable @typescript-eslint/recommended and stylistic in create-next-app --typescript Jul 20, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title feat: enable @typescript-eslint/recommended and stylistic in create-next-app --typescript feat: enable @typescript-eslint/recommended in create-next-app --typescript Jul 20, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title feat: enable @typescript-eslint/recommended in create-next-app --typescript feat: enable @typescript-eslint/recommended-type-checked in create-next-app --typescript Jul 20, 2023
@JoshuaKGoldberg JoshuaKGoldberg force-pushed the enable-typescript-eslint-recommended branch from d04e5aa to 6c62e53 Compare July 20, 2023 15:39
@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review July 20, 2023 15:47
ijjk pushed a commit that referenced this pull request Jul 31, 2023
…nternally (#52948)

Spinning out from #37151 and my draft PR #52845, this enables the two
basic recommended rulesets from
[typescript-eslint](https://typescript-eslint.io) for the Next.js
monorepo source code:

*
[`plugin:@typescript-eslint/recommended`](https://typescript-eslint.io/linting/configs#recommended):
Our base recommended rules that detect common bugs or _(non-stylistic)_
TypeScript bad practices
*
[`plugin:@typescript-eslint/stylistic`](https://typescript-eslint.io/linting/configs#stylistic):
Our base starting stylistic recommended for keeping codebases visually
consistent and avoiding out-of-practice visual constructs

The process I used is pretty standard (see
typescript-eslint/typescript-eslint#6760 for
other repos it was done on):

1. Enable those base recommended presets
2. Remove any rule settings that are now redundant
3. Reconfigure any rule whose default settings didn't seem to make sense
for this codebase
4. Add a `// Todo: ...` comment, and under it, add a disable for any
rule that immediately reported a lot of complaints

Note that this only enables the presets internally. It doesn't impact
what end-users of published packages such as Next.js or
`create-next-app` experience. That's a separate task in #52845.

I also didn't fix any existing warning from the `canary` branch. Would
you like me to do that? My preference would be a separate PR to get it
in more quickly.

Any code changes are commented inline.

---------

Co-authored-by: Steven <steven@ceriously.com>
@JoshuaKGoldberg
Copy link
Contributor Author

Ping ... hmm, @ijjk? Sorry I don't know who to bug here 😅. But other than some mysterious build failures after merging the latest canary yesterday and today I think this is still ready for review?

expect(eslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
expect(eslintrcJson).toMatchObject({
extends: ['next/core-web-vitals', 'next/typescript'],
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing any tests here?

For example, the linked issue mentions that it catches floating promises so perhaps we need a test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall ever seeing a project add explicit tests for particular lint rules being enabled. It's an interesting idea though.

Generally, the presence of something like next/typescript in the extends of an ESLint config has been considered enough. This is essentially a hasBeenCalledWith for the ESLint API.

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would be a breaking change for next lint so we'll need to consider this semver-major.

@JoshuaKGoldberg
Copy link
Contributor Author

👋 ping @styfle, is there anything I should do to be useful here?

@@ -7450,6 +7521,25 @@ packages:
- typescript
dev: true

/@typescript-eslint/utils@6.14.0(eslint@8.31.0)(typescript@4.8.2):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is duplicated with a 5.x version of @typescript-eslint/utils because eslint-plugin-jest still relies on @typescript-eslint/utils@5.

@samcx samcx removed the CI approved Approve running CI for fork label Mar 9, 2024
@JoshuaKGoldberg JoshuaKGoldberg force-pushed the enable-typescript-eslint-recommended branch from 288262b to a509c64 Compare March 25, 2024 16:53
@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented Mar 25, 2024

👋 @styfle / anybody, is there anything you're waiting for on my end to review? Resolving these merge conflicts takes up time for me and I'm unclear on whether & when this will be re-reviewed.

Edit: the force push is from me trying to resolve merge conflicts, messing up the pnpm-lock.yaml horrifically, and then force-pushing a revert back to the old commit.

@balazsorban44 balazsorban44 added Documentation Related to Next.js' official documentation. and removed area: documentation labels Apr 17, 2024
@eps1lon
Copy link
Member

eps1lon commented May 2, 2024

Last time I used lint rules using typechecking, it made ESLint horribly slow. Is ESLint report still blocked on the slowest rule or is in-editor linting streaming in results as rules are checked?

Typechecking performance is a big problem in non-trivial apps. Do you have some linting benchmarks (CLI and in-editor) on non-trivial apps?

To reduce the blast radius, we could also make type-checked rules opt-in.

@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented May 2, 2024

@eps1lon you're right, ESLint is still blocked on the slowest rule - as (a) it wouldn't be able to produce reports for a file until all the file's rules are done, and (b) some rules spookily modify state depended upon by other rules (😬).

typescript-eslint v8 will have a set of performance improvements (typescript-eslint/typescript-eslint#8922) & configuration streamlining (typescript-eslint/typescript-eslint#8031), but [typed linting] will still be orders of magnitude slower than traditional linting. It'll still be blocked on roughly the speed of TypeScript type checking in the common case, assuming the project hasn't misconfigured anything.

I do plan on setting up performance comparisons but first up will be getting typescript-eslint@v8 in user testing (typescript-eslint/typescript-eslint#9022). We can expect the comparisons middle to end of this summer, roughly.

I like the idea of starting with just the recommended config, and then later considering adding in an opt-in for typed linting. I won't be able to implement it this month but if nobody has updated this PR for me or sent a new one by June, I can. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application. Documentation Related to Next.js' official documentation. examples Issue/PR related to examples tests type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants