pre-commit ".pre-commit-config.yaml: mapping values are not allowed here" in CI
The YAML parser rejected .pre-commit-config.yaml before pre-commit validated it. "mapping values are not allowed here" almost always means bad indentation or an unquoted colon in a value.
What this error means
The run fails with a YAML scanner error naming a line and column in the config, such as "mapping values are not allowed here" or "could not find expected ':'".
YAML
while parsing a block mapping
in ".pre-commit-config.yaml", line 5, column 7
mapping values are not allowed here
in ".pre-commit-config.yaml", line 5, column 12Common causes
Incorrect indentation under a list item
A hook key indented under the wrong level, or a mix of tabs and spaces, produces a mapping where the parser does not expect one.
An unquoted colon inside a value
A value containing : (like an args entry) that is not quoted confuses the YAML parser.
How to fix it
Fix indentation and quote colons
- Go to the line and column the parser named.
- Correct the indentation (spaces only) and quote any value containing a colon.
- Re-run so YAML parses cleanly.
.pre-commit-config.yaml
repos:
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args: ["--line-length=88"]Lint the YAML in CI
Add a YAML check so a parse error is caught with a precise location before pre-commit runs.
.github/workflows/ci.yml
- run: python -c "import yaml,sys; yaml.safe_load(open('.pre-commit-config.yaml'))"How to prevent it
- Use spaces, never tabs, in the config.
- Quote any value that contains a colon.
- Validate the YAML in CI before invoking pre-commit.
Related guides
pre-commit "InvalidConfigError" in .pre-commit-config.yaml in CIFix pre-commit "InvalidConfigError" in CI - the framework parsed .pre-commit-config.yaml but a required key i…
pre-commit "InvalidManifestError" from a hook repo in CIFix pre-commit "InvalidManifestError" in CI - the hook repository pre-commit cloned has a .pre-commit-hooks.y…
pre-commit "Hook id ... not present in repo" in CIFix pre-commit "Hook id `X` not present in repository ..." in CI - the hook id in your config does not exist…