Skip to content

Commit

Permalink
yamllint: Disable document-start by default
Browse files Browse the repository at this point in the history
Some projects use documents starts (`---`) in YAML documents (for
example Ansible, OpenStack, yamllint), others don't. Since these markers
are required when declaring multiple documents in a single .yaml file
(see the spec [1]), it is a bad idea to forbid them.

This commit disables the `document-start` rule by default, instead of
forcing / forbidding the use of these markers.

[1]: http://yaml.org/spec/1.2/spec.html#id2800132

Closes coala#1417
Related to coala#923 and coala#965
  • Loading branch information
adrienverge committed Feb 8, 2017
1 parent 6d8d105 commit 064abf4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 4 additions & 7 deletions bears/yaml/YAMLLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class YAMLLintBear:

@staticmethod
def generate_config(filename, file,
document_start: bool=False):
document_start: bool=None):
"""
:param document_start:
Use this rule to require or forbid the use of document start
Expand All @@ -33,13 +33,10 @@ def generate_config(filename, file,
yamllint_configs = {
'extends': 'default',
'rules': {
'document-start': {
'present': False
}
}
'document-start': 'disable' if document_start is None
else {'present': document_start},
},
}
if document_start:
yamllint_configs['rules']['document-start']['present'] = True

return yaml.dump(yamllint_configs)

Expand Down
13 changes: 9 additions & 4 deletions tests/yaml/YAMLLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@
'yamllint_config': conf_file})

YAMLLintBear3Test = verify_local_bear(YAMLLintBear,
valid_files=(no_start_yaml_file,),
invalid_files=(with_start_yaml_file,))
valid_files=(no_start_yaml_file,
with_start_yaml_file,),
invalid_files=())

YAMLLintBear4Test = verify_local_bear(YAMLLintBear,
valid_files=(no_start_yaml_file,),
invalid_files=(with_start_yaml_file,),
settings={'document_start': False})

YAMLLintBear5Test = verify_local_bear(YAMLLintBear,
valid_files=(with_start_yaml_file,),
invalid_files=(no_start_yaml_file,),
settings={
'document_start': True})
settings={'document_start': True})

0 comments on commit 064abf4

Please sign in to comment.