Repository: preslavmihaylov/todocheck
Pull request #194 (2022-09-06 10:55:22)

Add support for yaml files

preslavmihaylov: Thanks for that!

Could you also add an integration test?
Jasper-Ben: > Thanks for that!
> 
> Could you also add an integration test?

Done. I've added it to the "scripts" testing, as the todo comment rules are identical. If you prefer it to be differently structured no problem as well.  

Patch:
diff --git a/.gitignore b/.gitignore
index 3a91cee..658e29c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 tmp/
 todocheck
+testing/authtokens.yaml
diff --git a/README.md b/README.md
index d5de010..d83642d 100644
--- a/README.md
+++ b/README.md
@@ -306,6 +306,7 @@ Based on this, here are the supported languages:
 | Scala                 | `*.scala`, `*.sc` extensions. Supports single-line `//` comments and multi-line `/* */` comments                                 |
 | Swift                 | `*.swift` extension. Supports single-line `//` comments and multi-line `/* */` comments
 | Vue                 | `*.vue` extension. Supports single-line `//` comments, multi-line `/* */` comments and multi-line `<!-- -->` HTML comments                                |
+| Yaml                  | `*.yaml`, `*.yml` extension. Supports `#` single-line comments                                                         |
 
 If you don't see your favorite language in this table, but it does use one of the supported comment formats, submit an issue [here](https://github.com/preslavmihaylov/todocheck/issues/new)
 
diff --git a/matchers/matchers.go b/matchers/matchers.go
index 1f351c3..dc41ef3 100644
--- a/matchers/matchers.go
+++ b/matchers/matchers.go
@@ -191,6 +191,8 @@ var supportedMatchers = map[string]*matcherFactory{
 	".bash": scriptsMatcherFactory,
 	".zsh":  scriptsMatcherFactory,
 	".R":    scriptsMatcherFactory,
+	".yaml": scriptsMatcherFactory,
+	".yml":  scriptsMatcherFactory,
 
 	// file types, supporting php comments
 	".php": phpMatcherFactory,


Test patch:
diff --git a/testing/scenarios/scripts/file.yaml b/testing/scenarios/scripts/file.yaml
new file mode 100644
index 0000000..b4a54f3
--- /dev/null
+++ b/testing/scenarios/scripts/file.yaml
@@ -0,0 +1,9 @@
+# This is a yaml file
+
+# A malformed TODO comment
+
+# TODO 123: This is a valid todo comment
+
+# TODO 321: This is an invalid todo, marked against a closed issue
+
+foo: bar # TODO 567: This is an invalid todo, marked against a non-existent issue
diff --git a/testing/scenarios/scripts/file.yml b/testing/scenarios/scripts/file.yml
new file mode 100644
index 0000000..b4a54f3
--- /dev/null
+++ b/testing/scenarios/scripts/file.yml
@@ -0,0 +1,9 @@
+# This is a yaml file
+
+# A malformed TODO comment
+
+# TODO 123: This is a valid todo comment
+
+# TODO 321: This is an invalid todo, marked against a closed issue
+
+foo: bar # TODO 567: This is an invalid todo, marked against a non-existent issue
diff --git a/testing/todocheck_test.go b/testing/todocheck_test.go
index 4844906..56cc34c 100644
--- a/testing/todocheck_test.go
+++ b/testing/todocheck_test.go
@@ -241,6 +241,36 @@ func TestScriptsTodos(t *testing.T) {
 				WithType(errors.TODOErrTypeNonExistentIssue).
 				WithLocation("scenarios/scripts/script.bash", 9).
 				ExpectLine("curl \"localhost:8080\" # TODO 567: This is an invalid todo, marked against a non-existent issue")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeMalformed).
+				WithLocation("scenarios/scripts/file.yaml", 3).
+				ExpectLine("# A malformed TODO comment")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeIssueClosed).
+				WithLocation("scenarios/scripts/file.yaml", 7).
+				ExpectLine("# TODO 321: This is an invalid todo, marked against a closed issue")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeNonExistentIssue).
+				WithLocation("scenarios/scripts/file.yaml", 9).
+				ExpectLine("foo: bar # TODO 567: This is an invalid todo, marked against a non-existent issue")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeMalformed).
+				WithLocation("scenarios/scripts/file.yml", 3).
+				ExpectLine("# A malformed TODO comment")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeIssueClosed).
+				WithLocation("scenarios/scripts/file.yml", 7).
+				ExpectLine("# TODO 321: This is an invalid todo, marked against a closed issue")).
+		ExpectTodoErr(
+			scenariobuilder.NewTodoErr().
+				WithType(errors.TODOErrTypeNonExistentIssue).
+				WithLocation("scenarios/scripts/file.yml", 9).
+				ExpectLine("foo: bar # TODO 567: This is an invalid todo, marked against a non-existent issue")).
 		Run()
 	if err != nil {
 		t.Errorf("%s", err)