مقالاتي
One lint config for every repo
Why I moved every repo onto one shared ESLint config and one small utility package, and what each of them holds.
نُشر
مدة القراءة
دقيقتان
المقال
Ok so, every new repo of mine used to start the same way, copy the ESLint config from the last one, tweak it, forget about the tweak, and repeat, until all of my configs had drifted apart and no two repos agreed on anything. So I stopped copying, and published the config instead.
The config
@eoussama/dx is my ESLint setup as a package. It’s built on top of Anthony Fu’s @antfu/eslint-config, which already gets most things right, with my own rules sitting on top, and it also handles formatting through ESLint’s stylistic rules, so there’s no separate Prettier config to keep in sync with the linter (one less thing to fight with).
A repo now needs one dependency and a short config file, and when I change a rule, every repo picks it up on its next update, so the argument about that rule happens once, not once per project.
The CLI
The package also ships a small dx command, dx lint lints, dx lint --fix applies whatever can be fixed automatically, and dx init writes the config file into a new repo. It’s not much, I know, but it means every repo exposes the same scripts, and I never have to remember how a given project wants to be linted.
The core
@eoussama/core is the other half, it’s the helpers I kept rewriting in every single project. At the center of it is tryCatch, which returns [error, data] instead of throwing:
const [error, user] = await tryCatch(() => fetchUser(id));
if (error) {
return null;
}
It’s basically Go’s way of handling errors, brought over to TypeScript, errors are values you handle right where they happen, not something that might fly past three functions before anyone notices. Around it sit a few small ones so far, wait for a pause, isPromise to tell a promise from a value, and the types they share, with no dependencies.
The trade-off
Shared config means shared opinions, a rule that annoys me in one repo now annoys me in all of them, and the fix is a release, not a quick edit.
Both dx and core are on npm (opens in a new tab) and GitHub (opens in a new tab) if you want to take a look.
التالي
A business card in your terminalأوكل مقالاتي (21)أوصفحة عشوائيةأوالرئيسية