9

I use precommit with this .pre-commit-config.yaml file (extract) :

-   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

and I am stuck with this error :

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

The beginning of my yaml file is :

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

I tried with and without a leading line --- but it changes only the line nb of the error.

I didn't found any help anywhere on the web, so if anybody can help me, I would be greatefull for that !

Thanks by advance, Herve

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
herve-guerin
  • 2,827
  • 20
  • 25

2 Answers2

29

The problem is now solved in pre-commit version 1.1.0 : https://github.com/pre-commit/pre-commit/issues/635 Thanks for your help.

You can enable this new option by setting args: [--allow-multiple-documents], for example:

    hooks:
    -   id: check-yaml
        args: [--allow-multiple-documents]
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
herve-guerin
  • 2,827
  • 20
  • 25
3

--- starts a new YAML document in your file. So you have two YAML documents in your file, and this is what the error complains about. Based on the documentation of pre-commit, I assume you want to make it a sequence instead:

- 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
flyx
  • 35,506
  • 7
  • 89
  • 126
  • Your solution is correct, thanks, but in fact I do need to use a multi-document yaml file, so your solution is not appropriate in my context, does anybody has a trick to precommit a multi-document yaml file ? – herve-guerin Sep 07 '17 at 07:57
  • 1
    It may be better to direct a feature request to pre-commit than to ask for a workaround here. However, I wonder why you need a multi-document yaml file. If you process it somewhere else, couldn't you alter that process to take a sequence instead? – flyx Sep 07 '17 at 10:20
  • Sorry, I searched but I didnt find where to put a feature request about pre-commit, can you give the address of the appropriate forum to post it ? Thanks in advance, Herve – herve-guerin Oct 09 '17 at 08:22
  • There is an issue tracker [at GitHub](https://github.com/pre-commit/pre-commit/issues), which I assume is the right place. But I am not a maintainer nor a user of pre-commit. – flyx Oct 09 '17 at 11:21