ESLint Flat Config (v9 support #2229) #2426

Merged
SomeAspy merged 3 commits from master into master 2024-09-19 12:19:42 +00:00
SomeAspy commented 2024-09-18 00:05:34 +00:00 (Migrated from github.com)

I have remade the config in ESLint's new format, as required by ESLint v9.

Major changes

  • ESLint Prettier plugin removed - there is no way to properly integrate prettier config into ESLint, unless you want to put the prettier config IN the eslint.config.mjs file - which I assume would break actual prettier formatters built into IDEs
  • ESLint v9 deprecated a ton of rules, these have moved into Stylistic which I have added.
  • Closes #2229

Other changes

  • Using my best judgement, I fixed 2 warnings only the new config generated
  1. src/plugins/precise-volume/override.ts Line 11:
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  1. src/plugins/synced-lyrics/renderer/lyrics/fetch.ts Line 19:
- // eslint-disable-next-line prefer-const
I have remade the config in ESLint's new format, as required by ESLint v9. ## Major changes - ESLint Prettier plugin removed - there is no way to properly integrate prettier config into ESLint, unless you want to put the prettier config IN the `eslint.config.mjs` file - which I assume would break actual prettier formatters built into IDEs - ESLint v9 deprecated a *ton* of rules, these have moved into [Stylistic](https://eslint.style/packages/default) which I have added. - Closes #2229 ## Other changes - Using my best judgement, I fixed 2 warnings only the new config generated 1. `src/plugins/precise-volume/override.ts` Line 11: ```diff - // eslint-disable-next-line @typescript-eslint/ban-ts-comment ``` 2. `src/plugins/synced-lyrics/renderer/lyrics/fetch.ts` Line 19: ```diff - // eslint-disable-next-line prefer-const ```
JellyBrick commented 2024-09-18 07:50:43 +00:00 (Migrated from github.com)

Could you convert .mjs to .mts?

Thanks for your contribution!

Could you convert `.mjs` to `.mts`? Thanks for your contribution!
SomeAspy commented 2024-09-18 19:03:39 +00:00 (Migrated from github.com)

I don't think that is possible
https://github.com/eslint/eslint/discussions/17726
image
Perhaps there is some roundabout convoluted way to do this, but I don't think it would be worth the effort when the //@ts-check directive effectively makes it a typescript file. https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html

I don't think that is possible https://github.com/eslint/eslint/discussions/17726 ![image](https://github.com/user-attachments/assets/af6f2655-671b-4b39-9ca6-24bb88e51527) Perhaps there is some roundabout convoluted way to do this, but I don't think it would be worth the effort when the `//@ts-check` directive effectively makes it a typescript file. https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html
SomeAspy commented 2024-09-18 19:04:35 +00:00 (Migrated from github.com)

actually, let me double check. https://github.com/eslint/rfcs/pull/117

actually, let me double check. https://github.com/eslint/rfcs/pull/117
SomeAspy commented 2024-09-18 20:48:32 +00:00 (Migrated from github.com)

@JellyBrick this is the conclusion I arrived at:
To parse config files, ESLint is hard coded to use Node (The possibility of using tsx was suggested in the ESLint RFC PR I mentioned earlier, but ultimately did not make it in)
However, Node recently added an experimental flag to strip types from TS files in 22.6.0 which means linting will not work on systems with one of the last 3 latest versions of Node - none of which are LTS (At time of writing)

Ignoring that, this lead me to
NODE_OPTIONS='--experimental-strip-types' pnpm run lint -c eslint.config.mts
However, this will not work on Windows because Windows requires setting environmental variables with a different command... which brings me to the latest iteration I've come up with
pnpm cross-env NODE_OPTIONS='--experimental-strip-types' eslint . -c eslint.config.mts"
broken down:

  • cross-env: PNPM integrated command that properly sets environmental variables, regardless of OS
  • NODE_OPTIONS: The Node environment variables, with the type stripping set.
  • eslint -c: Manually tells ESLint to use eslint.config.mts as ESLint does not auto-detect the config file with non-JS extensions

While it's ultimately up to you, as I have provided a working method, I don't think the complexity of the command is worth the effort, when compared to // @ts-check paired with .mjs, which gives you typescript linting and works out of the box, with the only pitfall being you cannot use typescript keywords (the most important being the as keyword or specifying types with :type There is an implentation for this in JS however, being JSDoc which most IDEs will grab information from properly

@JellyBrick this is the conclusion I arrived at: To parse config files, ESLint is hard coded to use Node (The possibility of using tsx was suggested in the ESLint RFC PR I mentioned earlier, but ultimately did not make it in) However, Node recently added an **experimental** flag to strip types from TS files [in 22.6.0](https://nodejs.org/en/blog/release/v22.6.0) which means linting will not work on systems with one of the last 3 latest versions of Node - none of which are LTS (At time of writing) Ignoring that, this lead me to `NODE_OPTIONS='--experimental-strip-types' pnpm run lint -c eslint.config.mts` However, this will not work on Windows because Windows requires setting environmental variables with a different command... which brings me to the latest iteration I've come up with `pnpm cross-env NODE_OPTIONS='--experimental-strip-types' eslint . -c eslint.config.mts"` broken down: - cross-env: PNPM integrated command that properly sets environmental variables, regardless of OS - NODE_OPTIONS: The Node environment variables, with the type stripping set. - eslint -c: Manually tells ESLint to use `eslint.config.mts` as ESLint does not auto-detect the config file with non-JS extensions While it's ultimately up to you, as I have provided a working method, I don't think the complexity of the command is worth the effort, when compared to `// @ts-check` paired with `.mjs`, which gives you typescript linting and works out of the box, with the only pitfall being you cannot use typescript keywords (the most important being the `as` keyword or specifying types with `:type` There is an implentation for this in JS however, being JSDoc which most IDEs will grab information from properly
JellyBrick commented 2024-09-18 22:22:47 +00:00 (Migrated from github.com)
@SomeAspy How about this? https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files
SomeAspy commented 2024-09-18 23:24:40 +00:00 (Migrated from github.com)

I think that would involve having eslint.config.mjs file point to eslint.config.mts, which seems to mostly defeat the purpose. Why do you want the eslint config to be TS?
I love typescript as much as the next guy, but I think having eslint.config.mjs point to eslint.config.mts seems like unnecessary clutter, although, I will oblige if you really want it.

I think that would involve having eslint.config.mjs file point to eslint.config.mts, which seems to mostly defeat the purpose. Why do you want the eslint config to be TS? I love typescript as much as the next guy, but I think having eslint.config.mjs point to eslint.config.mts seems like unnecessary clutter, although, I will oblige if you really want it.
JellyBrick (Migrated from github.com) approved these changes 2024-09-19 12:18:21 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: YTMD/youtube-music#2426
No description provided.