C/C++ Lint Workflow Guide
π C/C++ Code Quality Checks
The C/C++ Lint workflow runs clang-format and clang-tidy using cpp-linter for code quality enforcement.
π Table of Contents
π― Overview
Purpose : C/C++ code quality enforcement using cpp-linter-action
Key Features :
clang-format for code style
clang-tidy for static analysis
PR annotations and comments
Configurable file extensions
Configurable exclude paths
Direct integration with cpp-linter/cpp-linter-action@v2
Use Case : Code style consistency and quality enforcement
π§ Clang Configuration
Input
Type
Required
Default
Description
clang_version
string
β
20
Clang major version
style
string
β
"file"
clang-format style (llvm, google, webkit, or βfileβ to use .clang-format)
tidy_checks
string
β
""
clang-tidy checks (comma-separated glob patterns, use - prefix to disable)
π File Selection
Input
Type
Required
Default
Description
extensions
string
β
"c,cpp,cc,cxx,h,hpp"
File extensions to check (comma-separated)
ignore
string
β
"build\|.git"
Files or directories to exclude from linting (pipe-separated)
files_changed_only
boolean
β
false
Only lint files that have been changed in the pull request
lines_changed_only
boolean
β
false
Only inspect lines that have changed in the pull request
π Output Options
Input
Type
Required
Default
Description
step_summary
boolean
β
true
Add a summary of linting results to the workflow step summary
file_annotations
boolean
β
true
Display linting errors and warnings as file annotations in the GitHub UI
thread_comments
boolean
β
false
Post a collapsible thread comment in pull requests with linting issues
π€ Outputs
Output
Description
PR annotations
File-level annotations for style issues
PR comments
Summary comments with issue counts
Step summary
Workflow step summary with linting results
π Usage Examples
Basic Usage
1
2
3
4
5
jobs :
lint :
uses : N3b3x/hf-general-ci-tools/.github/workflows/c-cpp-lint.yml@v1
with :
clang_version : " 20"
Custom File Extensions
1
2
3
4
5
6
jobs :
lint :
uses : N3b3x/hf-general-ci-tools/.github/workflows/c-cpp-lint.yml@v1
with :
extensions : " c,cpp,h,hpp,cc,cxx"
clang_version : " 18"
Custom Exclude Paths
1
2
3
4
5
6
jobs :
lint :
uses : N3b3x/hf-general-ci-tools/.github/workflows/c-cpp-lint.yml@v1
with :
ignore : " build|.git|third_party|vendor|test"
clang_version : " 20"
Advanced Configuration
1
2
3
4
5
6
7
8
9
10
11
jobs :
lint :
uses : N3b3x/hf-general-ci-tools/.github/workflows/c-cpp-lint.yml@v1
with :
clang_version : " 20"
style : " google" # Use Google style instead of .clang-format file
tidy_checks : " readability-*,performance-*,modernize-*" # Specific checks
extensions : " c,cpp,h,hpp"
ignore : " build|.git|third_party"
files_changed_only : true # Only check changed files in PRs
thread_comments : true # Post collapsible thread comments
1
2
3
4
5
6
7
8
9
10
11
jobs :
lint :
uses : N3b3x/hf-general-ci-tools/.github/workflows/c-cpp-lint.yml@v1
with :
clang_version : " 20"
files_changed_only : true # Only lint changed files
lines_changed_only : true # Only check changed lines
ignore : " build|.git|third_party|vendor" # Exclude more directories
step_summary : true # Show summary in workflow
file_annotations : true # Show inline annotations
thread_comments : false # Disable thread comments for performance
π§ Linting Behavior
The workflow provides:
Code Style Checking : clang-format checks for style violations
Static Analysis : clang-tidy performs static analysis checks
PR Feedback : Annotations and comments on pull requests
Configurable Scope : Control which files and paths are checked
Performance Options : Check only changed files/lines for faster runs
File Annotations : Provides PR annotations for linting issues
β οΈ Important Notes
Permissions Required : The workflow needs pull-requests: write permission for PR comments
File Discovery : The action automatically discovers C/C++ files in your repository
Configuration Files : Uses .clang-format and .clang-tidy files if present
βοΈ Configuration
Create a .clang-format file in your project root:
1
2
3
4
BasedOnStyle : Google
IndentWidth : 2
ColumnLimit : 100
AccessModifierOffset : -2
.clang-tidy
Create a .clang-tidy file for static analysis:
1
2
3
Checks : ' *,readability-*,performance-*,modernize-*'
WarningsAsErrors : ' '
HeaderFilterRegex : ' '
π§ Troubleshooting
Common Issues
Style Issues Not Detected
Verify .clang-format exists and is valid
Check file extensions are included
Ensure paths match your project structure
Clang Version Issues
Use supported versions (18, 19, 20)
Check cpp-linter compatibility
Next: Static Analysis Workflow β