Prettier 不会忽略具有 root 权限的文件夹

发布于 2025-01-13 12:38:05 字数 756 浏览 1 评论 0原文

在我的项目中,我们有一个用于运行容器的 docker 文件夹。问题是,当我们运行 prettier 时,我收到此错误:

[error] Unable to expand directory: .
[error] EACCES: permission denied, scandir '/home/nanez/my-project/docker/data/postgres'

此文件夹需要 root 权限才能访问和删除它(使用 sudo ofc)。我已经将整个 docker 文件夹添加到 .prettierignore 以及特定的 postgres 文件夹中,但我仍然抛出错误。这是我的 .prettierignore

## Deps
node_modules
cache

generated
docker
./docker
/docker/**/*
/docker/*
/docker/data/postgres

如您所见,我添加了 docker 文件夹,其中包含我认为的所有可能性。

如果我使用负模式运行 prettier 效果很好,例如: npx prettier 。 '!./docker' --check。这一切运行都没有问题,但我想知道为什么我不能直接忽略 npx prettier 。 --检查 .prettierignore 中是否已有 docker 文件夹。

我在 Ubuntu 20.04LTS 中使用 WSL2。

谢谢 :)

In my project we have a docker folder that we use to run the container. The issue is that when we run prettier i got this error:

[error] Unable to expand directory: .
[error] EACCES: permission denied, scandir '/home/nanez/my-project/docker/data/postgres'

This folder need root permissions to access and delete it (using sudo ofc). I already added the whole docker folder to .prettierignore and also the specific postgres folder and i still throwing the error. Here my .prettierignore:

## Deps
node_modules
cache

generated
docker
./docker
/docker/**/*
/docker/*
/docker/data/postgres

As you can see, I added the docker folder with all the posibilities that I thought.

If I run prettier with the negative pattern work good, for ex: npx prettier . '!./docker' --check. This run all without problem, but I'm wonder why I can't ignore directly with npx prettier . --check if already I have the docker folder in the .prettierignore.

I'm using WSL2 with Ubuntu 20.04LTS.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2025-01-20 12:38:05

正如 @Sagnik Pradhan 评论,目前(2023 年 3 月)在 Prettier 中打开问题 #11568

从那里,有只有一个评论解决办法

对于仍然面临此问题的人,我找到了解决方法。您可以使用命令行专门忽略有问题的文件/文件夹。例如,我遇到了 .pki 问题,所以我运行了 prettier 。 --检查'!./.pki'。

因此,目前问题中已经建议了最佳答案(并且对我有用):

npx prettier . '!./docker' --check

As @Sagnik Pradhan comments, this is currently (March 2023) an open issue #11568 in Prettier.

From there, there is only a commented work around

For anyone still facing this issue, I found a workaround. You can specifically ignore the problem file/folder using the command line. For example I was having issues with .pki so I ran prettier . --check '!./.pki'.

So currently the best answer has already been suggested in the question (and worked for me):

npx prettier . '!./docker' --check
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文