mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 16:23:04 +02:00
3.0 KiB
3.0 KiB
C Language Linter Setup for imageViewer Project
This directory contains a comprehensive linting setup for the imageViewer C project.
Tools Included
1. clang-tidy - Static Analysis
- Configuration:
.clang-tidy - Checks for bugs, performance issues, and style violations
- Enforces modern C coding standards
2. clang-format - Code Formatting
- Configuration:
.clang-format - Automatically formats code to consistent style
- 100-character line limit, 4-space indentation
3. cppcheck - Additional Static Analysis
- Detects memory leaks, null pointer dereferences
- Checks for undefined behavior
4. gcc with warnings - Compiler Analysis
- Comprehensive warning flags
- Standards compliance checking
Usage
Quick Start
# Install dependencies (Arch Linux)
make deps-arch
# Run all lint checks
make lint
# Format code
make format
# Run all checks
make check
# Check for memory leaks
make memcheck
Individual Commands
# Manual linting
./lint.sh
# Format specific file
clang-format -i main.c
# Run clang-tidy
clang-tidy main.c -- -I/usr/include/SDL2 -D_REENTRANT
# Run cppcheck
cppcheck --enable=all main.c
VS Code Integration
The .vscode/settings.json file provides:
- Automatic formatting on save
- C99 standard compliance
- IntelliSense configuration for SDL2
- Integrated linting with clang-tidy and cppcheck
Recommended Extensions for VS Code
- C/C++ (Microsoft)
- clang-tidy (mine-cetinkaya-fianso)
- cppcheck (unixwrapped)
Linting Rules
Enabled Checks
- clang-diagnostic-*: Compiler diagnostics
- clang-analyzer-*: Static analysis
- bugprone-*: Bug-prone patterns
- cert-*: CERT secure coding standards
- misc-*: Miscellaneous checks
- performance-*: Performance improvements
- portability-*: Cross-platform issues
- readability-*: Code readability
Disabled Checks
readability-magic-numbers: Allows constants like window dimensionscert-err33-c: Allows ignoring some function return valuesmisc-unused-parameters: Common in callback functions
Code Quality Workflow
- Write Code: Develop features in
main.c - Lint: Run
make lintto check for issues - Format: Run
make formatto fix formatting - Build: Run
maketo compile - Test: Run
make testwith sample images - Memory Check: Run
make memcheckfor leak detection
Configuration Files
.clang-tidy: Static analysis rules.clang-format: Code formatting style.vscode/settings.json: VS Code integrationlint.sh: Comprehensive linting scriptMakefile: Build and quality targets
Installation on Different Systems
Arch Linux
sudo pacman -S clang cppcheck valgrind
Ubuntu/Debian
sudo apt install clang-tidy cppcheck clang-format valgrind
Fedora/RHEL
sudo dnf install clang-tools-extra cppcheck clang valgrind
This setup ensures high code quality, consistency, and helps catch potential issues early in development.