-
Notifications
You must be signed in to change notification settings - Fork 3
Add centralized clang-tidy infrastructure #2
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
RSingh1511
wants to merge
4
commits into
eclipse-score:main
Choose a base branch
from
RSingh1511:rs/clang_tidy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8e7e595
fix review comments: fix clang-tidy yaml and remove issue templates
RSingh1511 f147fc8
Fix review comments: sanitizers.bazelrc bugs, restore lsan Rust suppr…
RSingh1511 fb9f64e
Remove sanitizer changes
RSingh1511 51989ec
fix review comments: update READMEs and drop defs.bzl thin wrapper
RSingh1511 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| --- | ||
| # Default clang-tidy configuration for S-CORE C++ modules. | ||
| # NOTE: the set of enabled checks is yet subject to be tailored per module. | ||
| Checks: >- | ||
| -*, | ||
| clang-analyzer-*, | ||
| cert-*, | ||
| cppcoreguidelines-*, | ||
| bugprone-*, | ||
| misc-*, | ||
| performance-*, | ||
| readability-*, | ||
| modernize-* | ||
| # NOTE: WarningsAsErrors is yet subject to be expanded per module as compliance increases. | ||
| WarningsAsErrors: >- | ||
| clang-analyzer-* | ||
| # Exclude third-party and generated headers from analysis. | ||
| HeaderFilterRegex: '^(?!.*/(third_party|bazel-out|external)/).*$' | ||
|
|
||
| FormatStyle: file | ||
|
|
||
| # NOTE: CheckOptions are yet subject to be provided for each enabled check per module. | ||
| #CheckOptions: | ||
| # none yet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| exports_files( | ||
| [ | ||
| ".clang-tidy", | ||
| "clang_tidy.bazelrc", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Clang-Tidy | ||
|
|
||
| Centralized clang-tidy configuration for Eclipse S-CORE C++ modules. | ||
|
|
||
| ## What This Provides | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `.clang-tidy` | Canonical S-CORE check set (conservative baseline, tailorable per module) | | ||
| | `clang_tidy.bazelrc` | Importable Bazel flags that activate the `clang-tidy` test config | | ||
|
|
||
| This module ships **policy assets**, not API wrappers. Consumers wire up | ||
| `lint_clang_tidy_aspect` / `lint_test` from `@aspect_rules_lint` directly — | ||
| exactly the same pattern used by the `sanitizers` module. | ||
|
|
||
| ## Setup (8 steps) | ||
|
|
||
| ### 1 — Add Bazel dependencies | ||
|
|
||
| In your `MODULE.bazel`: | ||
|
|
||
| ```python | ||
| bazel_dep(name = "score_cpp_policies", version = "<version>") | ||
| bazel_dep(name = "aspect_rules_lint", version = "2.5.0") | ||
| bazel_dep(name = "toolchains_llvm", version = "1.7.0") | ||
| ``` | ||
|
|
||
| Register an LLVM toolchain via the `llvm` extension (see `tests/MODULE.bazel` for a | ||
| minimal example). | ||
|
|
||
| ### 2 — Import `clang_tidy.bazelrc` | ||
|
|
||
| In your workspace `.bazelrc`: | ||
|
|
||
| ```bazelrc | ||
| import %workspace%/path/to/clang_tidy.bazelrc # if vendored locally | ||
| # — or, once Bazel supports external-repo imports — | ||
| # import %workspace%/../clang_tidy/clang_tidy.bazelrc | ||
| ``` | ||
|
|
||
| > **Tip**: If your repo layout places `score_cpp_policies` as a sibling (as in the | ||
| > `tests/` self-test workspace here), a relative `import` works. Otherwise vendor | ||
| > the three lines from `clang_tidy.bazelrc` into your own `.bazelrc`. | ||
|
|
||
| ### 3 — Create `tools/lint/BUILD.bazel` | ||
|
|
||
| ```python | ||
| # tools/lint/BUILD.bazel (empty package marker is sufficient) | ||
| ``` | ||
|
|
||
| ### 4 — Create `tools/lint/linters.bzl` | ||
|
|
||
| ```python | ||
| load("@aspect_rules_lint//lint:clang_tidy.bzl", "lint_clang_tidy_aspect") | ||
| load("@aspect_rules_lint//lint:lint_test.bzl", "lint_test") | ||
|
|
||
| clang_tidy_aspect = lint_clang_tidy_aspect( | ||
| binary = Label("@llvm_toolchain//:clang-tidy"), | ||
| configs = [ | ||
| Label("@score_cpp_policies//clang_tidy:.clang-tidy"), # central baseline | ||
| Label("//:.clang-tidy"), # local overrides (optional) | ||
| ], | ||
| lint_target_headers = True, | ||
| angle_includes_are_system = True, | ||
| ) | ||
|
|
||
| clang_tidy_test = lint_test(aspect = clang_tidy_aspect) | ||
| ``` | ||
|
|
||
| If you do not need per-module overrides, omit the `Label("//:.clang-tidy")` entry and | ||
| skip step 5. | ||
|
|
||
| ### 5 — (Optional) Add a local `.clang-tidy` override | ||
|
|
||
| Place a `.clang-tidy` at your repo root to extend or tighten the central check set. | ||
| Use [`@score_cpp_policies//clang_tidy:.clang-tidy`](.clang-tidy) as the starting point. | ||
|
|
||
| > **Advisory checks**: Checks in the `cppcoreguidelines-*` and `modernize-*` families are | ||
| > advisory (warnings only). Only `clang-analyzer-*` is `WarningsAsErrors` by default. | ||
| > Module owners should tighten `WarningsAsErrors` incrementally as compliance improves. | ||
|
|
||
| ### 6 — Expose `clang_tidy_test` in a `BUILD` file | ||
|
|
||
| ```python | ||
| load("//tools/lint:linters.bzl", "clang_tidy_test") | ||
|
|
||
| clang_tidy_test( | ||
| name = "clang_tidy", | ||
| srcs = ["//..."], # or a more targeted glob | ||
| ) | ||
| ``` | ||
|
|
||
| ### 7 — Run | ||
|
|
||
| ```bash | ||
| bazel test --config=clang-tidy //... | ||
| ``` | ||
|
|
||
| Reports are written to `bazel-out/.../rules_lint_report/` as text files next to each | ||
| linted target. | ||
|
|
||
| ### 8 — CI integration | ||
|
|
||
| Add a workflow job that runs: | ||
|
|
||
| ```bash | ||
| bazel test --config=clang-tidy //... | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| test:clang-tidy --aspects=//tools/lint:linters.bzl%clang_tidy_aspect | ||
| test:clang-tidy --output_groups=+rules_lint_report | ||
| test:clang-tidy --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| exports_files( | ||
| ["linters.bzl"], | ||
| visibility = ["//visibility:public"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| """Clang-tidy aspect and test rule.""" | ||
|
|
||
| load("@aspect_rules_lint//lint:clang_tidy.bzl", "lint_clang_tidy_aspect") | ||
| load("@aspect_rules_lint//lint:lint_test.bzl", "lint_test") | ||
|
|
||
| clang_tidy_aspect = lint_clang_tidy_aspect( | ||
| binary = Label("@llvm_toolchain//:clang-tidy"), | ||
| configs = [Label("@score_cpp_policies//clang_tidy:.clang-tidy")], | ||
| lint_target_headers = True, | ||
| angle_includes_are_system = True, | ||
|
|
||
| ) | ||
|
|
||
| clang_tidy_test = lint_test(aspect = clang_tidy_aspect) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to add separat readme file in each tool, i.e clang_tidy/readme.md, sanitizers/readme.md etc.
the readme file in root only summarizes all tools in this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.