aspect-build / rules_lint

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

[Bug]: _typings produces no files #245

Closed Zemnmez closed 4 months ago

Zemnmez commented 4 months ago

What happened?

When I try to follow the tutorial for formatting tests for typescript, I get issues because my _typings target doesn't seem to produce files with the Provider that rules_lint is using:

ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_YAML_with_yamlfmt: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_Jsonnet_with_jsonnetfmt: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_Jsonnet_with_jsonnetfmt' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_Go_with_gofmt: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_Go_with_gofmt' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_Shell_with_shfmt: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_Shell_with_shfmt' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_YAML_with_yamlfmt' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_JavaScript_with_prettier: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_JavaScript_with_prettier' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_Terraform_with_terraform-fmt: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_Terraform_with_terraform-fmt' failed
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: in args attribute of sh_test rule //ts/factorio/react:react_lint_formatting_Starlark_with_buildifier: label '//ts/factorio/react:react_typings' in $(location) expression expands to no files. Since this rule was created by the macro 'ts_project', the error might have been caused by the macro implementation
ERROR: /Users/tshadwell/code/monorepo/ts/factorio/react/BUILD.bazel:4:11: Analysis of target '//ts/factorio/react:react_lint_formatting_Starlark_with_buildifier' failed

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel 7.1.2

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

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

Language(s) and/or frameworks involved:

typescript

How to reproduce

You can pull this commit: https://github.com/zemn-me/monorepo/pull/5472/commits/a117b1a5614ddc908855186a852a45302bb4d951

and run `bazel test --keep_going //ts/factorio/react/...`

Any other information?

No response

alexeagle commented 4 months ago

You're trying to check the formatting of some build outputs, which is wrong. You should format-test the original srcs of the ts_project:

diff --git a/ts/rules.bzl b/ts/rules.bzl
index 42538157f..fdf978f21 100644
--- a/ts/rules.bzl
+++ b/ts/rules.bzl
@@ -49,11 +49,6 @@ def ts_lint(name, srcs = None, **kwargs):
         **kwargs
     )

-    format_test(
-        name = name + "_formatting",
-        srcs = srcs,
-    )
-
 def ts_project(name, visibility = None, lint = True, deps = [], data = [], resolve_json_module = True, srcs = None, tsconfig = "//:tsconfig", preserve_jsx = None, tags = [], **kwargs):
     """
     Compile a set of typescript files, dependencies, runtime data and other source files into typescript types and source maps.
@@ -109,3 +104,7 @@ def ts_project(name, visibility = None, lint = True, deps = [], data = [], resol

     if lint:
         ts_lint(name = name + "_lint", srcs = [name + "_typings"], tags = tags)
+        format_test(
+            name = name + "_formatting",
+            srcs = srcs,
+        )