Skip to content

ORC-1307: Add .clang-format to enforce C++ code style - #1308

Merged
wgtmac merged 11 commits into
apache:mainfrom
wgtmac:clang-format
Nov 8, 2022
Merged

wgtmac merged 11 commits into
apache:mainfrom
wgtmac:clang-format

Conversation

@wgtmac

@wgtmac wgtmac commented Nov 4, 2022

Copy link
Copy Markdown
Member

There are some guidelines on formatting: https://orc.apache.org/develop/coding/. But no tooling has been available to enforce the style of C++ code. This patch aims to be the starting point. Follow-up changes will include automatic scripts to format cpp source files and per-commit check.

@wgtmac
wgtmac requested a review from dongjoon-hyun November 5, 2022 00:34

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you so much, @wgtmac . I have three comments.

  • This looks worth to have a JIRA ID. Could you file one?
  • The code change should be in the same PR because we cannot merge this if this rule causes too breaking changes.
  • In addition, we had better the CI enforcement of this rule in this PR together.

@dongjoon-hyun

Copy link
Copy Markdown
Member

cc @williamhyun and @stiga-huang

@github-actions github-actions Bot added the INFRA label Nov 6, 2022
@wgtmac wgtmac changed the title MINOR: Add .clang-format for C++ code ORC-1307: Add .clang-format to enforce C++ code style Nov 6, 2022
@github-actions github-actions Bot added the CPP label Nov 6, 2022
@wgtmac

wgtmac commented Nov 6, 2022

Copy link
Copy Markdown
Member Author

I have tried to apply clang-format-action to verify whether the C++ files follow the .clang-format config file. However, I got an error as below:

jidicula/clang-format-action@v4.9.0 is not allowed to be used in apache/orc. Actions in this workflow must be: within a repository owned by apache, created by GitHub, verified in the GitHub Marketplace, or matching the following: /@[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+, AdoptOpenJDK/install-jdk@, JamesIves/github-pages-deploy-action@5dc1d5a, TobKed/label-when-approved-action@, actions-cool/issues-helper@, actions-rs/, al-cheb/configure-pagefile-action@, amannn/action-semantic-pull-request@, apache/, burrunan/gradle-cache-action@, bytedeco/javacpp-presets/.github/actions/, chromaui/action@, codecov/codecov-action@, conda-incubator/setup-miniconda@, container-tools/kind-action@, container-tools/microshift-action@, dawidd6/action-download-artifact@, delaguardo/setup-graalvm@, docker://jekyll/jekyll:, docker://pandoc/core:2.9, eps1lon/actions-label-merge-conflict@, gaurav-nelson/github-action-markdown-link-check@*,...

After some research, I figured out that this action is not whitelisted by the Apache project setting: https://github.com/orgs/community/discussions/25488. Unfortunately I don't have the permission to add it. Do you know how to do that, or is there any alternative? @dongjoon-hyun @williamhyun @stiga-huang

@dongjoon-hyun

Copy link
Copy Markdown
Member
  • Given that there are many other projects like Apache Arrow, there might be ASF-approved GitHub Action.
  • We need to file an INFRA JIRA to ask about what is allowed or to ask to add a new GitHub Action plugin.

@wgtmac

wgtmac commented Nov 7, 2022

Copy link
Copy Markdown
Member Author
  • Given that there are many other projects like Apache Arrow, there might be ASF-approved GitHub Action.
  • We need to file an INFRA JIRA to ask about what is allowed or to ask to add a new GitHub Action plugin.

I have checked Apache Arrow but it uses cpplint manually and does not integrate it with the GitHub workflow.

jidicula/clang-format-action

I have checked apache/arrow, apache/avro, and apache/impala. It looks like none of them use Github workflow to apply style check. Apache Arrow uses cpplint manually but it requires hard work to match the style between clang-format and cpplint.

I have filed an INFRA JIRA: https://issues.apache.org/jira/browse/INFRA-23873.

@wgtmac

wgtmac commented Nov 7, 2022

Copy link
Copy Markdown
Member Author

@dongjoon-hyun Now it is good to go.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you so much, @wgtmac .

@dongjoon-hyun dongjoon-hyun changed the title ORC-1307: Add .clang-format to enforce C++ code style ORC-1307: Add .clang-format to enforce C++ code style Nov 7, 2022

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1, LGTM.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Since it looks very intrusive, cc @williamhyun , @omalley , @stiga-huang , @guiyanakuang , too.

@williamhyun williamhyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 LGTM!

@guiyanakuang guiyanakuang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 LGTM

@stiga-huang

Copy link
Copy Markdown
Contributor

Thanks for adding this! One concern is that this PR touch most of the c++ codes. git blame will always point to this PR.
It seems that keeping the indent inside namespace can save many changes. Probably we can have a try?

@wgtmac

wgtmac commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

Thanks for adding this! One concern is that this PR touch most of the c++ codes. git blame will always point to this PR. It seems that keeping the indent inside namespace can save many changes. Probably we can have a try?

That's a good catch! Let me add NamespaceIndentation:All to reduce lines of change.

@stiga-huang

Copy link
Copy Markdown
Contributor

Thanks for adding the new rule! Now I see some changes are refactoring simple functions like

    bool operator != (const FileVersion & right) const {
      return !(*this == right);
    }

into in one line

    bool operator!=(const FileVersion& right) const { return !(*this == right); }

Does it mean the previous syntax won't be accepted anymore? Impala allows both format. Not sure if this takes effect:

https://github.com/apache/impala/blob/3938dae8be6f28132de67f10d0361665e5c6cad3/.clang-format#L7

It'd be nice if both formats are allowed. But I'm ok with merging the current PR.

@wgtmac

wgtmac commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

AllowShortFunctionsOnASingleLine: Inline

Unfortunately AllowShortFunctionsOnASingleLine: Inline fails the format check. I changed it to AllowShortFunctionsOnASingleLine: Empty instead. Please check @stiga-huang

@stiga-huang stiga-huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1. Thanks for making the changes!

@wgtmac
wgtmac merged commit b5cbed4 into apache:main Nov 8, 2022
@wgtmac

wgtmac commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

I just committed this. Thank you all! @dongjoon-hyun @stiga-huang @williamhyun @guiyanakuang

dongjoon-hyun added a commit that referenced this pull request Jan 9, 2023
### What changes were proposed in this pull request?

This PR is an accumulated change to make the PR labeler up-to-date.
- Remove `.travis.yml` (#991)
- Add `dev` folder (#1136)
- Add `.clang-format` (#1308)

### Why are the changes needed?

To make the PR labeler up-to-date.

### How was this patch tested?

Manual review.

Closes #1362 from dongjoon-hyun/ORC-1351.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
### What changes were proposed in this pull request?

This PR is an accumulated change to make the PR labeler up-to-date.
- Remove `.travis.yml` (apache#991)
- Add `dev` folder (apache#1136)
- Add `.clang-format` (apache#1308)

### Why are the changes needed?

To make the PR labeler up-to-date.

### How was this patch tested?

Manual review.

Closes apache#1362 from dongjoon-hyun/ORC-1351.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@wgtmac
wgtmac deleted the clang-format branch February 27, 2024 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants