-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
[Bug]: how do prettier plugins work? #176
Comments
The most sane thing is to ensure the configuration file is JavaScript, and has a require() statement for the plugin, then that is the source of a for example,
you might want to look back in history too, our shell language was a prettier plugin at one point: rules_lint/example/package.json Line 11 in d230f1e
|
Thanks for the response. I went to try your suggestion (I was on PTO for a bit) and discovered that...just adding the plugins to my bog-standard Thank you for introducing this particular |
Re-opened to track the missing documentation for this |
I was about to re-open to ask for further assistance. 😅 I still can't get this to work properly. Here's a gist file showing the relevant files: The output I get is:
Now, if I manually run |
No, but that doesn't mean much, as these plugin issues are never obvious. I tried creating a working repro from your files, but there's too much broken and/or missing. It would be easier to diagnose as a red PR on the example folder in rules_lint. |
Alternatively if you can make a fully-functional repro I can clone to see the error... |
One thing to check is that the pnpm lockfile is up-to-date with any changes you made to |
I put together a repro repo (say that three times fast…) Things that might surprise you and may ultimately end up being part of the problem, who knows:
Things that surprise me:
Thank you for your help! |
Bazel's default sandbox is not as strong as you think. It can only be as hermetic as the tools it runs, and a lot of Nodejs tools follow symlinks and can walk outside the sandbox to find |
Running into the same problem. Cloned the repo above and updated const prettierPluginTailwind = require("pretter-plugin-tailwindcss");
module.exports = {
plugins: [
prettierPluginTailwind
],
}; But still seeing the same error. Is conclusion that prettier plugin imports cannot be linked to dependencies inside the sandbox? |
@alexeagle I've bumped into this as well with random failures in different environments. After looking at this more closely, I don't believe the documented pattern of using a peer dep solves the problem. The issue here appears to a consequence of running format explicitly in the source tree rather than the output tree. So, all sorts of things can accidentally be resolved at runtime. I believe that the example configuration for prettier load("@npm//:prettier/package_json.bzl", prettier = "bin")
prettier.prettier_binary(
name = "prettier",
# Allow the binary to be run outside bazel
env = {"BAZEL_BINDIR": "."},
) is going to source whatever prettierrc file it finds in the source tree. Then any require/imports in that config file will be resolved relative to the config file and not the runfiles of the binary. So, if /node_modules/ exists everything will be fine. All the apparent hermeticity problems go away by declaring the dependency on the config and transitively the plugin. prettier.prettier_binary(
name = "prettier",
data = ["//:prettier_config"],
# Allow the binary to be run outside bazel
env = {"BAZEL_BINDIR": "."},
# default log level is "log" which spams on success
# https://prettier.io/docs/en/cli.html#--log-level
fixed_args = [
"--config=\"$$JS_BINARY__RUNFILES\"/$(rlocationpath //:prettier_config)",
],
) and js_library(
name = "prettier_config",
srcs = ["prettier.config.mjs"],
deps = ["//:node_modules/prettier-plugin"],
) Maybe there is a slightly cleaner way to do this? I'm happy to try and push a breaking configuration in example/. |
Thanks @sallustfire! I finally found time to reproduce the issue, and also try your approach, which I've put on a branch here: https://github.com/aspect-build/rules_lint/compare/prettier-plugins I added some logging in the |
@alexeagle Thanks for confirming. The updated documentation looks helpful. |
(It is entirely possible that I'm just Holding It Wrong; guidance welcome and appreciated. ❤️)
What happened?
I've got prettier set up as described in the docs, with a handful of plugins specified in BUILD as well as the .prettierrc file:
Unfortunately, no force on earth can compel these plugins to work:
I've been trying permutations for hours. Things I've tried that have not worked:
:prettierrc
(a plain old file) with ajs_library
target that .prettierrc assrcs
and had the plugins asdeps
At this point, I am fresh out of ideas and would love a nudge in the right direction. 🙏
Version
Development (host) and target OS/architectures: Ubuntu running in Docker on a M1 Mac
Output of
bazel --version
: bazel 6.4.0Version of the Aspect rules, or other relevant rules from your
WORKSPACE
orMODULE.bazel
file: 0.9.1Language(s) and/or frameworks involved: JS
How to reproduce
No response
Any other information?
No response
The text was updated successfully, but these errors were encountered: