【问题标题】:Precommit check-yaml error : "expected a single document in the stream"预提交 check-yaml 错误:“预期流中有单个文档”
【发布时间】:2018-02-14 21:25:21
【问题描述】:

我将 precommit 与这个 .pre-commit-config.yaml 文件(提取)一起使用:

-   repo: https://github.com/pre-commit/pre-commit-hooks
    sha: v0.9.2
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml

我被这个错误困住了:

Check Yaml...................Failed
hookid: check-yaml

expected a single document in the stream
  in "modules.yml", line 1, column 1
but found another document
  in "modules.yml", line 4, column 1

我的 yaml 文件的开头是:

repo: ssh://git.tranquilit.local/odoo-11-oca-tis/OCB.git
root: 8.0
branch: 8.0-tis
---
repo: ssh://git.tranquilit.local/odoo-71-tis/tis-addons.git
origin: tis
branch: 8.0
modules:
    #- attachment_rename
    #- partner_firstname
    - tis_account_analytic_recurrent_invoicing

我尝试了带和不带引导线 --- 但它只改变错误的 nb 行。

我在网上没有找到任何帮助,所以如果有人可以帮助我,我会很高兴的!

在此先感谢您,Herve

【问题讨论】:

    标签: yaml pre-commit.com


    【解决方案1】:

    问题现在在预提交版本 1.1.0 中得到解决:https://github.com/pre-commit/pre-commit/issues/635 感谢您的帮助。

    您可以通过设置args: [--allow-multiple-documents] 来启用这个新选项,例如:

        hooks:
        -   id: check-yaml
            args: [--allow-multiple-documents]
    

    【讨论】:

    • 仅供参考,我在使用 v2.5.0 时遇到了同样的问题,这个设置有帮助。
    【解决方案2】:

    --- 在您的文件中启动一个新的 YAML 文档。所以你的文件中有两个 YAML 文档,这就是错误所抱怨的。根据 pre-commit 的文档,我假设您想改为序列:

    - repo: ssh://git.tranquilit.local/odoo-11-oca-tis/OCB.git
      root: 8.0
      branch: 8.0-tis
    - repo: ssh://git.tranquilit.local/odoo-71-tis/tis-addons.git
      origin: tis
      branch: 8.0
      modules:
        #- attachment_rename
        #- partner_firstname
        - tis_account_analytic_recurrent_invoicing
    

    【讨论】:

    • 您的解决方案是正确的,谢谢,但实际上我确实需要使用多文档 yaml 文件,因此您的解决方案在我的上下文中不合适,是否有人有预提交多文档的技巧文档 yaml 文件?
    • 将功能请求引导到预先提交可能比在这里要求解决方法更好。但是,我想知道为什么您需要一个多文档 yaml 文件。如果你在其他地方处理它,你不能改变那个过程来取一个序列吗?
    • 对不起,我搜索了,但我没有找到关于预提交的功能请求的位置,你能给出相应论坛的地址来发布它吗?在此先感谢赫夫
    • 有一个问题跟踪器at GitHub,我认为这是正确的地方。但我不是维护者,也不是 pre-commit 的用户。
    猜你喜欢
    • 2014-02-04
    • 1970-01-01
    • 2019-08-23
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多