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

Autoformatting with js-beautify-html #241

Merged
merged 2 commits into from
Mar 23, 2020
Merged

Autoformatting with js-beautify-html #241

merged 2 commits into from
Mar 23, 2020

Conversation

subdavis
Copy link
Contributor

@subdavis subdavis commented Mar 23, 2020

Turns out autoformatting is hard.

  • Vetur Prettier ignores ESLint rules with prettier.eslintIntegration set to true vuejs/vetur#695 -- Vetur doesn't support a single autoformatter that is capable of running eslint --fix with our configuration. You can try to find a prettier config that happens to overlap, but I don't believe it's possible.
  • As a result, I've turned js autoformatting with vetur off for VS Code. Eslint is much smarter than any prettier config.
  • However, I did turn on lint-on-save features, which do read eslintConfig from package.json. It's basically like running yarn lint every time you save

HTML formatting was another animal. Eslint isn't that opinionated about html formatting, and I think we should be more rigorous when possible.

For example:

<v-tab-item key="login-box">
  <girder-login
            :oauth-providers="oauthProviders"
            v-bind="{ forceOtp, forgotPasswordUrl, forgotPasswordRoute, hideForgotPassword }"
            @forgotpassword="$emit('forgotpassword')" /> </v-tab-item>

eslint doesn't mind if you do stuff like this, but I'd prefer to be more strict:

      <v-tab-item key="login-box">
        <girder-login
          :oauth-providers="oauthProviders"
          v-bind="{ forceOtp, forgotPasswordUrl, forgotPasswordRoute, hideForgotPassword }"
          @forgotpassword="$emit('forgotpassword')"
        />
      </v-tab-item>

autoformatting with js-beautify will produce this, but more work is needed to figure out how to get it to run in CI. I think this PR provides reasonable middle ground for VS Code users: hitting ctrl+shift+i will perform autoformatting.

I'd love to bring back yarn lint:html but I've spent too long on this this morning so far. Settings for https://github.com/beautify-web/js-beautify can probably be found so that we can run js-beautify from a package.json command.

@subdavis subdavis requested a review from zachmullen March 23, 2020 15:11
@@ -155,7 +155,8 @@ export default {
<breadcrumb
:location="model"
readonly="readonly"
no-root="no-root"/>
no-root="no-root"
Copy link
Member

Choose a reason for hiding this comment

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

I was hoping there was some rule that would change these boolean properties back to just the no-root form. This is technically equivalent, just seems less preferable than the shorthand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #242 because I don't want to leave it like this, but I don't feel like fixing it right now.

@subdavis subdavis merged commit fddbab5 into pug-to-html Mar 23, 2020
@subdavis subdavis deleted the autoformatting branch March 23, 2020 16:20
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.

2 participants