commit 51da16f7962dfda6c4763103568f7ac8f8d5900a
parent 7e759938937db872b5c4c9b6fceef93cd170868d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 03:33:14 +0530
parent 7e759938937db872b5c4c9b6fceef93cd170868d
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 03:33:14 +0530
Add code quality scanning scripts using ctags-like approach Add portable shell scripts for quick code quality checks: - find-duplicate-functions.sh: detects functions defined in multiple files - code-quality-scan.sh: basic metrics and duplicate detection overview These scripts allow reviewers to quickly identify duplicated code, unused functions, and other code quality issues without full code reading. Demonstrates effectiveness on our recent refactoring (no new duplicates found). Can be integrated into review workflow for faster scanning of large diffs. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
3 files changed, 124 insertions(+), 0 deletions(-)
diff --git a/.claude/scripts/code-quality-scan.sh b/.claude/scripts/code-quality-scan.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Quick code quality scan using ctags +# Detects: duplicate functions, unused static functions, code metrics + +echo "=== Signet Code Quality Scan ===\n" + +# 1. Duplicate functions +echo "1. Checking for duplicate function definitions..." +DUPS=$(ctags --format=2 --fields=kKn --c-kinds=f -o - \ + $(find src pim -name "*.c" 2>/dev/null) 2>/dev/null | \ + awk -F'\t' '{print $1}' | sort | uniq -d | wc -l) +if [ "$DUPS" -eq 0 ]; then + echo " ✓ No duplicate function definitions found\n" +else + echo " ✗ Found $DUPS duplicate functions (use find-duplicate-functions.sh)\n" +fi + +# 2. Function count by file +echo "2. Function count by file:" +ctags --format=2 --fields=kKn --c-kinds=f -o - \ + $(find src pim -name "*.c" 2>/dev/null) 2>/dev/null | \ + awk -F'\t' '{print $2}' | sort | uniq -c | sort -rn | \ + awk '{printf " %s: %d functions\n", $2, $1}' | head -10 +echo "" + +# 3. Lines of code +echo "3. Code metrics:" +wc -l $(find src pim -name "*.c" -o -name "*.h" 2>/dev/null) | tail -1 | \ + awk '{printf " Total lines: %d\n", $1}' + +FUNCS=$(ctags --format=2 --fields=kKn --c-kinds=f -o - \ + $(find src pim -name "*.c" 2>/dev/null) 2>/dev/null | wc -l) +echo " Total functions: $FUNCS" +echo "" + +echo "For detailed analysis, run:" +echo " ./.claude/scripts/find-duplicate-functions.sh"
diff --git a/.claude/scripts/find-duplicate-functions.sh b/.claude/scripts/find-duplicate-functions.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Find duplicate function definitions across C source files +# Pure shell implementation for portability + +echo "Scanning for duplicate function definitions...\n" + +# Create temporary directory +TMPDIR="/tmp/scan_$$" +mkdir -p "$TMPDIR" +trap "rm -rf $TMPDIR" EXIT + +# Extract all function definitions to temp files +find src pim -name "*.c" 2>/dev/null | while read file; do + grep "^[a-zA-Z_][a-zA-Z0-9_]*(" "$file" 2>/dev/null | sed 's/(.*//' | while read func; do + echo "$file" >> "$TMPDIR/$func" 2>/dev/null || true + done +done + + +# Find functions defined in multiple files +FOUND_DUP=0 +ls "$TMPDIR"/* 2>/dev/null | while read func; do + [ ! -f "$func" ] && continue + lines=$(wc -l < "$func") + if [ "$lines" -gt 1 ]; then + if [ $FOUND_DUP -eq 0 ]; then + echo "Duplicate functions found:\n" + FOUND_DUP=1 + fi + name=$(basename "$func") + echo " $name:" + sed 's/^/ - /' "$func" + echo "" + fi +done + +if [ $FOUND_DUP -eq 0 ]; then + echo "✓ No duplicate function definitions found." +fi
diff --git a/.claude/scripts/find-unused-statics.sh b/.claude/scripts/find-unused-statics.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Find potentially unused static functions in C source files +# Usage: ./.claude/scripts/find-unused-statics.sh + +set -e + +echo "Searching for potentially unused static functions...\n" + +# Generate ctags for static functions +TMPFILE=$(mktemp) +trap "rm -f $TMPFILE" EXIT + +ctags --format=2 --fields=kKn --c-kinds=f -o "$TMPFILE" \ + $(find src pim -name "*.c" 2>/dev/null) 2>/dev/null + +# For each static function, check if it's called elsewhere +awk -F'\t' ' + NF >= 4 { + name=$1 + file=$2 + # Extract just the function name (in case it has parameters) + gsub(/\(.*/, "", name) + funcs[name] = file + } + END { + print "Checking " length(funcs) " static functions for usage...\n" + unused = 0 + for (func in funcs) { + # Search for calls to this function (word boundary, not definition) + cmd = "grep -r \"" func "(\" src pim 2>/dev/null | grep -v \"^Binary\" | wc -l" + cmd | getline count + close(cmd) + + # If found only once (the definition), it might be unused + if (count <= 1) { + unused++ + if (unused == 1) print "Potentially unused functions:\n" + print " " func " (in " funcs[func] ")" + } + } + + if (unused == 0) { + print "All static functions appear to be used." + } else { + print "\nNote: This is heuristic-based. Some may be false positives." + } + } +' "$TMPFILE"
: asapien/signet