--- /dev/null
+---
+AlignAfterOpenBracket: 'Align'
+AlignConsecutiveAssignments: 'false'
+AlignConsecutiveDeclarations: 'false'
+AlignConsecutiveMacros: 'true'
+AlignOperands: 'true'
+AlignTrailingComments: 'true'
+AllowAllArgumentsOnNextLine: 'false'
+AllowAllParametersOfDeclarationOnNextLine: 'false'
+AllowShortBlocksOnASingleLine: 'false'
+AllowShortCaseLabelsOnASingleLine: 'false'
+AllowShortFunctionsOnASingleLine: 'Inline'
+AllowShortIfStatementsOnASingleLine: 'false'
+AlwaysBreakAfterReturnType: 'All'
+BinPackParameters: 'false'
+BinPackArguments: 'false'
+BreakBeforeBraces: 'Linux'
+ColumnLimit: '100'
+DerivePointerAlignment: 'false'
+IndentCaseLabels: 'false'
+IndentWidth: '8'
+IncludeBlocks: 'Regroup'
+KeepEmptyLinesAtTheStartOfBlocks: 'false'
+Language: 'Cpp'
+MaxEmptyLinesToKeep: '1'
+PointerAlignment: 'Right'
+SortIncludes: 'true'
+SpaceAfterCStyleCast: 'false'
+SpaceBeforeAssignmentOperators : 'true'
+SpaceBeforeParens: 'ControlStatements'
+SpaceInEmptyParentheses: 'false'
+SpacesInSquareBrackets: 'false'
+TabWidth: '8'
+UseTab: 'Always'
+
+PenaltyBreakAssignment: '3'
+PenaltyBreakBeforeFirstCallParameter: '15'
+
+IncludeCategories:
+ - Regex: '^"config.h"$'
+ Priority: '0'
+ - Regex: '<fwupdplugin.h>'
+ Priority: '1'
+ - Regex: '^<'
+ Priority: '2'
+ - Regex: 'fwupd'
+ Priority: '3'
+ - Regex: '.*'
+ Priority: '4'
+...
run: |
./contrib/setup
source venv/bin/activate
- sed -i "/no-commit-to-branch/d; /args: [--branch, main]/d" .pre-commit-config.yaml
+ sed -i "/no-commit-to-branch/,+1d" .pre-commit-config.yaml
pre-commit run --all-files
build:
- id: check-merge-conflict
- id: mixed-line-ending
args: [--fix=lf]
+- repo: https://github.com/codespell-project/codespell
+ rev: v2.1.0
+ hooks:
+ - id: codespell
+ args: ['--config', './contrib/codespell.cfg', --write-changes]
- repo: https://github.com/ambv/black
- rev: 20.8b1
+ rev: 21.6b0
hooks:
- id: black
- repo: local
language: system
entry: shellcheck --severity=error -e SC2068
types: [shell]
+ - id: clang-format
+ name: clang-format
+ language: script
+ entry: ./contrib/reformat-code.py
+ types: [c]
+- repo: https://github.com/igorshubovych/markdownlint-cli
+ rev: v0.27.1
+ hooks:
+ - id: markdownlint
+ args: ['--fix', '--ignore', '.github']
--- /dev/null
+[codespell]
+builtin = clear,informal,en-GB_to_en-US
+skip = *.po,*.csv,*.svg,*.p7c,subprojects,.git,pcrs,build*,.ossfuzz,*/tests/*
+ignore-words-list = conexant,Conexant,gir,GIR,hsi,HSI,cancelled,Cancelled,te
--- /dev/null
+#!/usr/bin/python3
+#
+# Copyright (C) 2017 Dell Inc.
+#
+# SPDX-License-Identifier: LGPL-2.1+
+#
+
+import os
+import sys
+import subprocess
+import argparse
+
+CLANG_DIFF_FORMATTERS = [
+ "clang-format-diff-11",
+ "clang-format-diff-13",
+ "clang-format-diff",
+]
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ description="Reformat C code to match project style",
+ epilog="Call with no argument to reformat uncommitted code.",
+ )
+ parser.add_argument(
+ "commit", nargs="*", default="", help="Reformat all changes since this commit"
+ )
+ parser.add_argument(
+ "--debug", action="store_true", help="Display all launched commands"
+ )
+ return parser.parse_args()
+
+
+def select_clang_version(formatters):
+ for formatter in formatters:
+ try:
+ ret = subprocess.check_call(
+ [formatter, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
+ )
+ if ret == 0:
+ return formatter
+ except FileNotFoundError:
+ continue
+ print("No clang formatter installed")
+ sys.exit(1)
+
+
+## Entry Point ##
+if __name__ == "__main__":
+ args = parse_args()
+ base = os.getenv("GITHUB_BASE_REF")
+ if base:
+ base = "origin/%s" % base
+ else:
+ if args.commit:
+ base = args.commit[0]
+ else:
+ base = "HEAD"
+ cmd = ["git", "describe", base]
+ if args.debug:
+ print(cmd)
+ ret = subprocess.run(cmd, capture_output=True)
+ if ret.returncode:
+ if args.debug:
+ print(ret.stderr)
+ base = "HEAD"
+ print("Reformatting code against %s" % base)
+ formatter = select_clang_version(CLANG_DIFF_FORMATTERS)
+ cmd = ["git", "diff", "-U0", base]
+ if args.debug:
+ print(cmd)
+ ret = subprocess.run(cmd, capture_output=True, text=True)
+ if ret.returncode:
+ print("Failed to run %s\n%s" % (cmd, ret.stderr.strip()))
+ sys.exit(1)
+ cmd = [formatter, "-p1"]
+ if args.debug:
+ print(cmd)
+ ret = subprocess.run(cmd, input=ret.stdout, capture_output=True, text=True)
+ if ret.returncode:
+ print("Failed to run %s\n%s" % (cmd, ret.stderr.strip()))
+ sys.exit(1)
+ cmd = ["patch", "-p0"]
+ if args.debug:
+ print(cmd)
+ ret = subprocess.run(cmd, input=ret.stdout, capture_output=True, text=True)
+ if ret.returncode:
+ print("Failed to run %s\n%s" % (cmd, ret.stderr.strip()))
+ sys.exit(1)
+ sys.exit(0)