Skip to content
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ jobs:
run: sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.61.0
version: v2.3
args: --verbose --timeout 5m0s

shellcheck:
Expand Down
73 changes: 56 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
---
linters-settings:
govet:
disable:
- shadow # default value recommended by golangci
- composites
gosec:
excludes:
- G101
version: "2"
run:
build-tags:
- integration

linters:
enable:
- gosec

run:
build-tags:
- integration
timeout: 5m
- gomoddirectives
- staticcheck
settings:
gosec:
excludes:
- G101
govet:
disable:
# default value recommended by golangci
- shadow
- composites
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- gosec
path: ^(images/)?(pkg|internal)/.*_test\.go$
# unnecessary field selector
Comment thread
lzap marked this conversation as resolved.
- linters:
- staticcheck
text: "QF1008"
# error strings should not be capitalized
Comment thread
lzap marked this conversation as resolved.
- linters:
- staticcheck
text: "ST1005"
# unicode control character
- linters:
- staticcheck
path: ^(images/)?(pkg|internal)/.*_test\.go$
text: "ST1018"
# possible nil pointer dereference (many false alerts when t.Skip is used)
- linters:
- staticcheck
path: ^(images/)?(pkg|internal|internal/test)/(.*_test|helpers)\.go$
text: "SA5011"
paths:
- third_party$
- builtin$
- examples$

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default
# is 3.
max-same-issues: 0
exclude-rules:
- path: ^(images/)?(pkg|internal)/.*_test\.go$
linters: ["gosec"]

formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func u(s string) string {
return strings.Replace(s, "-", "_", -1)
return strings.ReplaceAll(s, "-", "_")
}

func run() error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func filterRepos(repos []rpmmd.RepoConfig, typeName string) []rpmmd.RepoConfig {
}

func u(s string) string {
return strings.Replace(s, "-", "_", -1)
return strings.ReplaceAll(s, "-", "_")
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/otk/osbuild-make-partition-stages/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestIntegration(t *testing.T) {
func TestModificationFname(t *testing.T) {
input := minimalInputBase
input.Tree.Const.Filename = "mydisk.img2"
expectedStages := strings.Replace(minimalExpectedStages, `"disk.img"`, `"mydisk.img2"`, -1)
expectedStages := strings.ReplaceAll(minimalExpectedStages, `"disk.img"`, `"mydisk.img2"`)

inpJSON, err := json.Marshal(&input)
assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions internal/assertx/testify_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
// needed until https://github.com/stretchr/testify/issues/1304 is fixed
func PanicsWithErrorRegexp(t assert.TestingT, reg *regexp.Regexp, f assert.PanicTestFunc) (assertOk bool) {
defer func() {
var message interface{} // nolint: gosimple

message = recover()
message := recover()
if message == nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions internal/common/pointers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

func TestToPtr(t *testing.T) {
var valueInt int = 42
valueInt := 42
Comment thread
lzap marked this conversation as resolved.
gotInt := ToPtr(valueInt)
assert.Equal(t, valueInt, *gotInt)

var valueBool bool = true
valueBool := true
gotBool := ToPtr(valueBool)
assert.Equal(t, valueBool, *gotBool)

var valueUint64 uint64 = 1
valueUint64 := uint64(1)
gotUint64 := ToPtr(valueUint64)
assert.Equal(t, valueUint64, *gotUint64)

var valueStr string = "the-greatest-test-value"
valueStr := "the-greatest-test-value"
gotStr := ToPtr(valueStr)
assert.Equal(t, valueStr, *gotStr)

Expand Down
7 changes: 4 additions & 3 deletions internal/testregistry/testregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ func (reg *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

if cmd == "manifests" {
switch cmd {
case "manifests":
repo.ServeManifest(ref, w, req)
} else if cmd == "blobs" {
case "blobs":
repo.ServeBlob(ref, w, req)
} else {
default:
http.NotFound(w, req)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/defs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var defaultDataFS fs.FS = distrodefs.Data
func dataFS() fs.FS {
// XXX: this is a short term measure, pass a set of
// searchPaths down the stack instead
var dataFS fs.FS = defaultDataFS
dataFS := defaultDataFS
if overrideDir := experimentalflags.String("yamldir"); overrideDir != "" {
olog.Printf("WARNING: using experimental override dir %q", overrideDir)
dataFS = os.DirFS(overrideDir)
Expand Down
13 changes: 7 additions & 6 deletions pkg/distro/generic/fedora_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,18 @@ func TestFedoraDistro_ManifestError(t *testing.T) {
Size: imgType.Size(0),
}
_, _, err := imgType.Manifest(&bp, imgOpts, nil, nil)
if imgTypeName == "iot-commit" || imgTypeName == "iot-container" || imgTypeName == "iot-bootable-container" {
switch imgTypeName {
case "iot-commit", "iot-container", "iot-bootable-container":
assert.EqualError(t, err, "kernel boot parameter customizations are not supported for ostree types")
} else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" {
case "iot-installer", "iot-simplified-installer":
assert.EqualError(t, err, fmt.Sprintf("boot ISO image type \"%s\" requires specifying a URL from which to retrieve the OSTree commit", imgTypeName))
} else if imgTypeName == "minimal-installer" {
case "minimal-installer":
assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, FIPS, Installer, Timezone, Locale"))
} else if imgTypeName == "workstation-live-installer" {
case "workstation-live-installer":
assert.EqualError(t, err, fmt.Sprintf(distro.NoCustomizationsAllowedError, imgTypeName))
} else if imgTypeName == "iot-raw-xz" || imgTypeName == "iot-qcow2" {
case "iot-raw-xz", "iot-qcow2":
assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, Directories, Files, Services, FIPS"))
} else {
default:
assert.NoError(t, err)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/distro/generic/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func checkOptionsRhel9(t *imageType, bp *blueprint.Blueprint, options distro.Ima
}
if (mountpoints != nil || partitioning != nil) && t.RPMOSTree && (t.Name() == "edge-container" || t.Name() == "edge-commit") {
return warnings, fmt.Errorf("custom mountpoints and partitioning are not supported for ostree types")
} else if (mountpoints != nil || partitioning != nil) && t.RPMOSTree && !(t.Name() == "edge-container" || t.Name() == "edge-commit") {
} else if (mountpoints != nil || partitioning != nil) && t.RPMOSTree && (t.Name() != "edge-container" && t.Name() != "edge-commit") {
//customization allowed for edge-raw-image,edge-ami,edge-vsphere,edge-simplified-installer
err := blueprint.CheckMountpointsPolicy(mountpoints, policies.OstreeMountpointPolicies)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/distro/generic/rhel8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,14 @@ func TestRH8_Distro_ManifestError(t *testing.T) {
Size: imgType.Size(0),
}
_, _, err := imgType.Manifest(&bp, imgOpts, nil, nil)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
switch imgTypeName {
case "edge-commit", "edge-container":
assert.EqualError(t, err, "kernel boot parameter customizations are not supported for ostree types")
} else if imgTypeName == "edge-raw-image" {
case "edge-raw-image":
assert.EqualError(t, err, fmt.Sprintf("%q images require specifying a URL from which to retrieve the OSTree commit", imgTypeName))
} else if imgTypeName == "edge-installer" || imgTypeName == "edge-simplified-installer" {
case "edge-installer", "edge-simplified-installer":
assert.EqualError(t, err, fmt.Sprintf("boot ISO image type %q requires specifying a URL from which to retrieve the OSTree commit", imgTypeName))
} else {
default:
assert.NoError(t, err)
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/distro/generic/rhel9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,16 @@ func TestRhel9_Distro_ManifestError(t *testing.T) {
Size: imgType.Size(0),
}
_, _, err := imgType.Manifest(&bp, imgOpts, nil, nil)
if imgTypeName == "edge-commit" || imgTypeName == "edge-container" {
switch imgTypeName {
case "edge-commit", "edge-container":
assert.EqualError(t, err, "kernel boot parameter customizations are not supported for ostree types")
} else if imgTypeName == "edge-raw-image" || imgTypeName == "edge-ami" || imgTypeName == "edge-vsphere" {
case "edge-raw-image", "edge-ami", "edge-vsphere":
assert.EqualError(t, err, fmt.Sprintf("\"%s\" images require specifying a URL from which to retrieve the OSTree commit", imgTypeName))
} else if imgTypeName == "edge-installer" || imgTypeName == "edge-simplified-installer" {
case "edge-installer", "edge-simplified-installer":
assert.EqualError(t, err, fmt.Sprintf("boot ISO image type \"%s\" requires specifying a URL from which to retrieve the OSTree commit", imgTypeName))
} else if imgTypeName == "azure-cvm" {
case "azure-cvm":
assert.EqualError(t, err, fmt.Sprintf("kernel customizations are not supported for %q", imgTypeName))
} else {
default:
assert.NoError(t, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (r *Request) Hash() string {
for _, repo := range r.Arguments.Repos {
h.Write([]byte(repo.Hash()))
}
h.Write([]byte(fmt.Sprintf("%T", r.Arguments.Search.Latest)))
fmt.Fprintf(h, "%T", r.Arguments.Search.Latest)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Commit message says "use sprintf" instead of "use fprintf".

h.Write([]byte(strings.Join(r.Arguments.Search.Packages, "")))

return fmt.Sprintf("%x", h.Sum(nil))
Expand Down Expand Up @@ -849,7 +849,7 @@ func parseError(data []byte, repos []repoConfig) Error {
if len(repo.Name) > 0 {
nameURL = fmt.Sprintf("%s: %s", repo.Name, nameURL)
}
e.Reason = strings.Replace(e.Reason, idstr, fmt.Sprintf("%s [%s]", idstr, nameURL), -1)
e.Reason = strings.ReplaceAll(e.Reason, idstr, fmt.Sprintf("%s [%s]", idstr, nameURL))
}

return e
Expand Down
6 changes: 3 additions & 3 deletions pkg/manifest/anaconda_installer_iso_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ func (p *AnacondaInstallerISOTree) serialize() osbuild.Pipeline {
default:
}

if p.ISOBoot == SyslinuxISOBoot {
switch p.ISOBoot {
case SyslinuxISOBoot:
options := &osbuild.ISOLinuxStageOptions{
Product: osbuild.ISOLinuxProduct{
Name: p.anacondaPipeline.product,
Expand All @@ -449,14 +450,13 @@ func (p *AnacondaInstallerISOTree) serialize() osbuild.Pipeline {

stage := osbuild.NewISOLinuxStage(options, p.anacondaPipeline.Name())
pipeline.AddStage(stage)
} else if p.ISOBoot == Grub2ISOBoot {
case Grub2ISOBoot:
var grub2config *osbuild.Grub2Config
if p.anacondaPipeline.InstallerCustomizations.DefaultMenu > 0 {
grub2config = &osbuild.Grub2Config{
Default: p.anacondaPipeline.InstallerCustomizations.DefaultMenu,
}
}

options := &osbuild.Grub2ISOLegacyStageOptions{
Product: osbuild.Product{
Name: p.anacondaPipeline.product,
Expand Down
5 changes: 3 additions & 2 deletions pkg/manifest/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func xorrisofsStageOptions(filename, isolabel string, isoboot ISOBootType) *osbu
ISOLevel: 3,
}

if isoboot == SyslinuxISOBoot {
switch isoboot {
case SyslinuxISOBoot:
// Syslinux BIOS ISO creation
options.Boot = &osbuild.XorrisofsBoot{
Image: "isolinux/isolinux.bin",
Catalog: "isolinux/boot.cat",
}
options.IsohybridMBR = "/usr/share/syslinux/isohdpfx.bin"
} else if isoboot == Grub2ISOBoot {
case Grub2ISOBoot:
// grub2 BIOS ISO creation
options.Boot = &osbuild.XorrisofsBoot{
Image: "images/eltorito.img",
Expand Down
5 changes: 3 additions & 2 deletions pkg/osbuild/curl_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func NewCurlPackageItem(pkg rpmmd.PackageSpec) (CurlSourceItem, error) {
}
item := new(CurlSourceOptions)
item.URL = pkg.RemoteLocation
if pkg.Secrets == "org.osbuild.rhsm" {
switch pkg.Secrets {
case "org.osbuild.rhsm":
item.Secrets = &URLSecrets{
Name: "org.osbuild.rhsm",
}
} else if pkg.Secrets == "org.osbuild.mtls" {
case "org.osbuild.mtls":
item.Secrets = &URLSecrets{
Name: "org.osbuild.mtls",
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/osbuild/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ func GenImagePrepareStages(pt *disk.PartitionTable, filename string, partTool Pa
},
)

if partTool == PTSfdisk {
switch partTool {
case PTSfdisk:
sfOptions := sfdiskStageOptions(pt)
sfdisk := NewSfdiskStage(sfOptions, loopback)
stages = append(stages, sfdisk)
} else if partTool == PTSgdisk {
case PTSgdisk:
sgOptions := sgdiskStageOptions(pt)
sgdisk := NewSgdiskStage(sgOptions, loopback)
stages = append(stages, sgdisk)
} else {
default:
panic("programming error: unknown PartTool: " + partTool)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/osbuild/librepo_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ func (source *LibrepoSource) AddPackage(pkg rpmmd.PackageSpec, repos []rpmmd.Rep
if mirror.Insecure && !pkg.IgnoreSSL {
return fmt.Errorf("inconsistent SSL configuration: package %v requires SSL but mirror %v is configured to ignore SSL", pkg.Name, mirror.URL)
}
if pkg.Secrets == "org.osbuild.rhsm" {
switch pkg.Secrets {
case "org.osbuild.rhsm":
mirror.Secrets = &URLSecrets{
Name: "org.osbuild.rhsm",
}
} else if pkg.Secrets == "org.osbuild.mtls" {
case "org.osbuild.mtls":
mirror.Secrets = &URLSecrets{
Name: "org.osbuild.mtls",
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/osbuild/mkfs_fat_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func isFATVolID(id string) bool {
// when generating the mkfs stage in mkfs_stage.go. This check removes all
// dashes to determine if the given id is a valid vfat volid.
volidre := regexp.MustCompile(fatVolIDRegex)
return volidre.MatchString(strings.Replace(id, "-", "", -1))
return volidre.MatchString(strings.ReplaceAll(id, "-", ""))
}
2 changes: 1 addition & 1 deletion pkg/osbuild/mkfs_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GenFsStages(pt *disk.PartitionTable, filename string) []*Stage {
stages = append(stages, NewMkfsXfsStage(options, stageDevices))
case "vfat":
options := &MkfsFATStageOptions{
VolID: strings.Replace(e.UUID, "-", "", -1),
VolID: strings.ReplaceAll(e.UUID, "-", ""),
Label: e.Label,
}
stages = append(stages, NewMkfsFATStage(options, stageDevices))
Expand Down
Loading
Loading