summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-17 00:11:56 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-17 13:34:23 -0600
commit1efe4e42745d79546160a581e1487c5c2f02d6bb (patch)
treedfa5f3aca9a0059b3d827795913dc24fe5d3d171
parent42fb27570262b52e2ca889030c621b5f4af76fe1 (diff)
wip clang-formatlukeshu/clang-format
-rw-r--r--.clang-format49
-rw-r--r--.editorconfig5
-rw-r--r--.yamlfmt.yml30
-rw-r--r--GNUmakefile7
4 files changed, 90 insertions, 1 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..686a068
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,49 @@
+---
+# .clang-format - How to format C files in sbc-harness
+#
+# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+# https://releases.llvm.org/19.1.0/tools/clang/docs/ClangFormatStyleOptions.html
+
+Language: Cpp # "C" didn't become a value until clang 20; I'm still on clang 19.1
+BasedOnStyle: LLVM
+LineEnding: LF
+ColumnLimit: 0
+
+# Indentation
+UseTab: AlignWithSpaces
+TabWidth: 8
+IndentWidth: 8
+ContinuationIndentWidth: 8
+IndentCaseLabels: false
+
+# Brace style
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortIfStatementsOnASingleLine: AllIfsAndElse
+BreakBeforeBraces: Attach
+Cpp11BracedListStyle: false
+
+# Alignment
+AlignConsecutiveAssignments:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: true
+ PadOperators: true
+AlignConsecutiveDeclarations:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: true
+ AlignFunctionPointers: true
+AlignConsecutiveShortCaseStatements:
+ Enabled: true
+
+# Preprocessor
+AlignConsecutiveMacros:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: true
+AlignEscapedNewlines: Left
+IndentPPDirectives: BeforeHash
+PPIndentWidth: -1 # inherit from IndentWidth
+SortIncludes: CaseSensitive
diff --git a/.editorconfig b/.editorconfig
index d2b92ed..5eed39e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -37,6 +37,11 @@ indent_size = 4
[requirements.txt]
_mode = pip
+[{*.yml,.clang-format}]
+_mode = yaml
+indent_style = space
+indent_size = 4
+
[{.editorconfig,.gitmodules,.pylintrc}]
_mode = ini
diff --git a/.yamlfmt.yml b/.yamlfmt.yml
new file mode 100644
index 0000000..b9672ef
--- /dev/null
+++ b/.yamlfmt.yml
@@ -0,0 +1,30 @@
+---
+# .yamlfmt.yml - How to format YAML files in sbc-harness
+#
+# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-Licence-Identifier: AGPL-3.0-or-later
+
+# Format options
+formatter:
+ type: basic
+ # Newlines
+ line_ending: lf
+ eof_newline: true
+ retain_line_breaks: false
+ retain_line_breaks_single: true
+ scan_folded_as_literal: false
+ # Indentation
+ indent: 4
+ indentless_arrays: false
+ # Other whitespace
+ pad_line_comments: 1
+ trim_trailing_whitespace: true
+ # Other
+ include_document_start: true
+ disallow_anchors: true
+ drop_merge_tag: false
+ max_line_length: 70
+
+# Program operation
+continue_on_error: false
+output_format: default
diff --git a/GNUmakefile b/GNUmakefile
index 9836b33..e56b353 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -130,7 +130,10 @@ lint/unknown: lint/%: build-aux/lint-unknown
.PHONY: lint lint/%
# specific #########
lint/c: lint/%: build-aux/lint-h build-aux/get-dscname
+ clang-format -Werror --dry-run -- $(sources_$*)
./build-aux/lint-h $(filter %.h,$(sources_$*))
+lint/yaml: lint/%:
+ yamlfmt -lint $(sources_$*)
lint/sh lint/bash: lint/%:
shellcheck $(sources_$*)
shfmt --diff --case-indent --simplify $(sources_$*)
@@ -151,7 +154,9 @@ format:
.PHONY: format format/%
# specific #########
format/c: format/%:
- @: TODO: Adopt a C code-formatter
+ clang-format -Werror -i -- $(sources_$*)
+format/yaml: format/%:
+ yamlfmt $(sources_$*)
format/sh format/bash: format/%:
shfmt --write --case-indent --simplify $(sources_$*)
format/python3: format/%: ./build-aux/venv