Skip to content
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

Merged
merged 6 commits into from Jul 7, 2022
Merged

Add eslint-config package #168

merged 6 commits into from Jul 7, 2022

Conversation

wormat
Copy link
Collaborator

@wormat wormat commented Jul 4, 2022

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

  • Github project and label have been assigned
  • Tests have been added or are unnecessary
  • Docs have been updated or are unnecessary
  • Preview deployment works (visit the Cloudflare preview URL)
  • Manual testing in #product-testing completed or unnecessary

@wormat wormat added internal CI settings, linting configuration, build process updates work in progress labels Jul 4, 2022
@cloudflare-pages
Copy link

cloudflare-pages bot commented Jul 4, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5058f53
Status: ✅  Deploy successful!
Preview URL: https://df7c112b.swim-ui.pages.dev
Branch Preview URL: https://sdk-eslint.swim-ui.pages.dev

View logs

packages/eslint-config/README.md Show resolved Hide resolved
npm install --save-dev @swim-io/eslint-config
```

Install the required peer dependencies:
Copy link
Contributor

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?

Copy link
Collaborator Author

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 as dependencies.

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.

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

@wormat wormat Jul 5, 2022

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@fisprak fisprak left a 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.

Same for Vue and Next.js.

npm install --save-dev @swim-io/eslint-config
```

Install the required peer dependencies:
Copy link
Contributor

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?

@wormat wormat marked this pull request as ready for review July 6, 2022 13:08
@wormat wormat requested review from nicomiicro and fisprak July 6, 2022 13:11
Copy link
Contributor

@nicomiicro nicomiicro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@wormat wormat merged commit fb100f7 into master Jul 7, 2022
@wormat wormat deleted the sdk/eslint branch July 7, 2022 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal CI settings, linting configuration, build process updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants