![](/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.