Skip to content

Commit

Permalink
meta: add clang-format formatting configuration
Browse files Browse the repository at this point in the history
This allows for voluntary formatting with clang-format (or
IDE tools like clang-format plugin for VS Code).

Once a suitable formatting configuration is found, automatic formatting
can be configured

Tweaked by Jakub Jelen
  • Loading branch information
martinpaljak authored and frankmorgner committed Jan 23, 2024
1 parent bc205ae commit 70aac71
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
BasedOnStyle: LLVM
# defaults from LLVM
# BreakBeforeBraces: Attach
# AllowShortIfStatementsOnASingleLine: Never
# IndentCaseLabels: false
# AlignAfterOpenBracket: Align
# AlignTrailingComments: true
# MaxEmptyLinesToKeep: 1
# ReflowComments: falsedefault
# SortIncludes: true
# BreakBeforeBinaryOperators: None
# BraceWrapping:
# AfterClass: false
# AfterControlStatement: false
# AfterFunction: false
# AfterNamespace: false
# BeforeCatch: false
# BeforeElse: false
# IndentBraces: false

# OpenSC modifications
TabWidth: 8
IndentWidth: 8
ContinuationIndentWidth: 16
AlignAfterOpenBracket: DontAlign
UseTab: Always
AlignConsecutiveMacros: true
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: None
AlwaysBreakAfterReturnType: AllDefinitions
## This prevents reflowing intentionally short lines but
## it can be allowed only after we will have some baseline
ColumnLimit: 0
#ColumnLimit: 110
IndentCaseBlocks: false
AlignArrayOfStructures: Left

BreakBeforeBraces: Custom
BraceWrapping:
AfterObjCDeclaration: true
AfterUnion: true
AfterFunction: true
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Formatting style

The OpenSC formatting rules are described in `.clang-format` in the root
directory. It is based on [LLVM](https://llvm.org/docs/CodingStandards.html)
style with couple of modifications:

* Tabs
* Tabs are used instead of spaces
* Tab is 8 spaces wide
* The maximum line width is 110 characters
* Opening braces follow the condition/expression except for the functions

Examples:

```
void
function_name(int arg)
{
int var = 0;
int rc = 0;
if (arg) {
var = do_something();
}
if (rc = call_some_function(arg) ||
rc = call_some_other_long_funct(arg) ||
rc = call_one_more_func(arg)) {
/* Note the two Tabs on the line above ! */
return rc;
}
return var;
}
```

To check your changes if they follow the formatting style (before submitting
a PR), you can use `clang-format` tool or `git-clang-format`, which can check
only the parts of the code you changed in your branch

```
$ git-clang-format --diff --commit upstream/master
```

# Testing locally

To learn how to run the tests from Github actions locally in containers, see
Expand Down

0 comments on commit 70aac71

Please sign in to comment.