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

[Frontend] Standardize code style using prettier #2406

Closed
Bobgy opened this issue Oct 16, 2019 · 6 comments
Closed

[Frontend] Standardize code style using prettier #2406

Bobgy opened this issue Oct 16, 2019 · 6 comments

Comments

@Bobgy
Copy link
Contributor

Bobgy commented Oct 16, 2019

A standard https://prettier.io/ config that allows everyone format code in the same way helps improve development productivity and avoid wasted efforts during review.

Also suggested by @eterna2
/area front-end
/priority p0

UPDATE: I never considered using clang-format (used in google) for this project, because it doesn't support tsx(react) formatting and deviates a lot from existing code style.

@Bobgy
Copy link
Contributor Author

Bobgy commented Oct 16, 2019

I am planning a few steps on doing this:

  1. [Frontend] Prettier config to be consistent with existing code style #2409 Make a reasonable prettier config with related documentation on how to use it. Start using it in newly written/changed code.
  2. After a week's feedback, agree on the config.
  3. Format all source files under frontend/src using prettier #2462 Transform the complete code base with prettier after syncing with people having open PRs.
  4. [Frontend] Check format in travis CI #2463 Set up precommit hooks + CI check. (No one currently wants a precommit hook, please comment below if you want it.)
  5. [Frontend] Update CONTRIBUTING.md with frontend code style info #2464 Update CONTRIBUTING doc with related information.

Note: there's an ongoing long PR for frontend/server: #2081, I will format server code after it gets merged.

@Bobgy
Copy link
Contributor Author

Bobgy commented Oct 16, 2019

My current prettier config that is mostly the same as our existing code style.

trailingComma: all
singleQuote: true
jsxSingleQuote: true

Made a PR for this config: #2409
Reference:

For configuration, reference: https://prettier.io/docs/en/options.html and https://prettier.io/docs/en/configuration.html

The only major difference is trailingComma: all: https://prettier.io/docs/en/options.html#trailing-commas
I'm strongly for using it, because:

  • it helps make list editing only affect the lines that actually changed, no need to keep fixing commas when reordering

Another difference to discuss is print-width: https://prettier.io/docs/en/options.html#print-width
It recommends 80, but I feel like it's too aggressive.
We can consider using 100 or 120 too.

The following PRs are examples of what code will be changed after applying different configs:

@Bobgy
Copy link
Contributor Author

Bobgy commented Oct 17, 2019

UPDATE, discussed with @jingzhang36 and @rmgogogo. Agreed on printWidth: 100 option, because our screens are larger than before.

@Bobgy
Copy link
Contributor Author

Bobgy commented Oct 23, 2019

Only left work item is enforcing code style for src/frontend/server, will address that in a separate issue as stated in #2406 (comment)

/close

@k8s-ci-robot
Copy link
Contributor

@Bobgy: Closing this issue.

In response to this:

Only left work item is enforcing code style for src/frontend/server, will address that in a separate issue as stated in #2406 (comment)

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Bobgy
Copy link
Contributor Author

Bobgy commented Dec 11, 2019

Note, also standardized src/frontend/server in #2717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants