admin管理员组文章数量:1410697
Is it possible to auto format on VS Code in directory whose root doesn't have prettier config?
- root <- current directory on VS Code
- app
- src <- Do i have to be here to run auto formatting??
- .prettierrc
- package.json
- file1
I cannot run prettier in root directory. Do I have to be in the directory which has prettierrc
?
Is it possible to auto format on VS Code in directory whose root doesn't have prettier config?
- root <- current directory on VS Code
- app
- src <- Do i have to be here to run auto formatting??
- .prettierrc
- package.json
- file1
I cannot run prettier in root directory. Do I have to be in the directory which has prettierrc
?
1 Answer
Reset to default 3You need to include a proper .prettierrc
file in the root directory, as the docs about Prettier Configuration File says:
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.
Prettier intentionally doesn’t support any kind of global configuration. This is to make sure that when a project is copied to another puter, Prettier’s behavior stays the same. Otherwise, Prettier wouldn’t be able to guarantee that everybody in a team gets the same consistent results.
root
├── app
│ ├── file4
│ ├── public
│ │ └── file5
│ └── src
│ ├── file1
│ ├── package.json
│ └── .prettierrc
├── file2
├── file3
└── .prettierrc
If you have a directory structure like above, the files under root/app/src/
(file1
, package.json
and root/app/src/.prettierrc
) will be formatted according to root/app/src/.prettierrc
config file, and other files under root/
or its subdirectories (file2
, file3
, root/.prettierrc
, file4
, and file5
) will be formatted according to root/.prettierrc
config file.
Or you can configure default options of Prettier for VS Code:
Configuring Default Options
Some users may not wish to create a new Prettier config for every project or use the VS Code settings. Because Prettier searches recursively up the file path, you can place a global prettier config at
~/.prettierrc
to be used as a fallback.You can also use the setting
prettier.configPath
to provide a global configuration. However, be careful, if this is set this value will always be used and local configuration files will be ignored.
本文标签: javascriptVS Code auto formatting with prettierStack Overflow
版权声明:本文标题:javascript - VS Code auto formatting with prettier - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744883702a2630359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论