Repository: twpayne/chezmoi
Pull request #282 (2019-05-03 21:25:46)

Add pre-release-checks target


Patch:
diff --git a/Makefile b/Makefile
index c3d83ca43..031f99395 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,6 @@ coverage.out:
 
 .PHONY: format
 format:
-	find . -name \*.go | xargs gofumpt -w
 	find . -name \*.go | xargs gofumports -w
 
 .PHONY: generate
@@ -25,6 +24,13 @@ lint:
 	go vet ./...
 	golangci-lint run
 
+.PHONY: pre-release-checks
+pre-release-checks: strict-lint
+
+.PHONY: strict-lint
+strict-lint:
+	golangci-lint run --enable-all ./...
+
 .PHONY: test
 test:
 	go test -race ./...
\ No newline at end of file
diff --git a/cmd/chattr.go b/cmd/chattr.go
index 18d3ec2de..562093768 100644
--- a/cmd/chattr.go
+++ b/cmd/chattr.go
@@ -131,7 +131,7 @@ func (c *Config) runChattrCmd(fs vfs.FS, args []string) error {
 
 	// Sort oldpaths in reverse so we update files before their parent
 	// directories.
-	oldpaths := make([]string, 0, len(updates))
+	var oldpaths []string
 	for oldpath := range updates {
 		oldpaths = append(oldpaths, oldpath)
 	}
diff --git a/cmd/upgrade.go b/cmd/upgrade.go
index dca7e0e06..39adb2fbf 100644
--- a/cmd/upgrade.go
+++ b/cmd/upgrade.go
@@ -121,7 +121,7 @@ func (c *Config) runUpgradeCmd(fs vfs.FS, args []string) error {
 	// already the latest version.
 	if !c.upgrade.force && VersionStr != devVersionStr {
 		if !Version.LessThan(*releaseVersion) {
-			fmt.Fprintf(c.Stdout(), "chezmoi: already at the latest version (%s)\n", Version)
+			fmt.Fprintf(c.Stdout(), "chezmoi: already at the latest version (%s)", Version)
 			return nil
 		}
 	}
diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md
index 485147379..e74608aed 100644
--- a/docs/CONTRIBUTING.md
+++ b/docs/CONTRIBUTING.md
@@ -25,6 +25,13 @@ that:
 
 Releases are managed with [goreleaser](https://goreleaser.com/).
 
+Before creating a release, please run:
+
+    make pre-release-checks
+
+This will run a variety of strict checks. Many can be ignored, but please
+manually check each of them before tagging a release.
+
 To create a new release, push a tag, eg:
 
     git tag -a v0.1.0 -m "First release"
diff --git a/lib/chezmoi/autotemplate.go b/lib/chezmoi/autotemplate.go
index 94def856a..3f370a8ff 100644
--- a/lib/chezmoi/autotemplate.go
+++ b/lib/chezmoi/autotemplate.go
@@ -26,7 +26,7 @@ func (b byValueLength) Less(i, j int) bool {
 }
 func (b byValueLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
 
-func autoTemplate(contents []byte, data map[string]interface{}) ([]byte, error) {
+func autoTemplate(contents []byte, data map[string]interface{}) []byte {
 	// FIXME this naive approach will generate incorrect templates if the
 	// variable names match variable values
 	// FIXME the algorithm here is probably O(N^2), we can do better
@@ -61,7 +61,7 @@ func autoTemplate(contents []byte, data map[string]interface{}) ([]byte, error)
 			}
 		}
 	}
-	return []byte(contentsStr), nil
+	return []byte(contentsStr)
 }
 
 func extractVariables(variables []templateVariable, parent []string, data map[string]interface{}) []templateVariable {
diff --git a/lib/chezmoi/targetstate.go b/lib/chezmoi/targetstate.go
index 8e6caa495..f6fa8866d 100644
--- a/lib/chezmoi/targetstate.go
+++ b/lib/chezmoi/targetstate.go
@@ -130,10 +130,7 @@ func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string,
 			return err
 		}
 		if addOptions.Template {
-			contents, err = autoTemplate(contents, ts.Data)
-			if err != nil {
-				return err
-			}
+			contents = autoTemplate(contents, ts.Data)
 		}
 		if addOptions.Encrypt {
 			contents, err = ts.Encrypt(contents)


Test patch:
diff --git a/lib/chezmoi/autotemplate_test.go b/lib/chezmoi/autotemplate_test.go
index 8f1d895c0..aed082b65 100644
--- a/lib/chezmoi/autotemplate_test.go
+++ b/lib/chezmoi/autotemplate_test.go
@@ -124,9 +124,7 @@ func TestAutoTemplate(t *testing.T) {
 		},
 	} {
 		t.Run(tc.name, func(t *testing.T) {
-			got, gotErr := autoTemplate([]byte(tc.contentsStr), tc.data)
-			assert.NoError(t, gotErr)
-			assert.Equal(t, tc.wantStr, string(got))
+			assert.Equal(t, tc.wantStr, string(autoTemplate([]byte(tc.contentsStr), tc.data)))
 		})
 	}
 }