-
Notifications
You must be signed in to change notification settings - Fork 19
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
Replace Galex ESLint config #1726
base: main
Are you sure you want to change the base?
Conversation
.eslintignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with a config object in each project's eslint.config.js
file.
apps/demo/eslint.config.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typical entrypoint for a project: it includes detection of dependencies, creation of the base config, and configuration of files to ignore.
} = { ...DEFAULT_OPTS, ...opts }; | ||
|
||
return tseslint.config( | ||
_.compact([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lodash's compact
utility allows passing withTypeScript && { ... }
into the array instead of ...(withTypeScript ? [{ ... }] : [])
.
'error', | ||
{ checkForEach: true }, // enforce no return in `forEach` | ||
], | ||
// 'arrow-body-style': 'off', // use of curly braces in arrow functions should first be dictated by readabillity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I declare every single rule explicitly so there are no surprises. I keep those that are disabled commented to not pollute the display when inspecting the config with pnpm --filter @h5web/shared lint:eslint --inspect-config
or the like.
withTypeScript && { | ||
/** | ||
* TypeScript plugin: https://typescript-eslint.io/rules/ | ||
* Use both `strictTypeChecked` and stylisticTypeChecked` configs, and then tweak. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typescript-eslint
is the only plugin for which I use the built-in configs and then tweak the rules (instead of declaring every single rule). There are just too many of them and most are enabled anyway.
const matches = regex.exec(base); | ||
|
||
if (!matches) { | ||
throw new Error(`Unrecognized base ${base}`); | ||
} | ||
|
||
const [, sign, sizeStr, h5tOrderStr] = matches; | ||
const size = Number.parseInt(sizeStr, 10); | ||
const size = Number.parseInt(sizeStr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this also enforced by a ESLint rule ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it was https://github.com/ljosberinn/eslint-config-galex/blob/1792b61043d9f8e5c08be924f6a999318cfc2cf1/src/plugins/eslint-core.ts#L1176
I've been enforcing this myself thinking it was still relevant. Well, there's still the case that, without a radix specified, the 0x
prefix parses the string as hexadecimal. For a user-provided input (e.g. the domain bounds in the domain widget), this might not be what we're after... but then maybe it is (or at least doesn't matter).
if (scaleType !== ScaleType.Log) { | ||
return formatTick; | ||
} | ||
|
||
// If available size allows for all log ticks to be rendered without overlap, use default formatter | ||
const [min, max] = domain[0] > 0 ? domain : [-domain[1], -[domain[0]]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it. Weird it wasn't picked up by TS
Galex is no longer maintained, unfortunately, notably because of the transition to ESLint 9's flat config format. Being dependent on it was starting to cause issues, notably with TypeScript.
Having not found a suitable replacement, I've decided to write my own config, in the hope that we can later use it in other projects at the ESRF.
eslint.config.js
instead of.eslintrc.cjs
) inside each project + at the root.eslint-plugin-tailwindcss
and@next/eslint-plugin-next
are dropped, obviouslyeslint-plugin-etc
is dropped as it doesn't support ESLint 9 and is not actively maintainedeslint-plugin-sonarjs
is dropped because most of the rules are either very opinionated/stylistic or duplicate core ESLint rules and rules from other plugins (like the new regexp plugin below)eslint-config-prettier
is dropped because I prefer to be careful not to enable stylistic rules that may conflict with Prettier myself (this is made a lot easier by the fact that stylistic rules are no longer part of the core ESLint package)eslint-plugin-jest
and related plugins are replaced witheslint-plugin-vitest
eslint-plugin-regexp
is added to properly lint regular expressions@stylistic/eslint-plugin-js
is added for one specific stylistic rule not enforced by Prettier:spaced-comment
.js
files use ESM (i.e. thatpackage.json
has"type": "module"
).As you'll see with the many changes in the source code, the new config is a little stricter. I'll try to explain what's going on a bit more with some comments.