From 14f24c8b84514aa6dfab410ed48eec5f334a312b Mon Sep 17 00:00:00 2001 From: Caleb Albers Date: Fri, 22 Jul 2022 15:14:32 -0700 Subject: [PATCH 1/2] Add support for .nomad and .tfvars (HCL) HashiCorp Nomad users occasionally use the (discouraged) `.nomad` extension for HCL-based configurations. Likewise, `.tfvars` is frequently used in the Terraform realm. Both of these file formats follow the same form as HCL, just with differing extensions. --- main.go | 2 +- testdata/expected/file.nomad | 19 +++++++++++++++++++ testdata/expected/file.tfvars | 16 ++++++++++++++++ testdata/initial/file.nomad | 5 +++++ testdata/initial/file.tfvars | 2 ++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 testdata/expected/file.nomad create mode 100644 testdata/expected/file.tfvars create mode 100644 testdata/initial/file.nomad create mode 100644 testdata/initial/file.tfvars diff --git a/main.go b/main.go index b2ef240..69b8be4 100644 --- a/main.go +++ b/main.go @@ -293,7 +293,7 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by lic, err = executeTemplate(tmpl, data, "/**", " * ", " */") case ".cc", ".cpp", ".cs", ".go", ".hcl", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv": lic, err = executeTemplate(tmpl, data, "", "// ", "") - case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".tcl", ".bzl", ".pl", ".pp": + case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".nomad", ".tcl", ".tfvars", ".bzl", ".pl", ".pp": lic, err = executeTemplate(tmpl, data, "", "# ", "") case ".el", ".lisp": lic, err = executeTemplate(tmpl, data, "", ";; ", "") diff --git a/testdata/expected/file.nomad b/testdata/expected/file.nomad new file mode 100644 index 0000000..a660157 --- /dev/null +++ b/testdata/expected/file.nomad @@ -0,0 +1,19 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +job "example" { + region = "us" + + group "app" {} +} diff --git a/testdata/expected/file.tfvars b/testdata/expected/file.tfvars new file mode 100644 index 0000000..f189b1b --- /dev/null +++ b/testdata/expected/file.tfvars @@ -0,0 +1,16 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable1 = "foo" +variable2 = "bar" diff --git a/testdata/initial/file.nomad b/testdata/initial/file.nomad new file mode 100644 index 0000000..ed02e12 --- /dev/null +++ b/testdata/initial/file.nomad @@ -0,0 +1,5 @@ +job "example" { + region = "us" + + group "app" {} +} diff --git a/testdata/initial/file.tfvars b/testdata/initial/file.tfvars new file mode 100644 index 0000000..efe19dd --- /dev/null +++ b/testdata/initial/file.tfvars @@ -0,0 +1,2 @@ +variable1 = "foo" +variable2 = "bar" From 12435d44c5f928eacef4bc02a84f302e51f2d113 Mon Sep 17 00:00:00 2001 From: Caleb Albers Date: Mon, 1 Aug 2022 17:08:10 -0700 Subject: [PATCH 2/2] Update test table from code review --- main_test.go | 2 +- testdata/expected/file.nomad | 19 ------------------- testdata/expected/file.tfvars | 16 ---------------- testdata/initial/file.nomad | 5 ----- testdata/initial/file.tfvars | 2 -- 5 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 testdata/expected/file.nomad delete mode 100644 testdata/expected/file.tfvars delete mode 100644 testdata/initial/file.nomad delete mode 100644 testdata/initial/file.tfvars diff --git a/main_test.go b/main_test.go index 9b0df64..f3d483d 100644 --- a/main_test.go +++ b/main_test.go @@ -316,7 +316,7 @@ func TestLicenseHeader(t *testing.T) { "// HYS\n\n", }, { - []string{"f.py", "f.sh", "f.yaml", "f.yml", "f.dockerfile", "dockerfile", "f.rb", "gemfile", "f.tcl", "f.bzl", "f.pl", "f.pp"}, + []string{"f.py", "f.sh", "f.yaml", "f.yml", "f.dockerfile", "dockerfile", "f.rb", "gemfile", "f.tcl", "f.bzl", "f.pl", "f.pp", "f.nomad", "f.tfvars"}, "# HYS\n\n", }, { diff --git a/testdata/expected/file.nomad b/testdata/expected/file.nomad deleted file mode 100644 index a660157..0000000 --- a/testdata/expected/file.nomad +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2018 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -job "example" { - region = "us" - - group "app" {} -} diff --git a/testdata/expected/file.tfvars b/testdata/expected/file.tfvars deleted file mode 100644 index f189b1b..0000000 --- a/testdata/expected/file.tfvars +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2018 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -variable1 = "foo" -variable2 = "bar" diff --git a/testdata/initial/file.nomad b/testdata/initial/file.nomad deleted file mode 100644 index ed02e12..0000000 --- a/testdata/initial/file.nomad +++ /dev/null @@ -1,5 +0,0 @@ -job "example" { - region = "us" - - group "app" {} -} diff --git a/testdata/initial/file.tfvars b/testdata/initial/file.tfvars deleted file mode 100644 index efe19dd..0000000 --- a/testdata/initial/file.tfvars +++ /dev/null @@ -1,2 +0,0 @@ -variable1 = "foo" -variable2 = "bar"