Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Master] Clang-format description on a wiki #20612

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/static_site/src/pages/community/clang_format_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
layout: page
title: Clang format
subtitle: Clang format in MXNet codebase for reviewers and contributors.
action: Contribute
action_url: /community/index
permalink: /community/code_guide
---
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
<!--- or more contributor license agreements. See the NOTICE file -->
<!--- distributed with this work for additional information -->
<!--- regarding copyright ownership. The ASF licenses this file -->
<!--- to you under the Apache License, Version 2.0 (the -->
<!--- "License"); you may not use this file except in compliance -->
<!--- with the License. You may obtain a copy of the License at -->

<!--- http://www.apache.org/licenses/LICENSE-2.0 -->

<!--- Unless required by applicable law or agreed to in writing, -->
<!--- software distributed under the License is distributed on an -->
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
<!--- KIND, either express or implied. See the License for the -->
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->

Clang-format Guide and Tips
===================

This wiki page describes how to set up clang-format tool as a part of your worklow. Running the command given in the description will fix clang-format problem.


- Add `tools/lint/git-clang-format-13 ` to your `$PATH`. Once its added to your `$PATH`, running `git clang-format` will invoke it.
```bash
git clang-format
```


- To reformat chosen file just do:
```bash
# `_FILE_NAME_` is the name of a file to be formatted.
# i - apply edits to files instead of displaying a diff
clang-format -i _FILE_NAME_
```

- To reformat all the lines in the latest git commit, just do:
```bash
git diff -U0 --no-color HEAD^ | clang-format-diff.py -i -p1

```

- If you want to apply clang-format only to the changed lines in each commit do the following:
```bash
# If it's a child of origin/master, the following command-line could be used:
# If you want to run this command on another brnach, then origin/master needs to be replaced.
export COMMIT_SHA=$(git rev-list --ancestry-path origin/master..HEAD | tail -n 1)

git filter-branch --tree-filter 'git-clang-format $COMMIT_SHA^' -- $COMMIT_SHA..HEAD
```
2 changes: 1 addition & 1 deletion docs/static_site/src/pages/community/code_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contributing and process.
C++ Code Styles
---------------

- Use the [Google C/C++ style](https://google.github.io/styleguide/cppguide.html).
- Use the [clang-format]({% link pages/community/clang_format_guide.md %}) to reformat your code.
- The public facing functions are documented in [doxygen](https://www.doxygen.nl/manual/docblocks.html) format.
- Favor concrete type declaration over `auto` as long as it is short.
- Favor passing by const reference (e.g. `const Expr&`) over passing
Expand Down
2 changes: 1 addition & 1 deletion docs/static_site/src/pages/community/pull_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ detailed guidelines.
```

- Make sure code style check pass by typing the following command, and
all the existing test-cases pass.
all the existing test-cases pass. Use the [clang-format]({% link pages/community/clang_format_guide.md %}) to reformat your code.

```bash
# Reproduce the lint procedure in the CI.
Expand Down