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
Add eslint-config package #168
Conversation
Deploying with Cloudflare Pages
|
npm install --save-dev @swim-io/eslint-config | ||
``` | ||
|
||
Install the required peer dependencies: |
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.
if we go for typescript only projects can't we include these as dependencies (and the typescript specific ones). Wouldn't that be more convenient?
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.
Unfortunately not (I went down several tunnels in this rabbit hole). First of all plugins and configs are treated very differently and get resolved differently. ESLint says this:
If your shareable config depends on a plugin, you should also specify it as a
peerDependency
(plugins will be loaded relative to the end user’s project, so the end user is required to install the plugins they need). However, if your shareable config depends on a third-party parser or another shareable config, you can specify these packages asdependencies
.
However, we can't actually do that with the prettier config because it's an optional dependency of eslint-plugin-prettier
: prettier/eslint-plugin-prettier#451. Which means we have to include it as a dependency of whatever loads the plugin if I understand correctly (also didn't get it to work any other way).
I also couldn't get the TS parser to work as a dependency, and I didn't work out why.
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 think they're working on changing all of this but this issue has been open since 2015: eslint/eslint#3458
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 have an example of a similar package we used in my previous job, see https://github.com/denis-sokolov/eslint-plugin/blob/master/package.json but I didn't set it up myself so I'm missing the little details
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.
But I see airbnb also lists that peer dependencies step https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb#eslint-config-airbnb-1
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 was somewhat helpful: https://zaicevas.com/blog/how-eslint-resolves-plugins-and-shareable-configs
It might well be that it's yarn that won't let us break the rules.
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.
What if we'll add postinstall
script that will automatically install peer dependencies?
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.
As of Yarn v2, Yarn won't run this automatically: https://yarnpkg.com/getting-started/migration#explicitly-call-the-pre-and-post-scripts
But that could be a good thing! I think it's also OK as it is, since we only need to add them once per package.
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.
Oh actually maybe it does do that for dependencies otherwise everything would probably break.
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.
Not sure this is even possible on reflection. The postinstall
script will run in the scope of the dependency, but we actually need to add them to the consuming package.
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.
What if we'll add a postinstall
script to that will install peer dependencies of @swim-io/eslint-config
? To package.json
in @swim-io/eslint-config
.
Just mentioning that there's a single ESLint config in Elastic Kibana. Kibana is probably the biggest open-source TypeScript monorepo.
npm install --save-dev @swim-io/eslint-config | ||
``` | ||
|
||
Install the required peer dependencies: |
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.
What if we'll add postinstall
script that will automatically install peer dependencies?
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.
LGTM 👍
Opening as a draft to get feedback before I add it to all the packages.This defines a default ESLint config for TS and an additional config for JS-only projects. The idea is we can then update ESLint rules in one place.
I'll add to the UI app in a separate PR because it will need to be published first.
Checklist