如何配置 prettier 以格式化 YAML 文件以使用零空格缩进缩进列表项

Raf*_*fiq 6 yaml prettier

当我运行时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
Run Code Online (Sandbox Code Playgroud)

我希望所有子行(除了以破折号 ( ) 开头的子行-)都从其父行缩进 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
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?

fly*_*lyx 8

你不能。引用期权哲学

Prettier 不是一个厨房水槽代码格式化程序,它会尝试以您希望的任何方式打印您的代码。这是固执己见

  • 嗯,这不是我们想要使用的方式。这种格式对于 YAML 来说非常常见。感谢你的回答。 (2认同)