Skip to content
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
195 changes: 195 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
Language: Cpp
BasedOnStyle: Google
Standard: c++20


# Characters per line
ColumnLimit: 120


# Do not wrap comments according to ColumnLimit
ReflowComments: false


# Indentation
IndentWidth: 4
AccessModifierOffset: -4
UseTab: false

# Keep up to 2 empty lines
MaxEmptyLinesToKeep: 2


# sort and group includes: c++, system, project
SortIncludes: true
IncludeBlocks: Regroup
IncludeCategories:
# C++ Standard Library headers
- Regex: '<[[:alnum:]_-]+>'
Priority: 5
# system libraries
- Regex: '<.+>'
Priority: 4
# project includes - libdnf5 absolute paths
- Regex: '"libdnf5/.+"'
Priority: 3
# project includes - libdnf5-cli absolute paths
- Regex: '"libdnf5-cli/.+"'
Priority: 2
# project includes
- Regex: '".+"'
Priority: 1


# Always break after an open bracket, if the parameters don't fit on a single line, e.g.:
#
# someLongFunction(
# argument1, argument2);
#
AlignAfterOpenBracket: AlwaysBreak


# Forbid simple braced statements on a single line.
#
# Allowed:
# if (a) {
# return;
# }
#
# Forbidden:
# if (a) { return; }
#
AllowShortBlocksOnASingleLine: false


# Forbid short case labels on a single line.
#
# Allowed:
# switch (a) {
# case 1:
# x = 1;
# break;
# }
#
# Forbidden:
# switch (a) {
# case 1: x = 1; break;
# case 2: return;
# }
#
AllowShortCaseLabelsOnASingleLine: false


# Allow only single line methods defined inside a class.
#
# Allowed:
# class Foo {
# void f() { foo(); }
# };
# void f() {
# foo();
# }
#
# Forbidden:
# void f() { foo(); }
AllowShortFunctionsOnASingleLine: Inline


# Forbid if statements on a single line.
#
# Allowed:
# if (a)
# return ;
# else {
# return;
# }
#
# Forbidden:
# if (a) return;
# else
# return;
#
AllowShortIfStatementsOnASingleLine: Never


# Forbid loops on a single line.
#
# Allowed:
# while (i < 1) {
# i--;
# }
#
# Forbidden:
# while (i < 1) i--;
#
AllowShortLoopsOnASingleLine: false


# Force middle pointer alignment.
#
# Examples:
# char * str;
# const std::string & str;
#
DerivePointerAlignment: false
PointerAlignment: Middle


# Allow only one argument/parameter per line.
#
# Allowed:
# void f(int aaaaaaaaaaaaaaaaaaaa,
# int aaaaaaaaaaaaaaaaaaaa,
# int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
#
# Forbidden:
# void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
# int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
#
BinPackArguments: false
BinPackParameters: false


# If the function declaration doesn't fit on a line, put all parameters on the next line.
#
# Allowed:
# void myFunction(
# int a, int b, int c, int d, int e);
#
# Forbidden:
# void myFunction(int a,
# int b,
# int c,
# int d,
# int e);
#
AllowAllParametersOfDeclarationOnNextLine: true


# Allow only per line constructor intitializers.
#
# Allowed:
# MyClass::MyClass()
# : member0(0)
# , member1(2)
#
# Forbidden:
# MyClass::MyClass() :
# member0(0), member1(2)
#
AllowAllConstructorInitializersOnNextLine: false
BreakConstructorInitializers: BeforeColon


# Align consecutive C/C++ preprocessor macros.
#
# Example:
# #define SHORT_NAME 42
# #define LONGER_NAME 0x007f
# #define EVEN_LONGER_NAME (2)
# #define foo(x) (x * x)
# #define bar(y, z) (y + z)
#
AlignConsecutiveMacros: true
...
31 changes: 31 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
Checks: 'bugprone-*,cert-*,concurrency-*,cppcoreguidelines-*,misc-*,modernize-*,-modernize-use-trailing-return-type,-modernize-use-nodiscard,performance-*,portability-*,readability-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case

- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: '0'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: '1'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: '1'
...
3 changes: 2 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
David Cantrell <dcantrell@redhat.com> David Cantrell <dcantrell@burdell.org>
Dave Cantrell <dcantrell@redhat.com> David Cantrell <dcantrell@burdell.org>
Dave Cantrell <dcantrell@redhat.com> David Cantrell <dcantrell@redhat.com>
Jan Kolarik <jkolarik@redhat.com> kolage <110612307+jan-kolarik@users.noreply.github.com>
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-xml
- id: check-added-large-files
- id: check-merge-conflict
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.0
hooks:
- id: clang-format
types_or:
- c++
- repo: https://github.com/hhatto/autopep8
rev: v2.2.0
hooks:
- id: autopep8
args: [-i, --max-line-length=120]
- repo: https://github.com/rpm-software-management/rpmlint.git
rev: 2.5.0
hooks:
- id: rpmlint
# Passes if packit not installed. Needed for validation locally
- repo: https://github.com/packit/pre-commit-hooks
rev: v1.2.0
hooks:
- id: validate-config
37 changes: 37 additions & 0 deletions tools/clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

show_help() {
cat << EOF
Usage: $0 [PATHSPEC]...
Calls clang-format on git tree files. If there's a non-empty diff between the
working tree and HEAD (note, even if the diff is only on non-C/C++ sources),
clang-format is called only on C/C++ source files that contain changes. If
there are no changes in the working tree, calls clang-format on all C/C++
source files in git.

PATHSPEC is passed directly to the git commands used, it can specify
files or directories to run on.

Options:
-h, --help Show this help

EOF
exit 0
}

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
show_help
fi

# the tutorial files are snippets, not full sources, clang-format doesn't work well on them
EXCLUDE=":!:test/tutorial"

if [ -n "$(git diff --name-only)" ]; then
FILES=$(git diff --name-only -- "$@" ${EXCLUDE} | grep -E '\.(c|cpp|h|hpp)$')
else
FILES=$(git ls-files -- "$@" ${EXCLUDE} | grep -E '\.(c|cpp|h|hpp)$')
fi

for FILE in ${FILES} ; do
clang-format -i "${FILE}"
done
31 changes: 31 additions & 0 deletions tools/clang-tidy-changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
#
# run clang-tidy on new and modified files
# print the result and store it in clang-tidy-changed.log
#

TOPDIR=$(dirname "$(readlink -f "$0")")
LOG="${TOPDIR}/clang-tidy-changed.log"

# get upstream branch (incl. remote)
UPSTREAM_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}')

# list all changed files
CHANGED_FILES=$(git diff --name-only "${UPSTREAM_BRANCH}" | grep -E '\.(c|cpp|h|hpp)$')

# list all untracked files
UNTRACKED_FILES=$(git ls-files --others --exclude-standard | grep -E '\.(c|cpp|h|hpp)$')

for FILE in ${CHANGED_FILES} ${UNTRACKED_FILES}; do
echo "Checking ${FILE}..."
CHECKS=""

case "${FILE}" in
test/)
# exclude several checks failing due to cppunit
CHECKS="-llvm-header-guard,-readability-convert-member-functions-to-static,-cppcoreguidelines-owning-memory,-cert-err58-cpp"
;;
esac

clang-tidy "${FILE}" -checks="${CHECKS}" -- -std=c++17 -I"{$TOPDIR}/include" | tee -a "${LOG}"
done
Loading