Skip to content

Commit 5ee5ab0

Browse files
authored
Merge pull request tinkerbell#30 from mmlb/fix-golangci-config-name
2 parents 6f6d11e + 6b49b6e commit 5ee5ab0

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Binaries for programs and plugins
2+
/lint-install
23
*.exe
34
*.exe~
45
*.dll

lint-install.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ func updateMakefile(root string, cfg Config, dryRun bool) (string, error) {
149149
}
150150

151151
// updateFile updates a configuration file within a project.
152+
// If the content is nil the file is removed.
152153
func updateFile(root string, basename string, content []byte, dryRun bool) (string, error) {
153154
dest := filepath.Join(root, basename)
154155
var existing []byte
155-
var err error
156156

157-
if _, err = os.Stat(dest); err == nil {
157+
f, err := os.Stat(dest)
158+
if err == nil {
158159
klog.Infof("Found existing %s", dest)
159160
existing, err = os.ReadFile(dest)
160161
if err != nil {
@@ -167,7 +168,18 @@ func updateFile(root string, basename string, content []byte, dryRun bool) (stri
167168
change := gotextdiff.ToUnified(basename, basename, string(existing), edits)
168169

169170
if !dryRun {
170-
if err := os.WriteFile(dest, content, 0o600); err != nil {
171+
var err error
172+
if content == nil {
173+
// must be broken up, can't be conten == nil && f != nil because then
174+
// the else branch will be taken if the file does *not* exist and
175+
// an empty file will be written
176+
if f != nil {
177+
err = os.Remove(dest)
178+
}
179+
} else {
180+
err = os.WriteFile(dest, content, 0o600)
181+
}
182+
if err != nil {
171183
return "", err
172184
}
173185
}
@@ -310,7 +322,7 @@ func main() {
310322
cfg.LintCommands = append(cfg.LintCommands, goLintCmd(root, cfg.Go, false))
311323
cfg.FixCommands = append(cfg.FixCommands, goLintCmd(root, cfg.Go, true))
312324

313-
diff, err := updateFile(root, ".golangci.yaml", goLintConfig, *dryRunFlag)
325+
diff, err := updateFile(root, ".golangci.yml", goLintConfig, *dryRunFlag)
314326
if err != nil {
315327
klog.Exitf("update go lint config failed: %v", err)
316328
}
@@ -319,6 +331,16 @@ func main() {
319331
} else {
320332
klog.Infof("go lint config has no changes")
321333
}
334+
335+
for _, name := range []string{".golangci.json", ".golangci.toml", ".golangci.yaml"} {
336+
diff, err := updateFile(root, name, nil, *dryRunFlag)
337+
if err != nil {
338+
klog.Exitf("deleting non-standardized go lint config failed: %v", err)
339+
}
340+
if diff != "" {
341+
klog.Infof("standardizing on golangci.yml, deleting %s", name)
342+
}
343+
}
322344
}
323345
if needs[Dockerfile] {
324346
cfg.Dockerfile = *dockerfileFlag

0 commit comments

Comments
 (0)