Skip to content

Enforce formatting in repo#1338

Merged
josemontespg merged 2 commits intogoogle:mainfrom
josemontespg:enforce-formatting
May 5, 2026
Merged

Enforce formatting in repo#1338
josemontespg merged 2 commits intogoogle:mainfrom
josemontespg:enforce-formatting

Conversation

@josemontespg
Copy link
Copy Markdown
Collaborator

@josemontespg josemontespg commented May 5, 2026

Enforce consistent formatting and linting across the repo

This PR implements the plan described in issue #1337 to address inconsistent formatting configurations that cause unnecessary whitespace diffs in PRs.

Proposed Changes

1. Infrastructure (Configs & Scripts)

  • Unified Prettier Configuration: Added a root-level .prettierrc and .prettierignore to ensure consistent formatting for JS/TS/JSON/Markdown files.
  • EditorConfig: Added a root-level .editorconfig to enforce basic rules like 2-space indentation repo-wide.
  • Formatting Script: Created scripts/fix_format.sh to easily lint and format the entire repository using Prettier, Pyink (Python), and Dart format.
  • CI Workflow: Added .github/workflows/enforce-formatting.yml to automatically check formatting on all pushes and PRs.
  • Documentation: Updated CONTRIBUTING.md with instructions on how to use the script and recommended VS Code extensions.
  • VS Code Settings: Updated .vscode/settings.json to help developers use the correct formatters by default on save.

2. Mechanical Formatting

  • Applied formatting to the codebase using the new rules. This is a large commit but purely mechanical.

Rationale for Choices

  • We chose to follow GTS (Google TypeScript Style) defaults repo-wide, including bracketSpacing: false, as it is preferred for consistency with Google standards.
  • We are using pyink for Python to adhere to Google's Python style.

Reviewing Strategy

Ideally, the changes can be reviewed separately:

  1. Commit 1: Infrastructure changes (configs and scripts).
  2. Commit 2: Mechanical formatting changes (large).

Fixes #1337

@github-project-automation github-project-automation Bot moved this to Todo in A2UI May 5, 2026
@josemontespg josemontespg marked this pull request as draft May 5, 2026 19:35
@josemontespg josemontespg marked this pull request as draft May 5, 2026 19:35
@josemontespg josemontespg force-pushed the enforce-formatting branch 2 times, most recently from 30c6d10 to 7ce5432 Compare May 5, 2026 20:41
@josemontespg josemontespg force-pushed the enforce-formatting branch from 7ce5432 to e6edd7b Compare May 5, 2026 20:45
@josemontespg josemontespg marked this pull request as ready for review May 5, 2026 20:53
Copy link
Copy Markdown
Collaborator

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!

We should be able to reuse this once we split into separate repos.

Copy link
Copy Markdown
Collaborator

@ditman ditman left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks for attempting this. I'd recommend you merge this ASAP (use my comments maybe as fast-follows).

PS: I'm surprised this PR does not touch any .py files. Is that expected? Were they being already formatted?

Comment thread scripts/fix_format.sh
if [ "$CHECK_ONLY" = true ]; then
dart format --output=none --set-exit-if-changed .
else
dart format .
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It'd be nice that this script would echo a "run scripts/fix_format.sh" (or the github action) so failures to check are more actionable.

Comment thread .prettierignore
# See the License for the specific language governing permissions and
# limitations under the License.

node_modules
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need things like .angular here as well? I remember having to add it to the gitignore earlier.

Comment thread .editorconfig
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any chance of enabling format-on-save or similar? Does the formatting config require running the formatting script, or can it be started from the IDE?

@josemontespg josemontespg merged commit 9526ab2 into google:main May 5, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in A2UI May 5, 2026
@josemontespg
Copy link
Copy Markdown
Collaborator Author

Increasing scope of the formatter for python in #1340

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Enforce formatter and linter in repo

3 participants