fuzzyworld

template / commit

Adding linting to the project. This relies on `golangci-lint`, which has to be installed first.

75a066b28db9ef846fea1eb238822935f914a8b5 · Pavel Safronov · 2022-11-15 18:03:50 -0800 · parents afe2bedb8536

Adding linting to the project. This relies on `golangci-lint`, which has to be installed first.
 Makefile          | 31 +++++++++++++++++--------------
 config_test.go    |  8 +++++---
 default_config.go |  1 -
 extras_test.go    |  3 ++-
 file.go           | 10 ++++++++--
 5 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 21e7111..d49f1f7 100644
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,26 @@ name = ""
 
 all: build test install
 
+clean:
+	go clean
+
 build:
 	go build .
 
-install: build
+lint: build
+	golangci-lint run
+
+test: build
+	mkdir -p test
+	go test -v ./... -coverprofile="./test/coverage.out"
+
+test_coverage: test
+	go tool cover -html="./test/coverage.out" -o "./test/coverage.html"
+
+test_coverage_html: test_coverage
+	open "./test/coverage.html"
+
+install: build test lint
 	go install
 	template reset
 
@@ -32,16 +48,3 @@ else
 	go run . --profile=$(profile) --name=$(name)
 endif
 endif
-
-test: build
-	mkdir -p test
-	go test -v ./... -coverprofile="./test/coverage.out"
-
-test_coverage: test
-	go tool cover -html="./test/coverage.out" -o "./test/coverage.html"
-
-test_coverage_html: test_coverage
-	open "./test/coverage.html"
-
-clean:
-	go clean
diff --git a/config_test.go b/config_test.go
index aac86ff..1fe2e31 100644
--- a/config_test.go
+++ b/config_test.go
@@ -40,7 +40,8 @@ func TestSaveLoadConfig(t *testing.T) {
 	assert.NotNil(t, err, "Expected to fail to load config, but succeeded")
 
 	// test load invalid yaml
-	os.WriteFile("./test/invalid-yaml.yaml", []byte("invalid yaml"), 0644)
+	err = os.WriteFile("./test/invalid-yaml.yaml", []byte("invalid yaml"), 0644)
+	assert.Nil(t, err, "Error writing invalid yaml file")
 	_, err = loadConfig("./test/invalid-yaml.yaml")
 	assert.NotNil(t, err, "Expected to fail to parse config, but succeeded")
 
@@ -163,10 +164,11 @@ func TestLoadConfig(t *testing.T) {
 profiles:
     - name:
 `)
-	os.WriteFile("./test/invalid-config.yaml", bytes, 0644)
+	err := os.WriteFile("./test/invalid-config.yaml", bytes, 0644)
+	assert.Nil(t, err, "Error writing invalid config file")
 
 	// load config
-	_, err := loadConfig("./test/invalid-config.yaml")
+	_, err = loadConfig("./test/invalid-config.yaml")
 	assert.NotNil(t, err, "Expected to fail to load config, but succeeded")
 	assert.Contains(t, err.Error(), "error validating profile : Profile name is required")
 }
diff --git a/default_config.go b/default_config.go
index 7b83074..0b13e06 100644
--- a/default_config.go
+++ b/default_config.go
@@ -269,6 +269,5 @@ echo "Let's test {{.ProjectName}}!"`,
 		},
 	}
 
-	validateConfig(&config)
 	return config
 }
diff --git a/extras_test.go b/extras_test.go
index 0cbb92b..92e1a8f 100644
--- a/extras_test.go
+++ b/extras_test.go
@@ -54,7 +54,8 @@ func TestExtras(t *testing.T) {
 	_, err = loadExtras("non-existent-file.yaml")
 	assert.NotNil(t, err, "Expected error loading non-existent file")
 
-	os.WriteFile(file.Name(), []byte("invalid yaml"), 0644)
+	err = os.WriteFile(file.Name(), []byte("invalid yaml"), 0644)
+	assert.Nil(t, err, "Error writing invalid yaml file")
 	_, err = loadExtras(fileName)
 	assert.NotNil(t, err, "Expected to fail to parse extras, but succeeded")
 }
diff --git a/file.go b/file.go
index 817a8a4..bc1c208 100644
--- a/file.go
+++ b/file.go
@@ -32,10 +32,16 @@ func createFile(
 		}
 
 		templateString := sb.String()
-		monkey.OSWriteFile(fullPath, []byte(templateString), os.ModePerm)
+		err = monkey.OSWriteFile(fullPath, []byte(templateString), os.ModePerm)
+		if err != nil {
+			return fmt.Errorf("error writing file: %v", err)
+		}
 	} else {
 		log.WithFields(log.Fields{"fullPath": fullPath}).Debug("Creating empty file", fullPath)
-		monkey.OSWriteFile(fullPath, []byte{}, os.ModePerm)
+		err := monkey.OSWriteFile(fullPath, []byte{}, os.ModePerm)
+		if err != nil {
+			return fmt.Errorf("error writing file: %v", err)
+		}
 	}
 	return nil
 }