eslint-config-galex
eslint-config-galex copied to clipboard
JS/TS project migration
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?
great idea, yeah!
would need to extract:
- createPossibleErrorRules -> typescript
- createBestPractices -> typescript
- createVariableRules -> typescript
- createStylisticIssuesRules -> typescript, CRA, Next
- createES6Rules -> typescript
should be fixed with the next release, lmk :)
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).
ah I believe that actually just needs an additional flag, let me introduce that
should be fixed with enableJavaScriptSpecificRulesInTypeScriptProject in the next release I hope :) docs included https://github.com/ljosberinn/eslint-config-galex#features
I've just upgraded, and it works great, thanks a lot! :tada:
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: