Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • openairinterface5G openairinterface5G
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 65
    • Issues 65
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 47
    • Merge requests 47
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • oaioai
  • openairinterface5Gopenairinterface5G
  • Merge requests
  • !785

Add .clang-format file

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Robert Schmidt requested to merge feature-support-clang-format into develop Mar 10, 2020
  • Overview 65
  • Commits 8
  • Pipelines 0
  • Changes 12

I propose to add a clang-format configuration file, notably since it allows to configure a range of lines of a file instead of the whole file only. Documentation of the options: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Integration into editors

Integration into various editors (vim, emacs, VSCode, CLion) is on the project page: https://clang.llvm.org/docs/ClangFormat.html

There is an eclipse plugin: https://github.com/wangzw/CppStyle

Integration into git

See here for a more detailed explanation. In short: Add this to ~/.gitconfig:

[clangFormat]
	binary = clang-format-12
	style = file

Now stage files for reformatting, then run git clang-format. It will reformat only the code that is staged, and you can the view what with a git diff (thus, the modified lines are not automatically staged).

There is also a pre-commit hook that you can install in file pre-commit-clang. See the file for instructions of how to use.

Differences to current astyle:

  • I believe astyle aligns assignments. The clang-format file does not do this, and would need to have AlignConsecutiveAssignments set to true. Example:
int aaaa = 12;
int b    = 23;
int ccc  = 23;
  • Also, the astyle configuration mandates to break lines after a logical, but the current clang format file does it before. Should we keep the astyle behavior? Option BreakBeforeBinaryOperators
if (thisVariable1 == thatVariable1 ||
        thisVariable2 == thatVariable2 ||
        thisVariable3 == thatVariable3)
    bar();

vs.

if (thisVariable1 == thatVariable1
        || thisVariable2 == thatVariable2
        || thisVariable3 == thatVariable3)
    bar();
Edited Aug 28, 2022 by Robert Schmidt
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: feature-support-clang-format