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

Go code cleanup #1148

Merged
merged 1 commit into from
Sep 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build/dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"indentBlockSequenceInMap": true
},
"json": {},
"excludes": [],
"excludes": [
"**/testdata/**"
],
"plugins": [
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm",
"https://plugins.dprint.dev/json-0.19.3.wasm"
Expand Down
18 changes: 6 additions & 12 deletions cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ The linter rules with automatic fixes available are currently:
},

RunE: wrapProfiling(func(args []string) error {
err := fix(args, params)
if err != nil {
if err := fix(args, params); err != nil {
log.SetOutput(os.Stderr)
log.Println(err)

Expand Down Expand Up @@ -339,8 +338,7 @@ func fix(args []string, params *fixCommandParams) error {
}

if fixReport.HasConflicts() {
err = r.Report(fixReport)
if err != nil {
if err = r.Report(fixReport); err != nil {
return fmt.Errorf("failed to output fix report: %w", err)
}

Expand Down Expand Up @@ -425,8 +423,7 @@ please run fix from a clean state to support the use of git checkout for undo`,
}

for _, dir := range dirs {
err := os.Remove(dir)
if err != nil {
if err := os.Remove(dir); err != nil {
return fmt.Errorf("failed to delete directory %s: %w", dir, err)
}
}
Expand All @@ -445,20 +442,17 @@ please run fix from a clean state to support the use of git checkout for undo`,
fileMode = fileInfo.Mode()
}

err = os.MkdirAll(filepath.Dir(file), 0o755)
if err != nil {
if err = os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
return fmt.Errorf("failed to create directory for file %s: %w", file, err)
}

err = os.WriteFile(file, fc, fileMode)
if err != nil {
if err = os.WriteFile(file, fc, fileMode); err != nil {
return fmt.Errorf("failed to write file %s: %w", file, err)
}
}
}

err = r.Report(fixReport)
if err != nil {
if err = r.Report(fixReport); err != nil {
return fmt.Errorf("failed to output fix report: %w", err)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ func formatError(format string, err error) error {

buf := &bytes.Buffer{}

err := testSuites.WriteXML(buf)
if err != nil {
if err := testSuites.WriteXML(buf); err != nil {
return fmt.Errorf("failed to format errors for output: %w", err)
}

Expand Down
18 changes: 6 additions & 12 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ func addToDataYAML(params newRuleCommandParams) error {
yamlEncoder := yaml.NewEncoder(&b)
yamlEncoder.SetIndent(2)

err = yamlEncoder.Encode(existingConfig)
if err != nil {
if err = yamlEncoder.Encode(existingConfig); err != nil {
return err
}

Expand Down Expand Up @@ -241,8 +240,7 @@ func scaffoldCustomRule(params newRuleCommandParams) error {
return err
}

err = ruleTmpl.Execute(ruleFile, templateValues(params))
if err != nil {
if err = ruleTmpl.Execute(ruleFile, templateValues(params)); err != nil {
return err
}

Expand All @@ -258,8 +256,7 @@ func scaffoldCustomRule(params newRuleCommandParams) error {
return err
}

err = testTmpl.Execute(testFile, templateValues(params))
if err != nil {
if err = testTmpl.Execute(testFile, templateValues(params)); err != nil {
return err
}

Expand Down Expand Up @@ -287,8 +284,7 @@ func scaffoldBuiltinRule(params newRuleCommandParams) error {
return err
}

err = ruleTmpl.Execute(ruleFile, templateValues(params))
if err != nil {
if err = ruleTmpl.Execute(ruleFile, templateValues(params)); err != nil {
return err
}

Expand All @@ -304,8 +300,7 @@ func scaffoldBuiltinRule(params newRuleCommandParams) error {
return err
}

err = testTmpl.Execute(testFile, templateValues(params))
if err != nil {
if err = testTmpl.Execute(testFile, templateValues(params)); err != nil {
return err
}

Expand Down Expand Up @@ -335,8 +330,7 @@ func createBuiltinDocs(params newRuleCommandParams) error {
return err
}

err = docTmpl.Execute(docFile, templateValues(params))
if err != nil {
if err = docTmpl.Execute(docFile, templateValues(params)); err != nil {
return err
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func init() {
case formatJSON:
e := encoding.JSON().NewEncoder(os.Stdout)
e.SetIndent("", " ")
err := e.Encode(vi)
if err != nil {
if err := e.Encode(vi); err != nil {
log.SetOutput(os.Stderr)
log.Println(err)
os.Exit(1)
Expand Down
Loading