Skip to content

Conversation

@martin4861
Copy link

@martin4861 martin4861 commented Sep 8, 2025

Add cppcheck as lint aspect as per #569.
A local test can be ran using: cd example; bazel lint //src:hello_cc
The aspect supports human readable output and xml output, e.g.
cd example; bazel build //... --aspects=//tools/lint:linters.bzl%cppcheck --output_groups=rules_lint_xml

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

"Add cppcheck linter"

Test plan

  • Manual testing: cd example; bazel build //... --aspects=//tools/lint:linters.bzl%cppcheck --output_groups=rules_lint_xml: This will produce following output:
INFO: Analyzed 194 targets (0 packages loaded, 0 targets configured).
INFO: Found 194 targets...
Aspect //tools/lint:linters.bzl%cppcheck of //src:hello_cc up-to-date:
  bazel-bin/src/hello_cc.AspectRulesLintCppCheck.xml
Aspect //tools/lint:linters.bzl%cppcheck of //src/cpp/main:hello-greet up-to-date:
  bazel-bin/src/cpp/main/hello-greet.AspectRulesLintCppCheck.xml
Aspect //tools/lint:linters.bzl%cppcheck of //src:hello_c up-to-date:
  bazel-bin/src/hello_c.AspectRulesLintCppCheck.xml
Aspect //tools/lint:linters.bzl%cppcheck of //src/cpp/lib:hello-time up-to-date:
  bazel-bin/src/cpp/lib/hello-time.AspectRulesLintCppCheck.xml
Aspect //tools/lint:linters.bzl%cppcheck of //src/cpp/main:hello-world up-to-date:
  bazel-bin/src/cpp/main/hello-world.AspectRulesLintCppCheck.xml
INFO: Elapsed time: 0.227s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

@CLAassistant
Copy link

CLAassistant commented Sep 8, 2025

CLA assistant check
All committers have signed the CLA.

@aspect-workflows
Copy link

aspect-workflows bot commented Sep 8, 2025

Test

All tests were cache hits

5 tests (100.0%) were fully cached saving 2s.


Test

example

8 test targets passed

Targets
//tools/format:format_test_HTML_Jinja_with_djlint [k8-fastbuild]5s
//tools/format:format_test_JavaScript_with_prettier [k8-fastbuild]12s
//tools/format:format_test_Markdown_with_prettier [k8-fastbuild]2s
//tools/format:format_test_Protocol_Buffer_with_buf [k8-fastbuild]745ms
//tools/format:format_test_Python_with_ruff [k8-fastbuild]494ms
//tools/format:format_test_SQL_with_prettier [k8-fastbuild]2s
//tools/format:format_test_Scala_with_scalafmt [k8-fastbuild]6s
//tools/format:format_test_Starlark_with_buildifier [k8-fastbuild]363ms

Total test execution time was 28s. 33 tests (80.5%) were fully cached saving 14s.


Test (WORKSPACE) (Test)

example

8 test targets passed

Targets
//tools/format:format_test_HTML_Jinja_with_djlint [k8-fastbuild]1s
//tools/format:format_test_JavaScript_with_prettier [k8-fastbuild]9s
//tools/format:format_test_Markdown_with_prettier [k8-fastbuild]1s
//tools/format:format_test_Protocol_Buffer_with_buf [k8-fastbuild]698ms
//tools/format:format_test_Python_with_ruff [k8-fastbuild]477ms
//tools/format:format_test_SQL_with_prettier [k8-fastbuild]1s
//tools/format:format_test_Scala_with_scalafmt [k8-fastbuild]2s
//tools/format:format_test_Starlark_with_buildifier [k8-fastbuild]264ms

Total test execution time was 16s. 13 tests (61.9%) were fully cached saving 8s.


Lint [.]      Lint [example]

@martin4861 martin4861 force-pushed the martin4861/add-cppcheck-linter branch from c13a79a to 65fc0a8 Compare September 18, 2025 14:40
@martin4861 martin4861 changed the title Add cppcheck lint aspect [WIP] feat: Add cppcheck lint aspect [WIP] Sep 18, 2025
@martin4861 martin4861 force-pushed the martin4861/add-cppcheck-linter branch 2 times, most recently from 6889850 to 47f06fa Compare September 19, 2025 09:08
@martin4861 martin4861 changed the title feat: Add cppcheck lint aspect [WIP] feat: Add cppcheck lint aspect Sep 19, 2025
@martin4861 martin4861 marked this pull request as ready for review September 19, 2025 09:11
@martin4861 martin4861 force-pushed the martin4861/add-cppcheck-linter branch from 47f06fa to 2e6eb8a Compare October 16, 2025 15:55
@martin4861 martin4861 force-pushed the martin4861/add-cppcheck-linter branch from 2e6eb8a to 80a4062 Compare October 16, 2025 15:57
build_file = "//tools/lint:cppcheck.BUILD",
integrity = "sha256-kacV5Qvy8pHqYoejdDCId4yS3VJDaqTqSJ9JgEIfQd0=",
strip_prefix = "cppcheckpremium-25.8.4",
urls = ["https://files.cppchecksolutions.com/25.8.4/ubuntu-22.04/cppcheckpremium-25.8.4-amd64.tar.gz"],
Copy link
Member

Choose a reason for hiding this comment

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

i am not sure if this okay, isn't cppcheckpremium a paid tool?

Copy link
Author

Choose a reason for hiding this comment

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

That's true. There is also a free version, which can be installed with apt install cppcheck. I tried to use rules_distroless, but it does not work due to transitive dependencies. Do we need to model the tool in Bazel or can it be installed in the environment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants