adoptium / aqa-test-tools

Home of Test Results Summary Service (TRSS) and PerfNext. These tools are designed to improve our ability to monitor and triage tests at the Adoptium project. The code is generic enough that it is extensible for use by any project that needs to monitor multiple CI servers and aggregate their results.
Apache License 2.0
27 stars 79 forks source link

Investigate the formatting tool for the project #591

Closed llxia closed 2 years ago

llxia commented 2 years ago

It is very important to have a good coding standard. It helps to keep the code simple and clean. A nice formatted code is easier for people to understand, review, compare, maintain and update. We should investigate a good formatting tool for the project. Below are some of the requirements:

Possible tool: https://prettier.io/

Addtional description (see https://github.com/adoptium/aqa-test-tools/issues/591#issuecomment-1023239334)

yinggzz commented 2 years ago

I'd love to investigate on the tool

yinggzz commented 2 years ago

Here are some potential formatting tools for the project I have found.

Prettier:

CodeBeautify

RubyMine

Language Specific Java:

Python: Black

smlambert commented 2 years ago

Thanks @yinggzz ! Based on our discussion today, you and @llxia have a few additional activities on this one, focussing on Prettier and CodeBeautify. Think about what we would expect of contributors to this repository. Would we 'enforce' formatting with a PR check? Are their github actions that would allow for this as part of a workflow? If we do not enforce it, is this mainly about creating a template and document guidelines?

llxia commented 2 years ago

The goal is this task is to find a formatting tool that can format automatically for the users. Ideally, the PR should be formatted well before users submit the PRs. I would expect that there is no or minimal work for both users and reviewers for formatting.

PR checks may be needed for users that do not use common IDE with formatter tool support. This can be discussed at a later stage. But for this issue, I would like to focus on:

Thanks @yinggzz for your work so far. I hope the above description clarifies the goal and scope of this task. If you have any questions, please let us know.

yinggzz commented 2 years ago

Hi @llxia , thank you for your instruction! After a lot of research, I couldn’t really find other tools that are similar to Prettier and support integration with different IDEs and languages.

Please see below for my research on Prettier, it can be used as a pre-commit tool to format file before committing.

I was wondering if you can elaborate what to include in the “Format file” besides links for downloading it for different code editors.

yinggzz commented 2 years ago

Prettier Pros:

Cons:

Pull-requests, pre-commit hook

Example use case for a project: Run prettier on a large code base at once https://flexport.engineering/upgrading-prettier-on-a-large-codebase-28d56c4de49e

Goal: run prettier so that changes it makes are attributed correctly in git, no merge conflict in open pull requests, repeatable.

  1. develop a small set of scripts to install and upgrade prettier
  2. run it on every file in code base, clean up errors, make commit to master and update all open pull request *scripts should be run without anyone else committing to master before the scripts finish.

General work flow to automate code formatting in pull requests: https://peterevans.dev/posts/github-actions-how-to-automate-code-formatting-in-pull-requests/

  1. When a pull request is raised the workflow executes as a check.
  2. The code formatter executes and modifies files if necessary.
  3. The workflow checks to see if any tracked files by git have been modified.
  4. If modified files exist they are committed and pushed to the remote.
  5. When using a repo scoped Personal Access Token instead of GITHUB_TOKEN, the push triggers all pull request checks to run again.
llxia commented 2 years ago

Add prettier in TRSS https://github.com/adoptium/aqa-test-tools/pull/611

llxia commented 2 years ago

https://github.com/adoptium/aqa-test-tools/pull/612 https://github.com/adoptium/aqa-test-tools/pull/613

llxia commented 2 years ago

Code formatter prettier is added in TRSS. I will close this issue.