aspect-build / rules_lint

Run static analysis tools with Bazel
Apache License 2.0
75 stars 42 forks source link

[Bug]: Clang-Tidy outputs absolute filepaths #378

Open JesseTatasciore opened 1 week ago

JesseTatasciore commented 1 week ago

What happened?

When running bazel lint //speller/... I am seeing absolute filepaths (which include the bazel output tree) with the linting results:

/private/var/tmp/_bazel_jesse/93d7e699c5e2019d94351d19b00be5a3/sandbox/darwin-sandbox/11/execroot/_main/speller/data_driven_tests/lookup-datatest.cc:16:8: warning: an exception may be thrown in function 'test_config' which should not throw exceptions [bugprone-exception-escape]

I expected to see relative filepaths outputed instead:

speller/data_driven_tests/lookup-datatest.cc:16:8: warning: an exception may be thrown in function 'test_config' which should not throw exceptions [bugprone-exception-escape]

Version

Development (host) and target OS/architectures:

Reproduceable on MacOS and Ubuntu

Output of bazel --version:

(This happens on all versions of the Aspect CLI)

Bazelisk version: 1.20.0
Aspect CLI Pro version: 5.11.0-alpha0.dev.150.g12ded54
Build label: 7.3.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Aug 19 16:41:27 2024 (1724085687)
Build timestamp: 1724085687
Build timestamp as int: 1724085687

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")
bazel_dep(name = "aspect_rules_cypress", version = "0.6.0")
bazel_dep(name = "aspect_rules_esbuild", version = "0.21.0")
bazel_dep(name = "aspect_rules_jasmine", version = "2.0.0")
bazel_dep(name = "aspect_rules_jest", version = "0.22.0")
bazel_dep(name = "aspect_rules_js", version = "2.0.0")
bazel_dep(name = "aspect_rules_lint", version = "1.0.0-rc9")
bazel_dep(name = "aspect_rules_swc", version = "2.0.0")
bazel_dep(name = "aspect_rules_ts", version = "3.0.0")
bazel_dep(name = "aspect_rules_webpack", version = "0.16.0")

Language(s) and/or frameworks involved:

Clang-Tidy

How to reproduce

Checkout: https://github.com/aspect-build/bazel-examples

Run: `bazel lint //speller/...`

Any other information?

We have solved this problem for eslint. Look into how we fixed it there and apply it to clang tidy as well

alexeagle commented 1 week ago

eslint fix is https://github.com/aspect-build/rules_lint/blob/main/lint/eslint.stylish-formatter.js#L1-L4

Yes, this is important since you can't click the file in your terminal to navigate to the site you want to edit. @jsharpe do you happen to know if this is easy to fix?

jsharpe commented 1 week ago

Not sure - a quick search shows this https://github.com/microsoft/vscode-cpptools/issues/9555 which shows it definitely is possible to get relative outputs from clang-tidy though; maybe the wrapper for clang-tidy needs to ensure that its passing sources as relative paths in its input?

alexeagle commented 1 week ago

Interesting, if I bypass Aspect CLI and run with vanilla Bazel, it's mostly relative paths but some absolute.

example % ./lint.sh src/cpp/...
src/cpp/main/hello-greet.h:6:13: error: function 'get_greet' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name,-warnings-as-errors]
std::string get_greet(const std::string &thing);
            ^
/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/sandbox/darwin-sandbox/9/execroot/_main/src/cpp/main/hello-greet.cc:5:13: note: the definition seen here
std::string get_greet(const std::string& who) { return "Hello " + who; }
            ^
src/cpp/main/hello-greet.h:6:13: note: differing parameters are named here: ('thing'), in definition: ('who')
std::string get_greet(const std::string &thing);
            ^                            ~~~~~
                                         who