Amphtml: Adopt `prettier` for code formatting

Created on 25 Jul 2018  路  9Comments  路  Source: ampproject/amphtml

INTENT TO IMPLEMENT Soon Feature Request infra

Most helpful comment

All 9 comments

/cc @kristoferbaxter @cramforce

Request: Look at removing all the ESLint rules regarding formatting at the same time.

@kristoferbaxter Yes, the goal is to replace all eslint style rules, while retaining all the coding guideline rules.

Hooray for consistency! Has there been / will there be a design review for implementing mandatory source formatting? Will this format the whole file at once, or just lines/blocks that were changed?

Design review is a good idea. I'll schedule one after I experiment with prettier and come up with a list of common workflows that will result from adopting it.

This issue hasn't been updated in awhile. @rsimha Do you have any updates?

At long last, I experimented with using prettier for AMP. Since we use eslint for code formatting and for preventing known anti-patterns through custom rules in build-system/eslint-rules, my approach was to use eslint-plugin-prettier as part of our global .eslintrc, thereby switching to prettier for code formatting while continuing to use eslint for other checks.

Unfortunately, it looks like I've hit a blocking issue. AMP code requires quoted object keys to prevent aggressive minification by closure compiler (#10094), which resulted in the amphtml-internal/dict-string-keys rule. It doesn't look like there's a way to prevent prettier from stripping away these keys (https://github.com/prettier/prettier/issues/4327), and it's unlikely that this bug will get fixed in the near future. The only workaround seems to be to use square brackets around keys to prevent them from being optimized away, and that doesn't seem like an acceptable solution.

@kristoferbaxter @cramforce Since you're more familiar with prettier than I am, are you aware of any other workarounds to this? Or are we at an impasse?

Full list of errors as of today: https://travis-ci.org/ampproject/amphtml/jobs/500592963#L1933

This is done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

torch2424 picture torch2424  路  3Comments

samanthamorco picture samanthamorco  路  3Comments

mrjoro picture mrjoro  路  3Comments

mkhatib picture mkhatib  路  3Comments

choumx picture choumx  路  3Comments