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 html to prettier #13252

Merged
merged 6 commits into from
Dec 15, 2020
Merged

Add html to prettier #13252

merged 6 commits into from
Dec 15, 2020

Conversation

swarajsaaj
Copy link
Contributor

HTML files will now be included in prettier command

Fix #13090


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (bellow reviewers) and adding skip-ci label, you can still see CI build result at your branch.

Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

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

LGTM.

@mshima
Copy link
Member

mshima commented Dec 12, 2020

@swarajsaaj move html extension to inside skipClient condition.
I don't think there is any html on backend only.

@swarajsaaj
Copy link
Contributor Author

@swarajsaaj move html extension to inside skipClient condition.
I don't think there is any html on backend only.

@mshima I could find src/main/resources/templates/error.html in backend, also some mail templates are there for usermanagement apps in src/main/resources/templates/mail/

@gmarziou
Copy link
Contributor

gmarziou commented Dec 12, 2020

I could find src/main/resources/templates/error.html in backend, also some mail templates are there for usermanagement apps in src/main/resources/templates/mail/

But these are Thymeleaf templates, I'm not sure Prettier can do a good job with them although I did not check.
I have same doubts about Angular templates, usually code formatters are not comfortable with template syntax.

@swarajsaaj
Copy link
Contributor Author

swarajsaaj commented Dec 12, 2020

I could find src/main/resources/templates/error.html in backend, also some mail templates are there for usermanagement apps in src/main/resources/templates/mail/

But these are Thymeleaf templates, I'm not sure Prettier can do a good job with them although I did not check.
I have same doubts about Angular templates, usually code formatters are not comfortable with template syntax.

@gmarziou I think for Thymeleaf most of syntax is inserted as attributes to HTML elements (with a prefix namespace), so they should not interfere with formatting.

For Angular templates, Prettier seems to have support for *.component.html files since v1.15 https://prettier.io/blog/2018/11/07/1.15.0.html to take interpolation into consideration

@mshima
Copy link
Member

mshima commented Dec 12, 2020

@gmarziou you can see the result at https://github.com/jhipster/generator-jhipster/pull/13252/checks?check_run_id=1542973740 (MERGE: project diff section).

Backend files are the first. Looks ok to me.

@gmarziou
Copy link
Contributor

gmarziou commented Dec 12, 2020

Thanks for the examples, output is consistent and works well with templates.

It's just that I'm not a big fan of the way Prettier formats html which uses much more vertical space than original formatting.

            <input
              type="password"
              class="form-control"
              id="newPassword"
              name="newPassword"
              placeholder="{{ 'global.form.newpassword.placeholder' | translate }}"
              formControlName="newPassword"
              data-cy="resetPassword"
              #newPassword
            />

or

<html
  xmlns:th="http://www.thymeleaf.org"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.thymeleaf.org"
  th:lang="${#locale.language}"
  lang="en"
>

Also embedded CSS formatting does not look familiar to me, I would keep body, p { together rather than inserting a new line like below:

      @media only screen and (max-width: 280px) {
        body,
        p {

@mshima
Copy link
Member

mshima commented Dec 12, 2020

Not a big fan either, but overall is better with prettier enabled IMO.

@gmarziou
Copy link
Contributor

Agreed, let's favor style consistency.

HTML files will now be included in prettier command

Fix jhipster#13090
@swarajsaaj
Copy link
Contributor Author

swarajsaaj commented Dec 13, 2020

@mshima @gmarziou Could you please help why "npm test" is failing in the CI (https://github.com/jhipster/generator-jhipster/pull/13252/checks?check_run_id=1546315589) ? I am not sure how this timeout error can be due to html prettier change, or is it due to some other issue?

@mshima
Copy link
Member

mshima commented Dec 13, 2020

Try to increase timeout to 40000 at:

timeout: 30000,

Enabling prettier at html can make the generation slower.

@swarajsaaj
Copy link
Contributor Author

swarajsaaj commented Dec 14, 2020

@mshima I have tried increasing 30000ms to 90000ms in steps, but seems that is not the issue (original test runs in ~3s), seems there is some conflict with HelloVue.html file being generated in the test (

this.template(path.join(process.cwd(), 'HelloVue.html.ejs'), `${ANGULAR_DIR}HelloVue.html`);
)

Correct HelloVue.html syntax to <head> tag instead of nested <meta>
tags, and reverted mocha tests timeout to 30000ms are original

Fix jhipster#13090
@swarajsaaj
Copy link
Contributor Author

@mshima Finally found the hidden problem, under the hood in test prettier was getting stuck due to a syntax error in HelloVue.html, <meta> was enclosed in a nested meta tag instead of a <head>, thanks for the help :)

@DanielFran
Copy link
Member

@swarajsaaj Thanks for the contribution!

@DanielFran DanielFran merged commit 580b200 into jhipster:main Dec 15, 2020
@mshima
Copy link
Member

mshima commented Dec 15, 2020

Great job finding the error.
I actually didn’t help.

@pascalgrimaud pascalgrimaud added this to the 7.0.0-beta.0 milestone Dec 18, 2020
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.

Enable prettier for html files.
5 participants