Skip to content

Commit

Permalink
Allow ka-lint to pass multi-document yaml files
Browse files Browse the repository at this point in the history
Summary:
Many yaml files are intentionally multi-document. Such yaml files should pass linting if there are no other problems. Here we fix that by copying that pattern in webapp, Khan/webapp@843faf4

Issue: INFRA-5255

Test Plan: In `khanflow`, run `ka-lint --always-exit-0 --blacklist=yes --propose-arc-fixes deployment/nfs-server/nfs-server.yaml`

Reviewers: csilvers, johnmelesky, #devops

Reviewed By: csilvers, #devops

Subscribers: csilvers, kevinb

Differential Revision: https://phabricator.khanacademy.org/D73017
  • Loading branch information
dbraley committed Jun 30, 2021
1 parent 940de62 commit 6405721
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,10 @@ class YamlLinter(Linter):
"""
def process(self, f, contents_of_f):
try:
yaml.safe_load(contents_of_f)
# We allow multiple documents within the same YAML file.
# Since safe_load_all returns a generator, we have to make sure it
# is properly unrolled.
list(yaml.safe_load_all(contents_of_f))
return 0
except yaml.parser.ParserError as e:
self.report(('%s:%s:%s: E=yaml= Error parsing yaml: %s %s'
Expand Down

0 comments on commit 6405721

Please sign in to comment.