From 8f6650919dbafc7dc9079723bd62bcbd1527e2c7 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 3 Apr 2026 14:03:01 +0300 Subject: [PATCH] chore: setup clang-format for formatting Signed-off-by: NotAShelf Change-Id: I322b7dd5dcd699247b58fe9f5db7bcd86a6a6964 --- .clang-format | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 16 +++++++- nix/shell.nix | 10 ++++- 3 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..39ef087 --- /dev/null +++ b/.clang-format @@ -0,0 +1,100 @@ +# Based on LLVM style with project-specific adjustments +--- +Language: C + +# Indentation +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +IndentCaseLabels: false +IndentPPDirectives: None + +# Line length +ColumnLimit: 120 + +# Braces +BreakBeforeBraces: Attach +BraceWrapping: + AfterFunction: false + AfterControlStatement: false + AfterEnum: false + AfterStruct: false + AfterUnion: false + BeforeElse: false + IndentBraces: false + +# Alignment +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +PointerAlignment: Right + +# Spacing +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Line breaks +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakStringLiterals: true +ContinuationIndentWidth: 4 + +# Includes +IncludeBlocks: Preserve +SortIncludes: false + +# Comments +ReflowComments: true +SpacesBeforeTrailingComments: 2 + +# Other +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +SpaceAfterTemplateKeyword: true +SpaceBeforeInheritanceColon: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpacesInAngles: false +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TypenameMacros: + - STACK_OF + - LIST + - DECLARE_STACK_OF + - DECLARE_LIST + - IMPLEMENT_STACK_OF + - IMPLEMENT_LIST diff --git a/Makefile b/Makefile index 096ca87..607167e 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ OBJDIR := obj SOURCES := $(wildcard $(SRCDIR)/*.c) OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES)) -.PHONY: all clean +.PHONY: all clean format format-check all: $(TARGET) @@ -29,3 +29,17 @@ clean: # Alias for development dev: all ./$(TARGET) + +# Format all source files with clang-format +fmt: + @command -v clang-format >/dev/null 2>&1 || { echo "Error: clang-format is missing"; exit 1; } + @echo "Formatting source files..." + @clang-format -i $(SOURCES) $(wildcard $(SRCDIR)/*.h) + @echo "Done formatting." + +# Check formatting without modifying files +fmt-check: + @command -v clang-format >/dev/null 2>&1 || { echo "Error: clang-format is missing"; exit 1; } + @echo "Checking formatting..." + @clang-format --dry-run --Werror \ + $(SOURCES) $(wildcard $(SRCDIR)/*.h) && echo "All files properly formatted." || { echo "Formatting issues found. Run 'make fmt' to fix."; exit 1; } diff --git a/nix/shell.nix b/nix/shell.nix index c30fba3..e51be03 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -7,10 +7,16 @@ }: mkShell { strictDeps = true; - buildInputs = [ + packages = [ clang-tools - raylib gnumake + ]; + + buildInputs = [ + raylib + ]; + + nativeBuildInputs = [ pkg-config ]; }