Przejdź do treści
Biblioteka skilli
Programowanie · Przegląd i audyt

cpp-quality

/cpp-quality

Konfiguruje narzędzia analizy statycznej i formatowania C++: clang-tidy, clang-format, cppcheck i include-what-you-use, wraz z integracją w CI.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Konfiguruje narzędzia analizy statycznej i formatowania C++: clang-tidy, clang-format, cppcheck i include-what-you-use, wraz z integracją w CI.

Wyzwalacze z opisu

clang-tidyclang-formatcppcheckiwyuinclude-what-you-use.clang-tidy.clang-formatC++ static analysis
Oryginalny opis (EN)

C++ static analysis and formatting tooling: clang-tidy, clang-format, cppcheck, include-what-you-use (IWYU), and CI integration patterns. USE WHEN: user mentions "clang-tidy", "clang-format", "cppcheck", "iwyu", "include-what-you-use", ".clang-tidy", ".clang-format", "C++ static analysis", "C++ linter" DO NOT USE FOR: SonarQube C++ rules (tool-agnostic), Coverity (commercial), PVS-Studio (commercial)

Jak działa

  1. clang-format
  2. clang-tidy
  3. cppcheck (complementary, not a replacement)
  4. include-what-you-use (IWYU)
  5. Compiler warnings (the cheap layer underneath)
  6. CI pipeline (GitHub Actions sketch)
  7. Anti-Patterns
Sekcje z nagłówków SKILL.md, w oryginale · 180 linii, 624 słów
Podgląd SKILL.md
---
name: cpp-quality
description: |
  C++ static analysis and formatting tooling: clang-tidy, clang-format, cppcheck,
  include-what-you-use (IWYU), and CI integration patterns.

  USE WHEN: user mentions "clang-tidy", "clang-format", "cppcheck", "iwyu",
  "include-what-you-use", ".clang-tidy", ".clang-format", "C++ static analysis",
  "C++ linter"

  DO NOT USE FOR: SonarQube C++ rules (tool-agnostic), Coverity (commercial),
  PVS-Studio (commercial)
allowed-tools: Read, Grep, Glob, Write, Edit
---
# C++ Quality Tooling - Quick Reference

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `cpp-quality`.

## clang-format

Reformats source per a style file. Runs in milliseconds; safe to wire into pre-commit and editors.

`.clang-format`:
```yaml
---
BasedOnStyle: LLVM
Language: Cpp
Standard: c++20
ColumnLimit: 100
IndentWidth: 4
AccessModifierOffset: -4
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Attach
NamespaceIndentation: None
PointerAlignment: Left
SortIncludes: CaseInsensitive
IncludeBlocks: Regroup
SpaceAfterTemplateKeyword: false
```

Run:
```bash
clang-format -i src/**/*.cpp include/**/*.hpp
clang-format --dry-run --Werror src/foo.cpp        # CI: fail if not formatted
git ls-files '*.cpp' '*.hpp' | xargs clang-format -i
```

Choose a base (`LLVM`, `Google`, `Mozilla`, `Chromium`, `Microsoft`) and tweak — don't bikeshed style from scratch.

## clang-tidy

Linter + simple refactor tool driven by `compile_commands.json` (enable with `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)`).

`.clang-tidy`:
```yaml
---
Checks: >
  -*,
  bugprone-*,
  cert-*,
  clang-analyzer-*,
  concurrency-*,
  cppcoreguidelines-*,
  modernize-*,
  performance-*,
  portability-*,
  readability-*,
  -modernize-use-trailing-return-type,
  -readability-magic-numbers,
  -readability-identifier-length,
  -cppcoreguidelines-avoid-magic-numbers
WarningsAsErrors: '*'
HeaderFilterRegex: '^.*/(include|src)/.*\.(h|hpp)$'
FormatStyle: file
CheckOptions:
  - { key: readability-function-cognitive-complexity.Threshold, value: '25' }
  - { key: cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage, value: 'true' }
```

Run:
```bash
# Single file
clang-tidy -p build src/foo.cpp

# Whole project (parallelized)
run-clang-tidy -p build -quiet -header-filter='^.*/(include|src)/.*'

# Auto-apply fixes
run-clang-tidy -p build -fix -fix-errors

# CMake target
add_custom_target(tidy COMMAND run-clang-tidy -p ${CMAKE_BINARY_DIR})
```

### High-value check categories

| Category | What it catches |
|----------|-----------------|
| `bugprone-*` | Real defect patterns (use-after-move, sizeof on pointer, infinite loop) |
| `clang-analyzer-*` | Path-sensitive: null deref, leak, UB |
| `cppcoreguidelines-*` | Per the C++ Core Guidelines (ownership, narrowing, slicing) |
| `modernize-*` | Suggests modern equivalents (`nullptr`, `auto`, `make_unique`) |
| `performance-*` | Unnecessary copies, std::move misuse, string concat in loops |
| `concurrency-*` | Misuse of `std::thread`, `std::condition_variable` |
| `readability-*` | Naming, identifier conventions, redundant code |

### Suppressing

```cpp
// One line
int* p = (int*)x;  // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)

// Block
// NOLINTBEGIN(modernize-use-nodiscard)
int legacy_api();
// NOLINTEND(modernize-use-nodiscard)
```
Prefer fixing or disabling at config level for whole categories you don't want.

## cppcheck (complementary, not a replacement)

```bash
cppcheck --enable=warning,style,performance,portability \
         --inline-suppr --error-exitcode=2 \
         --project=build/compile_commands.json \
         --suppress=missingIncludeSystem \
         -i tests
```

Catches different patterns than clang-tidy (less path-sensitive but quicker; flags some uninitialized-member and dangling-reference issues clang-tidy misses).

## include-what-you-use (IWYU)

Reduces include bloat → faster builds + fewer accidental dependencies.

```bash
iwyu_tool.py -p build src/foo.cpp
fix_includes.py < iwyu.out                # auto-apply suggestions
```

Annotate to override:
```cpp
#include <vector>          // IWYU pragma: keep
class Foo;                 // IWYU pragma: forward_declare
```

## Compiler warnings (the cheap layer underneath)

```cmake
target_compile_options(mylib PRIVATE
    $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive- /w14640>
    $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
        -Wall -Wextra -Wpedantic -Werror
        -Wshadow -Wnon-virtual-dtor -Wold-style-cast
        -Wcast-align -Woverloaded-virtual -Wconversion -Wsign-conversion
        -Wnull-dereference -Wdouble-promotion -Wformat=2
    >
)
```

Don't skip this in favor of clang-tidy — compiler warnings are free and faster than any external tool.

## CI pipeline (GitHub Actions sketch)

```yaml
- name: Configure
  run: cmake --preset debug

- name: Format check
  run: |
    git ls-files '*.cpp' '*.hpp' | xargs clang-format --dry-run --Werror

- name: Build
  run: cmake --build --preset debug -j

- name: clang-tidy
  run: run-clang-tidy -p build/debug -quiet

- name: Test
  run: ctest --preset debug
```

## Anti-Patterns

| Anti-Pattern | Why It's Bad | Correct Approach |
|--------------|--------------|------------------|
| `WarningsAsErrors: '*'` then `// NOLINT` everywhere | Hides real issues | Disable check at config level instead |
| Running clang-tidy without `compile_commands.json` | Wrong include paths, false positives | Always pass `-p build/` |
| Reformatting whole repo in one PR | Murders `git blame` | One reformat commit, mark in `.git-blame-ignore-revs` |
| `-Wno-error=...` to ship faster | Tech debt that never returns | Fix the warning or `// NOLINT` with reason |
| Skipping warnings when adopting a third-party header | Future you will pay | Wrap with `#pragma GCC diagnostic push/ignored/pop` |
| Tidying generated code | Fights the generator | Exclude with `HeaderFilterRegex` or path globs |

Wersje

W bazie nie ma innych skilli o nazwie cpp-quality.

Migawka bazy z 13.11.2026 · wersja paczki 684aea787c62 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100cpp-static-analysis
    Uruchamia i interpretuje stos analizy statycznej dla C++: clang-format, clang-tidy, clang static analyzer, cppcheck, include-what-you-use i build ze sanitizerami, przed PR i scalaniem.
  • 100static-analysis
    Pomaga w analizie statycznej C i C++: clang-tidy, cppcheck i scan-build, tłumienie fałszywych alarmów oraz integracja z CI.
  • 100static-analysis
    Podnosi jakość kodu C/C++ z clang-tidy, cppcheck lub scan-build: interpretuje kategorie kontroli, wycisza fałszywe alarmy, integruje z CI i pracuje z compile_commands.json.
  • 100clang
    Wspiera pracę z kompilatorem Clang/LLVM w projektach C/C++: diagnostykę, sanitizery, raporty optymalizacji, clang-tidy, LTO z lld i migrację z GCC.
  • 100c-code-style
    Pisze, edytuje i recenzuje kod C oraz nagłówki zgodnie z regułami stylu kodowania, a potem sprawdza i uruchamia clang-format, by wymusić formatowanie.
  • 100clang
    Wspiera budowy C i C++ z clang: diagnostyka, uwagi optymalizacyjne, clang-tidy, ThinLTO z lld, LLVM PGO i migracja z GCC do Clang.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.