![](/img/trans.png)
[英]How to disable eslint(prettier/prettier) single quotes error
[英]Disable prettier for a single file
我需要在我的 Vs-code 项目中为单个文件(API URL 文件)禁用prettier 。 实际上,我需要每个 API 及其 URL 都在一行中,但 prettier 将它们分成两行。
前
export const GET_SEARCH_TEACHERS = params => myexampleFunction_app_base(`teachers/search/${params.search}`);
后
export const GET_SEARCH_TEACHERS = params =>
myexampleFunction_app_base(`teachers/search/${params.search}`);
感谢evolutionxbox ,到目前为止找到了两种解决方案。
我们可以使用扩展程序在需要时在特定页面上切换格式,例如更漂亮。
格式切换https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle
Prettier 提供了一个逃生舱来忽略代码块或阻止整个文件被格式化。
忽略文件
要从格式中排除文件,请将条目添加到项目root
的.prettierignore
文件或设置--ignore-path
CLI 选项。 .prettierignore
使用 gitignore 语法。
/app/src/scripts/example.js
JavaScript
// prettier-ignore
JavaScript 注释将从格式化中排除抽象语法树中的下一个节点。
例如:
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)
将转化为:
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)
JSX
<div>
{/* prettier-ignore */}
<span ugly format='' />
</div>
在 repo 的根目录中创建 .prettierignore 文件,并添加要忽略的文件夹的名称,并添加要忽略的文件的完整路径并保存。
使用 .gitignore 格式更新你的文件,你也可以在更漂亮的网站上阅读它https://prettier.io/docs/en/ignore.html#ignoring-files
另一种选择是使用更漂亮的块状切换,禁用文件中“块”的格式化。 例如,在函数定义开始前添加
\/\/ prettier-ignore<\/code> ,将禁用该函数的更漂亮的格式。
... (code up here is formatted by prettier)
// prettier-ignore
function noPrettierFormattingInHere(){
...
}
... (code down here is formatted by prettier)
. React 项目的 prettierignore
build/
node_modules/
internals/generators/
internals/scripts/
package-lock.json
yarn.lock
package.json
coverage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.