Repository: coala/coala-bears

Issue:
Most YAML documents use document starts (---)
Hi,

I am the creator of yamllint, the linter coala uses for YAML.

Since #965 was merged three months ago, coala fails on many projects like Ansible, OpenStack and even yamllint itself, because coala doesn't accept document start markers (`---`) anymore.

Document start markers are commonly used, and required when declaring multiple documents in a single `.yaml` file (see [the spec](http://yaml.org/spec/1.2/spec.html#id2800132)).

The proposed fix in the original issue (#923) was to disable the rule, but the implemented fix (#965) made document starts forbidden.

My opinion is that coala should either require document starts, or disable the rule by default.


Discussion:
Agree. We should disable the rule by default.

So task is to use `None` as default value [here](https://github.com/coala/coala-bears/blob/master/bears/yaml/YAMLLintBear.py#L27) and if it's used, leave the config value for the rule, if `True` or `False` are passed, configure the rule with `True`/`False`.
Btw one can remove https://github.com/coala/coala-bears/blob/master/bears/yaml/YAMLLintBear.py#L42 and directly feed the value of `document-start` into the configuration dictionary^^
For reference, this fix would be very similliar with https://github.com/coala/coala-bears/pull/1335.

Resolving patch:
diff --git a/bears/yaml/YAMLLintBear.py b/bears/yaml/YAMLLintBear.py
--- a/bears/yaml/YAMLLintBear.py
+++ b/bears/yaml/YAMLLintBear.py
@@ -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
@@ -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)
 


Test patch:
diff --git a/tests/yaml/YAMLLintBearTest.py b/tests/yaml/YAMLLintBearTest.py
--- a/tests/yaml/YAMLLintBearTest.py
+++ b/tests/yaml/YAMLLintBearTest.py
@@ -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})