Skip to content

Commit

Permalink
[chore]: enable gofumpt linter
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 21, 2024
1 parent c9f8e8b commit 31dc31c
Show file tree
Hide file tree
Showing 132 changed files with 508 additions and 402 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ linters:
- errcheck
- errorlint
- gocritic
- gofmt
- gofumpt
- goimports
- gosec
- govet
Expand Down
1 change: 1 addition & 0 deletions client/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (e *exampleAuthData) GetAttribute(key string) any {
}
return nil
}

func (e *exampleAuthData) GetAttributeNames() []string {
return []string{"username"}
}
12 changes: 6 additions & 6 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"go.uber.org/zap"
)

const defaultBetaOtelColVersion = "v0.114.0"
const defaultStableOtelColVersion = "v1.17.0"

var (
// errMissingGoMod indicates an empty gomod field
errMissingGoMod = errors.New("missing gomod specification for module")
const (
defaultBetaOtelColVersion = "v0.114.0"
defaultStableOtelColVersion = "v1.17.0"
)

// errMissingGoMod indicates an empty gomod field
var errMissingGoMod = errors.New("missing gomod specification for module")

// Config holds the builder's configuration
type Config struct {
Logger *zap.Logger
Expand Down
4 changes: 2 additions & 2 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Generate(cfg *Config) error {

// if the file does not exist, try to create it
if _, err := os.Stat(cfg.Distribution.OutputPath); os.IsNotExist(err) {
if err = os.Mkdir(cfg.Distribution.OutputPath, 0750); err != nil {
if err = os.Mkdir(cfg.Distribution.OutputPath, 0o750); err != nil {
return fmt.Errorf("failed to create output path: %w", err)
}
} else if err != nil {
Expand Down Expand Up @@ -109,7 +109,7 @@ func Compile(cfg *Config) error {

cfg.Logger.Info("Compiling")

var ldflags = "-s -w"
ldflags := "-s -w"

args := []string{"build", "-trimpath", "-o", cfg.Distribution.Name}
if cfg.Distribution.DebugCompilation {
Expand Down
144 changes: 71 additions & 73 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,77 +37,75 @@ require (
modulePrefix = "go.opentelemetry.io/collector"
)

var (
replaceModules = []string{
"",
"/component",
"/component/componenttest",
"/component/componentstatus",
"/client",
"/config/configauth",
"/config/configcompression",
"/config/configgrpc",
"/config/confighttp",
"/config/confignet",
"/config/configopaque",
"/config/configretry",
"/config/configtelemetry",
"/config/configtls",
"/config/internal",
"/confmap",
"/confmap/provider/envprovider",
"/confmap/provider/fileprovider",
"/confmap/provider/httpprovider",
"/confmap/provider/httpsprovider",
"/confmap/provider/yamlprovider",
"/consumer",
"/consumer/consumererror",
"/consumer/consumererror/consumererrorprofiles",
"/consumer/consumerprofiles",
"/consumer/consumertest",
"/connector",
"/connector/connectortest",
"/connector/connectorprofiles",
"/exporter",
"/exporter/debugexporter",
"/exporter/exporterprofiles",
"/exporter/exportertest",
"/exporter/exporterhelper/exporterhelperprofiles",
"/exporter/nopexporter",
"/exporter/otlpexporter",
"/exporter/otlphttpexporter",
"/extension",
"/extension/auth",
"/extension/auth/authtest",
"/extension/experimental/storage",
"/extension/extensioncapabilities",
"/extension/extensiontest",
"/extension/zpagesextension",
"/featuregate",
"/internal/memorylimiter",
"/internal/fanoutconsumer",
"/internal/sharedcomponent",
"/otelcol",
"/pipeline",
"/pipeline/pipelineprofiles",
"/processor",
"/processor/processortest",
"/processor/batchprocessor",
"/processor/memorylimiterprocessor",
"/processor/processorprofiles",
"/receiver",
"/receiver/nopreceiver",
"/receiver/otlpreceiver",
"/receiver/receiverprofiles",
"/receiver/receivertest",
"/pdata",
"/pdata/testdata",
"/pdata/pprofile",
"/scraper",
"/semconv",
"/service",
}
)
var replaceModules = []string{
"",
"/component",
"/component/componenttest",
"/component/componentstatus",
"/client",
"/config/configauth",
"/config/configcompression",
"/config/configgrpc",
"/config/confighttp",
"/config/confignet",
"/config/configopaque",
"/config/configretry",
"/config/configtelemetry",
"/config/configtls",
"/config/internal",
"/confmap",
"/confmap/provider/envprovider",
"/confmap/provider/fileprovider",
"/confmap/provider/httpprovider",
"/confmap/provider/httpsprovider",
"/confmap/provider/yamlprovider",
"/consumer",
"/consumer/consumererror",
"/consumer/consumererror/consumererrorprofiles",
"/consumer/consumerprofiles",
"/consumer/consumertest",
"/connector",
"/connector/connectortest",
"/connector/connectorprofiles",
"/exporter",
"/exporter/debugexporter",
"/exporter/exporterprofiles",
"/exporter/exportertest",
"/exporter/exporterhelper/exporterhelperprofiles",
"/exporter/nopexporter",
"/exporter/otlpexporter",
"/exporter/otlphttpexporter",
"/extension",
"/extension/auth",
"/extension/auth/authtest",
"/extension/experimental/storage",
"/extension/extensioncapabilities",
"/extension/extensiontest",
"/extension/zpagesextension",
"/featuregate",
"/internal/memorylimiter",
"/internal/fanoutconsumer",
"/internal/sharedcomponent",
"/otelcol",
"/pipeline",
"/pipeline/pipelineprofiles",
"/processor",
"/processor/processortest",
"/processor/batchprocessor",
"/processor/memorylimiterprocessor",
"/processor/processorprofiles",
"/receiver",
"/receiver/nopreceiver",
"/receiver/otlpreceiver",
"/receiver/receiverprofiles",
"/receiver/receivertest",
"/pdata",
"/pdata/testdata",
"/pdata/pprofile",
"/scraper",
"/semconv",
"/service",
}

func newTestConfig(t testing.TB) *Config {
cfg, err := NewDefaultConfig()
Expand Down Expand Up @@ -429,14 +427,14 @@ func verifyGoMod(t *testing.T, dir string, replaceMods map[string]bool) {
func makeModule(dir string, fileContents []byte) error {
// if the file does not exist, try to create it
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err = os.Mkdir(dir, 0750); err != nil {
if err = os.Mkdir(dir, 0o750); err != nil {
return fmt.Errorf("failed to create output path: %w", err)
}
} else if err != nil {
return fmt.Errorf("failed to create output path: %w", err)
}

err := os.WriteFile(filepath.Clean(filepath.Join(dir, "go.mod")), fileContents, 0600)
err := os.WriteFile(filepath.Clean(filepath.Join(dir, "go.mod")), fileContents, 0o600)
if err != nil {
return fmt.Errorf("failed to write go.mod file: %w", err)
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/builder/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/spf13/cobra"
)

var (
version = ""
)
var version = ""

func init() {
// the second returned value is a boolean, which is true if the binaries are built with module support.
Expand Down
10 changes: 5 additions & 5 deletions cmd/mdatagen/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func run(ymlPath string) error {
tmplDir := "templates"

codeDir := filepath.Join(ymlDir, "internal", md.GeneratedPackageName)
if err = os.MkdirAll(codeDir, 0700); err != nil {
if err = os.MkdirAll(codeDir, 0o700); err != nil {
return fmt.Errorf("unable to create output directory %q: %w", codeDir, err)
}
if md.Status != nil {
Expand Down Expand Up @@ -130,7 +130,7 @@ func run(ymlPath string) error {
return nil
}

if err = os.MkdirAll(filepath.Join(codeDir, "testdata"), 0700); err != nil {
if err = os.MkdirAll(filepath.Join(codeDir, "testdata"), 0o700); err != nil {
return fmt.Errorf("unable to create output directory %q: %w", filepath.Join(codeDir, "testdata"), err)
}

Expand Down Expand Up @@ -376,7 +376,7 @@ func inlineReplace(tmplFile string, outputFile string, md Metadata, start string
return err
}

var re = regexp.MustCompile(fmt.Sprintf("%s[\\s\\S]*%s", start, end))
re := regexp.MustCompile(fmt.Sprintf("%s[\\s\\S]*%s", start, end))
if !re.Match(readmeContents) {
return nil
}
Expand All @@ -391,7 +391,7 @@ func inlineReplace(tmplFile string, outputFile string, md Metadata, start string
}

s := re.ReplaceAllString(string(readmeContents), string(buf))
if err := os.WriteFile(outputFile, []byte(s), 0600); err != nil {
if err := os.WriteFile(outputFile, []byte(s), 0o600); err != nil {
return fmt.Errorf("failed writing %q: %w", outputFile, err)
}

Expand All @@ -416,7 +416,7 @@ func generateFile(tmplFile string, outputFile string, md Metadata, goPackage str
}
}

if err := os.WriteFile(outputFile, result, 0600); err != nil {
if err := os.WriteFile(outputFile, result, 0o600); err != nil {
return fmt.Errorf("failed writing %q: %w", outputFile, err)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/mdatagen/internal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ func TestRunContents(t *testing.T) {
for _, tt := range tests {
t.Run(tt.yml, func(t *testing.T) {
tmpdir := filepath.Join(t.TempDir(), "shortname")
err := os.MkdirAll(tmpdir, 0750)
err := os.MkdirAll(tmpdir, 0o750)
require.NoError(t, err)
ymlContent, err := os.ReadFile(filepath.Join("testdata", tt.yml))
require.NoError(t, err)
metadataFile := filepath.Join(tmpdir, "metadata.yaml")
require.NoError(t, os.WriteFile(metadataFile, ymlContent, 0600))
require.NoError(t, os.WriteFile(metadataFile, ymlContent, 0o600))
require.NoError(t, os.WriteFile(filepath.Join(tmpdir, "README.md"), []byte(`
<!-- status autogenerated section -->
foo
<!-- end autogenerated section -->`), 0600))
<!-- end autogenerated section -->`), 0o600))

err = run(metadataFile)
if tt.wantErr {
Expand Down Expand Up @@ -472,7 +472,7 @@ Some info about a component
tmpdir := t.TempDir()

readmeFile := filepath.Join(tmpdir, "README.md")
require.NoError(t, os.WriteFile(readmeFile, []byte(tt.markdown), 0600))
require.NoError(t, os.WriteFile(readmeFile, []byte(tt.markdown), 0o600))

err := inlineReplace("templates/readme.md.tmpl", readmeFile, md, statusStart, statusEnd, "metadata")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/internal/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestFormatIdentifier(t *testing.T) {
var tests = []struct {
tests := []struct {
input string
want string
exported bool
Expand Down
1 change: 1 addition & 0 deletions cmd/mdatagen/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (m *Metric) Unmarshal(parser *confmap.Conf) error {
}
return parser.Unmarshal(m)
}

func (m Metric) Data() MetricData {
if m.Sum != nil {
return m.Sum
Expand Down
6 changes: 4 additions & 2 deletions component/componentstatus/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ func Test_ReportStatus(t *testing.T) {
})
}

var _ = (component.Host)(nil)
var _ = (Reporter)(nil)
var (
_ = (component.Host)(nil)
_ = (Reporter)(nil)
)

type reporter struct {
reportStatusCalled bool
Expand Down
2 changes: 1 addition & 1 deletion component/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newErrMapType() *errMapType {
}

func TestValidateConfig(t *testing.T) {
var tests = []struct {
tests := []struct {
name string
cfg any
expected error
Expand Down
2 changes: 1 addition & 1 deletion component/identifiable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMarshalText(t *testing.T) {

func TestUnmarshalText(t *testing.T) {
validType := MustNewType("valid_type")
var testCases = []struct {
testCases := []struct {
name string
expectedErr bool
expectedID ID
Expand Down
Loading

0 comments on commit 31dc31c

Please sign in to comment.