当我运行
npx prettier --write pipeline.yml
时,它会格式化所有子行,包括破折号 (-
),并从父行中缩进 2 个空格,如下所示:
resources:
- name: concourse-examples
type: git
icon: github
check_every: 30m
source:
uri: https://github.com/concourse/examples
jobs:
- name: set-self
public: true
plan:
- get: concourse-examples
trigger: true
- set_pipeline: self
file: concourse-examples/pipelines/set-pipelines.yml
我希望所有子行(除了以破折号(
-
)开头的子行)都从其父行缩进 2 个空格,如下所示:
resources:
- name: concourse-examples
type: git
icon: github
check_every: 30m
source:
uri: https://github.com/concourse/examples
jobs:
- name: set-self
public: true
plan:
- get: concourse-examples
trigger: true
- set_pipeline: self
file: concourse-examples/pipelines/set-pipelines.yml
我怎样才能实现这个目标?
您最好的选择是通过创建一个
.prettierignore
文件并向其中添加以下内容,让 prettier 忽略所有 yml 文件...
*.yml
overrides
:
{
"singleQuote": true,
"overrides": [
{
"files": "*.yml",
"options": {
"singleQuote": false
}
}
]
}
P.S.:我知道这是一个旧的,但这是谷歌的第一次点击,而且答案确实不令人满意。