Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept .yml files as well as .yaml for templates. #3646

Merged
merged 1 commit into from Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/lint/rules/template.go
Expand Up @@ -101,7 +101,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
linter.RunLinterRule(support.ErrorSev, path, validateAllowedExtension(fileName))

// We only apply the following lint rules to yaml files
if filepath.Ext(fileName) != ".yaml" {
if filepath.Ext(fileName) != ".yaml" || filepath.Ext(fileName) == ".yml" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be != ".yml"?

Copy link
Contributor Author

@nicdoye nicdoye Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. In fact, it should be:

filepath.Ext(fileName) != ".yaml" && filepath.Ext(fileName) != ".yml"

as we only want to go to continue if it's not .yaml and it's not .yml.

continue
}

Expand Down Expand Up @@ -138,15 +138,15 @@ func validateTemplatesDir(templatesPath string) error {

func validateAllowedExtension(fileName string) error {
ext := filepath.Ext(fileName)
validExtensions := []string{".yaml", ".tpl", ".txt"}
validExtensions := []string{".yaml", ".yml", ".tpl", ".txt"}

for _, b := range validExtensions {
if b == ext {
return nil
}
}

return fmt.Errorf("file extension '%s' not valid. Valid extensions are .yaml, .tpl, or .txt", ext)
return fmt.Errorf("file extension '%s' not valid. Valid extensions are .yaml, .yml, .tpl, or .txt", ext)
}

func validateYamlContent(err error) error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/lint/rules/template_test.go
Expand Up @@ -28,11 +28,11 @@ import (
const templateTestBasedir = "./testdata/albatross"

func TestValidateAllowedExtension(t *testing.T) {
var failTest = []string{"/foo", "/test.yml", "/test.toml", "test.yml"}
var failTest = []string{"/foo", "/test.toml"}
for _, test := range failTest {
err := validateAllowedExtension(test)
if err == nil || !strings.Contains(err.Error(), "Valid extensions are .yaml, .tpl, or .txt") {
t.Errorf("validateAllowedExtension('%s') to return \"Valid extensions are .yaml, .tpl, or .txt\", got no error", test)
if err == nil || !strings.Contains(err.Error(), "Valid extensions are .yaml, .yml, .tpl, or .txt") {
t.Errorf("validateAllowedExtension('%s') to return \"Valid extensions are .yaml, .yml, .tpl, or .txt\", got no error", test)
}
}
var successTest = []string{"/foo.yaml", "foo.yaml", "foo.tpl", "/foo/bar/baz.yaml", "NOTES.txt"}
Expand Down