fix: address CI lint errors (gosec, errcheck, unparam, duplicate tests) (#730)
* fix: address CI lint errors (gosec, errcheck, unparam, duplicate tests) - Remove duplicate TestHandleDelete_DryRun and TestHandleDelete_PartialSuccess from server_mutations_test.go (already defined in server_delete_test.go) - Add nolint:gosec comments for exec.CommandContext calls in sync_branch.go (variables come from trusted config/git sources) - Fix gosec G304/G306 in yaml_config.go (file read/write permissions) - Fix errcheck in mol_run.go (templateStore.Close) - Add nolint:unparam for updateYamlKey error return * fix: add remaining nolint:gosec comments for exec.CommandContext calls - sync_branch.go: diffCmd, logCmd (dry-run), commitCmd, pushCmd, remoteCmd - sync_check.go: checkLocalCmd * fix: add more nolint:gosec comments for exec.CommandContext calls - sync_branch.go: pullCmd - sync_check.go: localRefCmd, remoteRefCmd, aheadCmd - sync_import.go: checkoutCmd * fix: add final nolint:gosec comments for exec.CommandContext calls - sync_check.go: behindCmd - sync_import.go: fetchCmd --------- Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
This commit is contained in:
@@ -83,7 +83,7 @@ func SetYamlConfig(key, value string) error {
|
||||
}
|
||||
|
||||
// Read existing config
|
||||
content, err := os.ReadFile(configPath)
|
||||
content, err := os.ReadFile(configPath) //nolint:gosec // configPath is from findProjectConfigYaml
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read config.yaml: %w", err)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func SetYamlConfig(key, value string) error {
|
||||
}
|
||||
|
||||
// Write back
|
||||
if err := os.WriteFile(configPath, []byte(newContent), 0644); err != nil {
|
||||
if err := os.WriteFile(configPath, []byte(newContent), 0600); err != nil { //nolint:gosec // configPath is validated
|
||||
return fmt.Errorf("failed to write config.yaml: %w", err)
|
||||
}
|
||||
|
||||
@@ -132,6 +132,8 @@ func findProjectConfigYaml() (string, error) {
|
||||
// updateYamlKey updates a key in yaml content, handling commented-out keys.
|
||||
// If the key exists (commented or not), it updates it in place.
|
||||
// If the key doesn't exist, it appends it at the end.
|
||||
//
|
||||
//nolint:unparam // error return kept for future validation
|
||||
func updateYamlKey(content, key, value string) (string, error) {
|
||||
// Format the value appropriately
|
||||
formattedValue := formatYamlValue(value)
|
||||
|
||||
Reference in New Issue
Block a user