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 to project #715

Merged
merged 3 commits into from
Oct 28, 2021
Merged

Add eslint to project #715

merged 3 commits into from
Oct 28, 2021

Conversation

kpodsiad
Copy link
Member

@kpodsiad kpodsiad commented Sep 30, 2021

todo

  • use prettier for formatting rules (e.g. quotes)
  • setup CI check
  • add extensions.json with recommended extensions

.eslintrc.js Outdated Show resolved Hide resolved
Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Thanks @kpodsiad! I have many comments to this, but I won't be able to look at it for a few days, unless we're in a rush can we please hold on to it for a bit? Two general comments I can leave now:

  • let's not use eslint for formatting rules (quotes, braces, etc). Let's stick to prettier for it, which is more appropriate, with whatever default it has
  • as suggested on discord, I would start smaller, I already see many rules with questionable benefits that require us to turn them off selectively. It's a small codebase with relatively few contributors, I think we can afford going little by little

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Another couple of suggestions for improving dx:

  • setting up recommended extensions for the workspace, so that new contributors opening the project will get a prompt suggesting to install them
  • setting up lint-staged to run prettier and eslint on changed files as a pre commit hook
  • enforce eslint on the CI

@kpodsiad
Copy link
Member Author

kpodsiad commented Oct 5, 2021

Thanks for your feedback @gabro
I'll add todo list containing your suggestions, but one of them needs further discussion. We aren't in rush so don't worry and take your time ;)

  • let's not use eslint for formatting rules (quotes, braces, etc). Let's stick to prettier for it, which is more appropriate, with whatever default it has

Yes, you are right with quotes, it could be managed by prettier. However, braces should be managed by eslint, see this comment.

  • as suggested on discord, I would start smaller, I already see many rules with questionable benefits that require us to turn them off selectively. It's a small codebase with relatively few contributors, I think we can afford going little by little

I started with just recommended rules, I disabled only 3 rules so it's not that many. I think it's better to stick with the recommended ones and disable the rules which don't suit us than another way, it's shorter for sure.

  • setting up lint-staged to run prettier and eslint on changed files as a pre commit hook

Pre-commit hook could very annoying, especially when developing sth locally and frequently committing local changes. For now, I wouldn't add it.

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

@kpodsiad coming back to this

Yes, you are right with quotes, it could be managed by prettier. However, braces should be managed by eslint, see this comment.

Ok, I'm still not super sold on enforcing formatting rules with eslint because it's trickier to setup a "format on save" workflow. In order to fix those errors on save you would need to enable code actions on save in VS Code, but that setting also fixes a bunch of other non-formatting stuff, so it's not something we would necessarily want to recommend.

I started with just recommended rules, I disabled only 3 rules so it's not that many. I think it's better to stick with the recommended ones and disable the rules which don't suit us than another way, it's shorter for sure.

Left some comment inline about this

Pre-commit hook could very annoying, especially when developing sth locally and frequently committing local changes. For now, I wouldn't add it.

Sure, let's avoid it for now. I would still enforce in the CI, otherwise we're still at risk of merging something that doesn't comply with the rules, which in turn generates spurious diffs in future PRs.

.eslintrc.js Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
src/decoration-protocol.ts Show resolved Hide resolved
src/extension.ts Outdated Show resolved Hide resolved
src/extension.ts Show resolved Hide resolved
src/extension.ts Show resolved Hide resolved
@kpodsiad
Copy link
Member Author

Ok, I'm still not super sold on enforcing formatting rules with eslint because it's trickier to setup a "format on save" workflow. In order to fix those errors on save you would need to enable code actions on save in VS Code, but that setting also fixes a bunch of other non-formatting stuff, so it's not something we would necessarily want to recommend.

@gabro Do you think that lack of "fix on save" action is problematic? ESLint extension shows errors immediately and offers the possibility to quick-fix them. I think, in the terms of this particular rule which is curly, what ESLint does is good enough. Especially when we'll take into account amount of people who will be developing metals extension and fact that inserting braces is a little bit more than just formatting ;)

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my comments! I think it's good enough to merge, let's try with curly and see how it goes :)

There's a merge conflict to fix, but other than that, LGTM! Nice work!

@kpodsiad kpodsiad force-pushed the eslint branch 2 times, most recently from edfc624 to b5f929e Compare October 28, 2021 11:27
@kpodsiad
Copy link
Member Author

@tgodzik @gabro could we merge this PR instead of labeling this with wait for metals release?

@tgodzik
Copy link
Contributor

tgodzik commented Oct 28, 2021

@tgodzik @gabro could we merge this PR instead of labeling this with wait for metals release?

We don't need to wait for anything that doesn't require server changes. I am ok with merging, though I am not an expert here 😅

@gabro
Copy link
Member

gabro commented Oct 28, 2021

Nothing here that needs a new metals release, so yes, let's merge it!

@gabro gabro merged commit 804865e into scalameta:main Oct 28, 2021
@kpodsiad
Copy link
Member Author

In theory, syntax/formatting changes could break some features, just saying' :P

@kpodsiad kpodsiad deleted the eslint branch October 28, 2021 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants