Skip to content

Run clang-format on all first-party code, and add a .git-blame-ignore-revs file #9781

Open
@redoak

Description

@redoak

Task (REQUIRED):

A lot of first-party code doesn't conform to the .clang-format rules (600+ files when I ran it).

This raises a question for new contributors: "should I follow the existing style in the file I'm editing, should I apply the clang style on my changes only, the whole file, or do something else?"

It may also introduce distracting formatting diffs when comparing code across files. Tools that do diffs could be affected, like code duplication finders.

By running clang-format on all first-party code, all future commits can be set to be automatically formatted (or verified) with clang-format, via a GitHub action or local Git pre-commit hook, without causing unwanted changes. It may be good to have any action or hook verify that the local clang-format version is the expected version, since the formatted output may differ between versions.

To avoid these formatting changes from polluting git blame results, a .git-blame-ignore-revs file should be added. This blog post describes what's needed. GitHub picks up this file automatically. Locally, each user should run git config --global blame.ignoreRevsFile .git-blame-ignore-revs.

To avoid third-party code from being formatted, clang-format-ignore files should be added. I would suggest that each folder that contains a direct sub-folder with third-party code should have a .clang-format-ignore file. E.g. /engine/physics/src/box2d/.clang-format-ignore would list ./Box2D. These files would also be a useful resource when you want to run tools on first-party code, like a code duplication finder.

Expected outcome (REQUIRED):

  • All first-party code is formatted correctly
  • A .git-blame-ignore-revs file containing the commit hash is located in the repository root
  • .clang-format-ignore files list all third-party code sub-folders
  • A GitHub action is set up, or a Git pre-commit hook file is available for users to download

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupengineIssues related to the Defold enginetaskA task that needs to be performed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions