eslint-config-galex icon indicating copy to clipboard operation
eslint-config-galex copied to clipboard

JS/TS project migration

Open axelboc opened this issue 3 years ago • 1 comments

I'm currently working on a project with a lot of legacy JS code. We're slowly converting JS files to TS, but it's gonna take a while.

I've noticed that some typical linting problems, like undeclared variables (no-undef), are not reported. It seems to be because of ternaries like this one: https://github.com/ljosberinn/eslint-config-galex/blob/master/src/plugins/eslint-core.ts#L1057

The project does have TypeScript, but we can't enable checkJs in tsconfig.json at this point, as this would be a nightmare. So we basically have legacy JS files that aren't fully linted.

Perhaps a better approach for galex would be to move all those core ESLint rules that are shadowed by equivalent TypeScript rules into a JS-only override (*.{js,jsx}) and to enable them only if typescript is installed and checkJs is enabled?

axelboc avatar Jul 29 '22 08:07 axelboc

great idea, yeah!

would need to extract:

  • createPossibleErrorRules -> typescript
  • createBestPractices -> typescript
  • createVariableRules -> typescript
  • createStylisticIssuesRules -> typescript, CRA, Next
  • createES6Rules -> typescript

ljosberinn avatar Jul 29 '22 13:07 ljosberinn

should be fixed with the next release, lmk :)

ljosberinn avatar Aug 07 '22 15:08 ljosberinn

Hmm, it seems that the new behaviour is not quite what I expected since my JS files are still not fully linted. They do get fully linted if I enable checkJs, but as mentioned, this is not doable in my project.

The error is mine: checkJs has nothing to do with the issue at hand. Obviously, ESLint only cares about the *.ts glob! It doesn't magically apply the TS override to JS files when checkJs is enabled... Silly me! 😓

So I think the solution is for the new override that disables rules with TS equivalents to only ever apply to TS files -- never to JS files, regardless of checkJs.

If this leads to too many errors in a legacy project, then this is a good use case for your incrementalAdoption feature (which I haven't had time to look into yet but sounds very promising).

axelboc avatar Aug 08 '22 10:08 axelboc

ah I believe that actually just needs an additional flag, let me introduce that

ljosberinn avatar Aug 08 '22 17:08 ljosberinn

should be fixed with enableJavaScriptSpecificRulesInTypeScriptProject in the next release I hope :) docs included https://github.com/ljosberinn/eslint-config-galex#features

ljosberinn avatar Aug 08 '22 18:08 ljosberinn

I've just upgraded, and it works great, thanks a lot! :tada:

axelboc avatar Aug 10 '22 07:08 axelboc

As a side benefit, it now also fully lints all the .eslintrc.js, vite.config.js and other jest.config.js files in my monorepo :smile:

axelboc avatar Aug 10 '22 07:08 axelboc