Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

[IMP] Add Prettier and ESLint with --fix #618

Merged
merged 2 commits into from
Jan 24, 2020

Conversation

yajo
Copy link
Member

@yajo yajo commented Nov 19, 2019

This commit includes:

  • Using https://prettier.io/ for supported file formats (these include CSS, SCSS, JS, HTML, MD, YAML and others; see website).
  • Configure ESLint using eslint-config-prettier and removing stylistic checks to avoid conflicts with Prettier.
  • Add Promise as a builtin for v13 (this was missed before, so I take this chance to add that).
  • Format properly .travis.yml so that when it gets merged downstream it gets less diffs when passed trhough Prettier.
  • Use eslint --fix so we get less warnings and more fixes.

Some insights:

@Tecnativa @sbidoul @moylop260 OCA/maintainer-tools#323 (comment) TT20357

@yajo yajo force-pushed the precommit-prettier-eslintfix branch from b194a65 to 16f8ab0 Compare November 19, 2019 11:28
@yajo yajo force-pushed the precommit-prettier-eslintfix branch from 16f8ab0 to 200f754 Compare November 19, 2019 11:39
Copy link
Contributor

@moylop260 moylop260 left a comment

Choose a reason for hiding this comment

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

the concept looks good to me
thanks!

@lmignon
Copy link
Contributor

lmignon commented Nov 19, 2019

@yajo Nice improvement!

@yajo yajo force-pushed the precommit-prettier-eslintfix branch from 200f754 to 0129df2 Compare November 19, 2019 13:10
@sbidoul
Copy link
Member

sbidoul commented Nov 19, 2019

I tried this on my favorite repo and found a few potential issues:

  • it fiddles with .md files, including rewriting LICENSE.md, is that what we want?
  • it also fiddles with .html files (there is a doc template in mis builder where the prettier output is not that pretty I'd say)
  • also, eslint complains
[Error - 10:01:53 PM] Error: Failed to load config "prettier" to extend from.
Referenced from: /home/sbi-local/ACSONE/OpenErp/odoo-10/src/mis-builder/.eslintrc

Otherwise, for .js, .yml, and .css files, it looks good 👍

@yajo
Copy link
Member Author

yajo commented Nov 20, 2019

  • it fiddles with .md files, including rewriting LICENSE.md, is that what we want?

I think yes, autoformatting is good everywhere IMHO, MD included. We can add the exception for LICENSE files however, although it's weird that your license is written in MD because I have not seen any LICENSE provider that uses MD. They tend to use raw txt instead. Do you have an example?

  • it also fiddles with .html files (there is a doc template in mis builder where the prettier output is not that pretty I'd say)

Again if you can point to the example... You can see I ignored for instance static/description where the bot generates the HTML readme; we can add more exceptions.

  • also, eslint complains

You mean eslint out of pre-commit, right? For instance when using an integrated eslint on your IDE... Well, you see that it needs a new npm dependency that includes some configs. You have to make sure that the npm package eslint-config-prettier is available to the node environment where your local eslint is running. In the pre-commit environment, pre-commit will install that dependency now, though.

@sbidoul
Copy link
Member

sbidoul commented Nov 20, 2019

.md files, LICENSE.md

You can look in the mis-builder repo (I think I got the license from the GNU website).

.html

Example in OCA/mis-builder, docs directory.

So yeah, to avoid bad surprises, I would tend to restrict prettier to an explicit list of formats (.js, .css and friends, and .xml when it's stable).

eslint out of pre-commit, right? For instance when using an integrated eslint on your IDE

Yes exactly. I think there is huge value to have .eslintrc working out of the box so dummies like me do not have to ask themselves how to make their IDE work. Since we will be maintaining these configs automatically, a little bit of redundancy does not hurt.

@yajo yajo force-pushed the precommit-prettier-eslintfix branch 2 times, most recently from f805338 to 1a84ab0 Compare November 21, 2019 09:20
@yajo
Copy link
Member Author

yajo commented Nov 21, 2019

You can look in the mis-builder repo (I think I got the license from the GNU website).

I see, yes it's downloadable from GNU as MD.

OK, I added an exclusion pattern to avoid touching license files. 😊

Example in OCA/mis-builder, docs directory.

Excluded now.

So yeah, to avoid bad surprises, I would tend to restrict prettier to an explicit list of formats (.js, .css and friends, and .xml when it's stable).

That's basically what I'm proposing here. Those formats are JS, Less, CSS, SCSS, HTML and MD. It's just that it's implicit, but since the prettier version is pinned, there'll be no surprises there.

I think there is huge value to have .eslintrc working out of the box so dummies like me do not have to ask themselves how to make their IDE work. Since we will be maintaining these configs automatically, a little bit of redundancy does not hurt.

I have a mixed feeling here.

On one side, you're right that it's good to have ides working out of the box, but it's also true that what really works out of the box is pre-commit, and it works even if you edit files with cat, so it's a pretty good out-of-the-box integration on any environment.

On the other side, a problem maintaining .eslintrc is that it is a JSON file, so we cannot have i.e. comments. There's no way to warn maintainers // hey, these settings come from that package, which we are not including because blahblah, so all you see is a big file with tons of settings and it's not obvious why they are there. However, now you immediately see "extends": ["prettier"], and that makes it obvious that you need some extension to make it work. I have to admit that it's also not so obvious that the package you need is eslint-config-prettier, though...

Balancing both things, I personally prefer the maintenance side of the problem. The dev side can be fixed very easily with an entry in the contributing guideline: "How to set up a development environment". Now that we have bots 🤖 we can instruct them to add a link to that section in all repos (or modules) READMEs.

@sbidoul
Copy link
Member

sbidoul commented Nov 21, 2019

That's basically what I'm proposing here. Those formats are JS, Less, CSS, SCSS, HTML and MD

I'd be more comfortable to leave out html and md.

"extends": ["prettier"], and that makes it obvious that you need some extension to make it work

Can't we include the prettier part of the config in a commented block or something? We want to keep it as simple as possible for contributors even if it's a bit less comfortable for maintainers of the config (i.e. you and me for now), and currently eslint works out of the box with the .eslintrc we provide for 13.0 branches, so requiring additional config is a regression IMO.

@yajo
Copy link
Member Author

yajo commented Nov 26, 2019

I'd be more comfortable to leave out html and md.

why do you want ugly MD/HTML files around? 🤔

I'm reluctant to exclude those. The same reasons we want code autoformatters for other formats apply for MD and HTML, and in any case, the autogenerated index.html files are excluded and the split README files are in RST so they are not affected, so it's not like that's gonna mean much of a problem for us.

If you are worried about reducing diff... then we shouldn't use code formatters at all; but I guess we already passed that milestone, so I see no problem there.

Can't we include the prettier part of the config in a commented block or something?

Nope. JSON doesn't support comments.

@yajo
Copy link
Member Author

yajo commented Nov 26, 2019

Simplifying .eslintrc is going to be easier than I thought:

  • I will convert to YAML, which supports richer syntax including comments. It is supported by ESLint out of the box.
  • I will remove all disabling rules. It turns out all rules are diabled by default.
  • Since all rules are disabled by default, there's no need to include the eslint-config-prettier plugin because it's only disabling things that are disabled already.

I'm going to include a link to this comment, explaining that style rules shouldn't be included (those are handled by Prettier; we only need rules that check AST patterns), and that we shouldn't include any rule listed in https://github.com/prettier/eslint-config-prettier/blob/v6.6.0/index.js.

@yajo yajo force-pushed the precommit-prettier-eslintfix branch from 1a84ab0 to 6a3a97f Compare November 26, 2019 12:07
@yajo
Copy link
Member Author

yajo commented Nov 26, 2019

This should be ready to merge 😊

@sbidoul
Copy link
Member

sbidoul commented Nov 26, 2019

The .md prettying changes the addons table generated by the bot in README.md, so it will loop.

@yajo yajo force-pushed the precommit-prettier-eslintfix branch 2 times, most recently from cf8ce5a to dd062cc Compare November 28, 2019 10:23
@yajo
Copy link
Member Author

yajo commented Nov 28, 2019

The .md prettying changes the addons table generated by the bot in README.md, so it will loop.

I added prettier ignore marks to README template, to avoid that.

I also opened OCA/maintainer-tools#436 to avoid different header styles.

That should fix the problem. 😊

@sbidoul
Copy link
Member

sbidoul commented Nov 28, 2019

I added prettier ignore marks to README template, to avoid that.

Does this mean all README.md need to be updated manually?

@yajo
Copy link
Member Author

yajo commented Nov 28, 2019

I was supposing it is an automatic process also... It can be done with a sed command maybe.

There's the possibility to make the script inject the prettier lines inside instead, but prettier converts [//]: # (addons) into [//]: # "addons". Not a big problem if we add that to the regexp, though. Next run of prettier would touch it and it'd be done forever.

@yajo
Copy link
Member Author

yajo commented Dec 19, 2019

So?

@moylop260
Copy link
Contributor

@guewen
Your opinion is welcome here

@sbidoul
Do you have feedback?

@sbidoul
Copy link
Member

sbidoul commented Dec 19, 2019

I'm fine with the js and yml parts.

I checked the last comments again and it seems to me we are still blocked on README.md

I was supposing it is an automatic process also... It can be done with a sed command maybe.

README.md files are maintained manually.

The easiest way out is still to leave .md files out of prettier's hands, IMO.

@yajo
Copy link
Member Author

yajo commented Jan 24, 2020

Given we're going to add a big reformatter change, I took the chance to update some hooks. I tested this config and it works fine.

@yajo yajo force-pushed the precommit-prettier-eslintfix branch from e2e270e to 6c162d3 Compare January 24, 2020 09:31
@yajo
Copy link
Member Author

yajo commented Jan 24, 2020

The email is ready, I just need to know the schedule if possible. Otherwise you can just reply to it in the mailing list to tell that.

Jairo Llopis added 2 commits January 24, 2020 10:56
This commit includes:

- Using https://prettier.io/ for supported file formats (these include CSS, SCSS, JS, HTML, MD, YAML and others; see website).
- Transform `.eslintrc` (deprecated) to `.eslintrc.yml`, which supports more advanced syntax.
- Simplify `.eslintrc.yml` removing disabled checks. All checks are disabled by default anyways.
- Remove from `.eslintrc.yml` all stylistic checks that would conflict with Prettier.
- Add `Promise` as a builtin for v13 (this was missed before, so I take this chance to add that).
- Format properly `.travis.yml` so that when it gets merged downstream it gets less diffs when passed trhough Prettier.
- Use `eslint --fix` so we get less warnings and more fixes.
- Add prettier ignoration tags to README.md template, to avoid double-formatting addons table section.
- Add prettier XML plugin too, as a separate job.
- Ignore for now README.md files to avoid overcomplicating maintenance of those files.
@yajo yajo force-pushed the precommit-prettier-eslintfix branch from 6c162d3 to bb15a90 Compare January 24, 2020 10:57
@sbidoul
Copy link
Member

sbidoul commented Jan 24, 2020

I can try to prepare a bit this week-end and apply it on all repos the week-end of February 15th.

@yajo
Copy link
Member Author

yajo commented Jan 24, 2020 via email

@sbidoul
Copy link
Member

sbidoul commented Jan 24, 2020 via email

@yajo
Copy link
Member Author

yajo commented Jan 24, 2020

I don't have merge permissions here, could anybody merge please?

@pedrobaeza pedrobaeza merged commit 1b93706 into OCA:master Jan 24, 2020
@pedrobaeza pedrobaeza deleted the precommit-prettier-eslintfix branch January 24, 2020 12:46
yajo pushed a commit to Tecnativa/maintainer-quality-tools that referenced this pull request Jan 24, 2020
A couple of fixes missing from OCA#618.

@Tecnativa TT20357
yajo pushed a commit to Tecnativa/web that referenced this pull request Jan 24, 2020
@lmignon
Copy link
Contributor

lmignon commented Jan 24, 2020

I'm late into this conversation but does that mean we're going to fix all the migration PRs that haven't been merged yet. It's a lot of work, even though I know it's for the best...

yajo pushed a commit to Tecnativa/website that referenced this pull request Jan 24, 2020
@yajo
Copy link
Member Author

yajo commented Jan 24, 2020 via email

@lmignon
Copy link
Contributor

lmignon commented Jan 24, 2020

you are right @yajo Neverthless, in any case the PRs will no longer be mergeable. 😱 😏

@yajo
Copy link
Member Author

yajo commented Jan 24, 2020

Yes, I guess the amend will be required anyway.

Merge them quick before february 15th! 😁

@guewen
Copy link
Member

guewen commented Jan 24, 2020

@sbidoul If I propose OCA/stock-logistics-warehouse#828 in this repo during the next week, do you think it can be included in the next pre-commit files update?

@sbidoul
Copy link
Member

sbidoul commented Jan 24, 2020

@guewen Sure!

yajo pushed a commit to Tecnativa/web that referenced this pull request Jan 27, 2020
yajo pushed a commit to Tecnativa/website that referenced this pull request Jan 27, 2020
yajo pushed a commit to Tecnativa/web that referenced this pull request Jan 30, 2020
yajo pushed a commit to Tecnativa/web that referenced this pull request Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants