Skip to content

Add code formatters for Telemetry #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions telemetry/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Options: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Google
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
ColumnLimit: 80
IndentWidth: 4
UseTab: Never
33 changes: 33 additions & 0 deletions telemetry/.githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
set -e

# Header
printf "\n"
printf "=====================================\n"
printf " FS-3 Telemetry Code Checks \n"
printf "=====================================\n"

# Get staged files
FILES=$(git diff --cached --name-only --diff-filter=ACM)
FORMATTABLE_FILES=$(printf "%s\n" "$FILES" | grep -E '\.(c|cpp|h|hpp)$' || true)

# Check if there are any files to format
if [ -z "$FORMATTABLE_FILES" ]; then
printf "✅ No files to format. You're good to go!\n\n"
exit 0
fi

TOTAL=$(printf "%s\n" "$FORMATTABLE_FILES" | wc -l | tr -d ' ')

# Format loops
INDEX=1
printf "%s\n" "$FORMATTABLE_FILES" | while IFS= read -r FILE; do
TOOL="🎨 clang-format"
clang-format -i "$FILE" >/dev/null 2>&1
git add "$FILE"
printf "[%d/%d] %s: %s\n" "$INDEX" "$TOTAL" "$TOOL" "$FILE"
INDEX=$((INDEX + 1))
done

# Final message
printf "\n✅ All formatted! Pre-commit complete.\n"
6 changes: 6 additions & 0 deletions telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# FS-3 Telemetry

## Setup (git hooks)
1. `chmod +x setup-hooks.sh`
2. `./setup-hooks.sh`
3. Go ahead and `git add <files>` and `git commit`!
31 changes: 31 additions & 0 deletions telemetry/setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
set -e

HOOK_SOURCE="telemetry/hooks/pre-commit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be blind but I think this is the wrong filepath? The other PR you made had the right one i think

HOOK_TARGET=".git/hooks/pre-commit"

echo "🛠️ FS-3 Telemetry: Pre-Commit Hook Setup"

# Does source hook exist?
if [ ! -f "$HOOK_SOURCE" ]; then
echo "❌ Error: Cannot find hook source at $HOOK_SOURCE"
exit 1
fi

# Create .git/hooks if needed
if [ ! -d ".git/hooks" ]; then
echo "📂 Creating .git/hooks directory..."
mkdir -p .git/hooks
fi

# Symlink the hook
echo "🔗 Linking $HOOK_SOURCE → $HOOK_TARGET"
ln -sf "../../$HOOK_SOURCE" "$HOOK_TARGET"

# Make it executable
echo "🔒 Making hook executable"
chmod +x "$HOOK_TARGET"

# Finish up
echo "✅ Pre-commit hook installed!"
echo "🚦 Try staging a file and running: git commit -m 'Test'"