Skip to content

Commit a7a09c9

Browse files
committed
yamllint: Disable document-start by default
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 #1417 Fixes #923 #965
1 parent 6d8d105 commit a7a09c9

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

bears/yaml/YAMLLintBear.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class YAMLLintBear:
2424

2525
@staticmethod
2626
def generate_config(filename, file,
27-
document_start: bool=False):
27+
document_start: bool=None):
2828
"""
2929
:param document_start:
3030
Use this rule to require or forbid the use of document start
@@ -33,13 +33,10 @@ def generate_config(filename, file,
3333
yamllint_configs = {
3434
'extends': 'default',
3535
'rules': {
36-
'document-start': {
37-
'present': False
38-
}
39-
}
36+
'document-start': 'disable' if document_start is None
37+
else {'present': document_start},
38+
},
4039
}
41-
if document_start:
42-
yamllint_configs['rules']['document-start']['present'] = True
4340

4441
return yaml.dump(yamllint_configs)
4542

tests/yaml/YAMLLintBearTest.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@
7070
'yamllint_config': conf_file})
7171

7272
YAMLLintBear3Test = verify_local_bear(YAMLLintBear,
73-
valid_files=(no_start_yaml_file,),
74-
invalid_files=(with_start_yaml_file,))
73+
valid_files=(no_start_yaml_file,
74+
with_start_yaml_file,),
75+
invalid_files=())
7576

7677
YAMLLintBear4Test = verify_local_bear(YAMLLintBear,
78+
valid_files=(no_start_yaml_file,),
79+
invalid_files=(with_start_yaml_file,),
80+
settings={'document_start': False})
81+
82+
YAMLLintBear5Test = verify_local_bear(YAMLLintBear,
7783
valid_files=(with_start_yaml_file,),
7884
invalid_files=(no_start_yaml_file,),
79-
settings={
80-
'document_start': True})
85+
settings={'document_start': True})

0 commit comments

Comments
 (0)