Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE/improvement.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## Related ticket

> [!IMPORTANT]
> Please replace `[ISSUE-NUMBER]` with the issue-number that tracks this bug fix. If there is no such
> Please replace `[ISSUE-NUMBER]` with the issue-number that tracks this improvement. If there is no such
> ticket yet, create one via [this issue template](../ISSUE_TEMPLATE/new?template=improvement.md).
closes [ISSUE-NUMBER] (improvement ticket)
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_cc", version = "0.1.5")

bazel_dep(name = "aspect_rules_lint", version = "2.5.0")

11 changes: 8 additions & 3 deletions README.md
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# score_cpp_policies

Centralized C++ quality tool policies for Eclipse S-CORE, providing sanitizer configurations reusable across all S-CORE modules (logging, communication, baselibs, etc.).
Centralized C++ quality tool policies for Eclipse S-CORE, providing sanitizer
configurations and clang-tidy integration reusable across all S-CORE modules
(logging, communication, baselibs, etc.).

Planned: clang-tidy, clang-format, code coverage policies.
Planned: clang-format, code coverage policies.

## What This Provides

Expand All @@ -11,6 +13,8 @@ Planned: clang-tidy, clang-format, code coverage policies.
- **`sanitizers/sanitizers.bazelrc`** — canonical config that consumers import or copy
- **Suppression files** — per-sanitizer suppression lists for known false positives (GoogleTest, etc.)
- **Constraint system** — `target_compatible_with` settings for sanitizer-incompatible targets
- **`clang_tidy/.clang-tidy`** — centralized default check set (conservative baseline, tailorable per module)
- **`clang_tidy/clang_tidy.bazelrc`** — `--config=clang-tidy` bazelrc config consumers can import

## Available Sanitizer Configurations

Expand All @@ -27,7 +31,7 @@ Planned: clang-tidy, clang-format, code coverage policies.
### Add Dependency

```python
bazel_dep(name = "score_cpp_policies", version = "0.0.0")
bazel_dep(name = "score_cpp_policies")
```

### Configure Sanitizers
Expand Down Expand Up @@ -103,6 +107,7 @@ cd tests

bazel test --config=asan_ubsan_lsan //...
bazel test --config=tsan //...
bazel test --config=clang-tidy //...
```

## Contributing
Expand Down
39 changes: 39 additions & 0 deletions clang_tidy/.clang-tidy
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
20 changes: 20 additions & 0 deletions clang_tidy/BUILD.bazel
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"],
)
108 changes: 108 additions & 0 deletions clang_tidy/README.md
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 //...
```
16 changes: 16 additions & 0 deletions clang_tidy/clang_tidy.bazelrc
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
4 changes: 2 additions & 2 deletions tests/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

# Import centralized sanitizer configurations
import %workspace%/../sanitizers/sanitizers.bazelrc

import %workspace%/../clang_tidy/clang_tidy.bazelrc

common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
common --registry=https://bcr.bazel.build

# Use LLVM toolchain for sanitizer configs (same as consuming modules)
build:asan_ubsan_lsan --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
build:tsan --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
15 changes: 9 additions & 6 deletions tests/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

module(
name = "score_cpp_policies_tests",
)
module(name = "score_cpp_policies_tests")

bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "toolchains_llvm", version = "1.7.0")
bazel_dep(name = "rules_cc", version = "0.2.17")

bazel_dep(name = "score_cpp_policies")
local_path_override(
module_name = "score_cpp_policies",
path = "..",
)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
# LLVM toolchain for clang-tidy (provides @llvm_toolchain//:clang-tidy).
bazel_dep(name = "toolchains_llvm", version = "1.7.0")

llvm = use_extension(
"@toolchains_llvm//toolchain/extensions:llvm.bzl",
"llvm",
)
llvm.toolchain(
llvm_version = "19.1.7",
extra_known_features = [
Expand Down
17 changes: 17 additions & 0 deletions tests/tools/lint/BUILD.bazel
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"],
)
27 changes: 27 additions & 0 deletions tests/tools/lint/linters.bzl
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)
Loading