Apply De Morgan's law

This fixes a bunch of "QF1001: could apply De Morgan's law" warnings
from staticcheck linter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-03-27 14:13:40 -07:00
parent b1010808ed
commit 0dddc5e3c0
23 changed files with 41 additions and 41 deletions

View File

@ -164,7 +164,7 @@ func imageSearch(cmd *cobra.Command, args []string) error {
isJSON := report.IsJSON(searchOptions.Format)
for i, element := range searchReport {
d := strings.ReplaceAll(element.Description, "\n", " ")
if len(d) > 44 && !(searchOptions.NoTrunc || isJSON) {
if len(d) > 44 && (!searchOptions.NoTrunc && !isJSON) {
d = strings.TrimSpace(d[:44]) + "..."
}
searchReport[i].Description = d

View File

@ -195,7 +195,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
// Check if healthcheck is not nil and --no-healthcheck option is not set.
// If --no-healthcheck is set Test will be always set to `[NONE]`, so the
// inspect status should be set to nil.
if c.config.HealthCheckConfig != nil && !(len(c.config.HealthCheckConfig.Test) == 1 && c.config.HealthCheckConfig.Test[0] == "NONE") {
if c.config.HealthCheckConfig != nil && (len(c.config.HealthCheckConfig.Test) != 1 || c.config.HealthCheckConfig.Test[0] != "NONE") {
// This container has a healthcheck defined in it; we need to add its state
healthCheckState, err := c.readHealthCheckLog()
if err != nil {
@ -215,7 +215,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
data.NetworkSettings = networkConfig
// Ports in NetworkSettings includes exposed ports for network modes that are not host,
// and not container.
if !(c.config.NetNsCtr != "" || c.NetworkMode() == "host") {
if c.config.NetNsCtr == "" && c.NetworkMode() != "host" {
addInspectPortsExpose(c.config.ExposedPorts, data.NetworkSettings.Ports)
}

View File

@ -1333,7 +1333,7 @@ func (c *Container) start() error {
// Check if healthcheck is not nil and --no-healthcheck option is not set.
// If --no-healthcheck is set Test will be always set to `[NONE]` so no need
// to update status in such case.
if c.config.HealthCheckConfig != nil && !(len(c.config.HealthCheckConfig.Test) == 1 && c.config.HealthCheckConfig.Test[0] == "NONE") {
if c.config.HealthCheckConfig != nil && (len(c.config.HealthCheckConfig.Test) != 1 || c.config.HealthCheckConfig.Test[0] != "NONE") {
if err := c.updateHealthStatus(define.HealthCheckStarting); err != nil {
return fmt.Errorf("update healthcheck status: %w", err)
}
@ -1622,7 +1622,7 @@ func (c *Container) unpause() error {
isStartupHealthCheck := c.config.StartupHealthCheckConfig != nil && !c.state.StartupHCPassed
isHealthCheckEnabled := c.config.HealthCheckConfig != nil &&
!(len(c.config.HealthCheckConfig.Test) == 1 && c.config.HealthCheckConfig.Test[0] == "NONE")
(len(c.config.HealthCheckConfig.Test) != 1 || c.config.HealthCheckConfig.Test[0] != "NONE")
if isHealthCheckEnabled || isStartupHealthCheck {
timer := c.config.HealthCheckConfig.Interval.String()
if isStartupHealthCheck {

View File

@ -20,7 +20,7 @@ func (c *Container) validate() error {
rootfsSet := c.config.Rootfs != ""
// If one of RootfsImageIDor RootfsImageName are set, both must be set.
if (imageIDSet || imageNameSet) && !(imageIDSet && imageNameSet) {
if (imageIDSet || imageNameSet) && (!imageIDSet || !imageNameSet) {
return fmt.Errorf("both RootfsImageName and RootfsImageID must be set if either is set: %w", define.ErrInvalidArg)
}
@ -30,7 +30,7 @@ func (c *Container) validate() error {
}
// Must set at least one of RootfsImageID or Rootfs
if !(imageIDSet || rootfsSet) {
if !imageIDSet && !rootfsSet {
return fmt.Errorf("must set root filesystem source to either image or rootfs: %w", define.ErrInvalidArg)
}

View File

@ -121,7 +121,7 @@ func (p *Pod) getInfraContainer() (*Container, error) {
func GenerateForKubeDaemonSet(ctx context.Context, pod *YAMLPod, options entities.GenerateKubeOptions) (*YAMLDaemonSet, error) {
// Restart policy for DaemonSets can only be set to Always
if !(pod.Spec.RestartPolicy == "" || pod.Spec.RestartPolicy == v1.RestartPolicyAlways) {
if pod.Spec.RestartPolicy != "" && pod.Spec.RestartPolicy != v1.RestartPolicyAlways {
return nil, fmt.Errorf("k8s DaemonSets can only have restartPolicy set to Always")
}
@ -178,7 +178,7 @@ func GenerateForKubeDaemonSet(ctx context.Context, pod *YAMLPod, options entitie
// kind YAML.
func GenerateForKubeDeployment(ctx context.Context, pod *YAMLPod, options entities.GenerateKubeOptions) (*YAMLDeployment, error) {
// Restart policy for Deployments can only be set to Always
if options.Type == define.K8sKindDeployment && !(pod.Spec.RestartPolicy == "" || pod.Spec.RestartPolicy == v1.RestartPolicyAlways) {
if options.Type == define.K8sKindDeployment && (pod.Spec.RestartPolicy != "" && pod.Spec.RestartPolicy != v1.RestartPolicyAlways) {
return nil, fmt.Errorf("k8s Deployments can only have restartPolicy set to Always")
}
@ -815,7 +815,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic
if !ctr.HostNetwork() {
hostNetwork = false
}
if !(ctr.IDMappings().HostUIDMapping && ctr.IDMappings().HostGIDMapping) {
if !ctr.IDMappings().HostUIDMapping || !ctr.IDMappings().HostGIDMapping {
hostUsers = false
}
kubeCtr, kubeVols, ctrDNS, annotations, err := containerToV1Container(ctx, ctr, getService)

View File

@ -293,7 +293,7 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
// if not only the default network is connected we can return here
// otherwise we have to populate the InspectBasicNetworkConfig settings
_, isDefaultNet := networks[c.runtime.config.Network.DefaultNetwork]
if !(len(networks) == 1 && isDefaultNet) {
if len(networks) != 1 || !isDefaultNet {
return settings, nil
}
} else {

View File

@ -464,7 +464,7 @@ func (r *Runtime) removeVolume(ctx context.Context, v *Volume, force bool, timeo
} else if v.config.Driver == define.VolumeDriverImage {
if err := v.runtime.storageService.DeleteContainer(v.config.StorageID); err != nil {
// Storage container is already gone, no problem.
if !(errors.Is(err, storage.ErrNotAContainer) || errors.Is(err, storage.ErrContainerUnknown)) {
if !errors.Is(err, storage.ErrNotAContainer) && !errors.Is(err, storage.ErrContainerUnknown) {
return fmt.Errorf("removing volume %s storage: %w", v.Name(), err)
}
logrus.Infof("Storage for volume %s already removed", v.Name())

View File

@ -275,7 +275,7 @@ func (v *Volume) UsesVolumeDriver() bool {
}
return false
}
return !(v.config.Driver == define.VolumeDriverLocal || v.config.Driver == "")
return v.config.Driver != define.VolumeDriverLocal && v.config.Driver != ""
}
func (v *Volume) Mount() (string, error) {

View File

@ -40,7 +40,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
return
}
if !(query.Stdout || query.Stderr) {
if !query.Stdout && !query.Stderr {
msg := fmt.Sprintf("%s: you must choose at least one stream", http.StatusText(http.StatusBadRequest))
utils.Error(w, http.StatusBadRequest, fmt.Errorf("%s for %s", msg, r.URL.String()))
return

View File

@ -258,7 +258,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
for _, containerfile := range m {
// Add path to containerfile iff it is not URL
if !(strings.HasPrefix(containerfile, "http://") || strings.HasPrefix(containerfile, "https://")) {
if !strings.HasPrefix(containerfile, "http://") && !strings.HasPrefix(containerfile, "https://") {
containerfile = filepath.Join(contextDirectory,
filepath.Clean(filepath.FromSlash(containerfile)))
}

View File

@ -37,7 +37,7 @@ func NewCompatAPIDecoder() *schema.Decoder {
// mimic behaviour of github.com/docker/docker/api/server/httputils.BoolValue()
dec.RegisterConverter(true, func(s string) reflect.Value {
s = strings.ToLower(strings.TrimSpace(s))
return reflect.ValueOf(!(s == "" || s == "0" || s == "no" || s == "false" || s == "none"))
return reflect.ValueOf(s != "" && s != "0" && s != "no" && s != "false" && s != "none")
})
return dec

View File

@ -45,9 +45,9 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
stdout bool
stderr bool
}{
stdin: !(stdin == nil || reflect.ValueOf(stdin).IsNil()),
stdout: !(stdout == nil || reflect.ValueOf(stdout).IsNil()),
stderr: !(stderr == nil || reflect.ValueOf(stderr).IsNil()),
stdin: stdin != nil && !reflect.ValueOf(stdin).IsNil(),
stdout: stdout != nil && !reflect.ValueOf(stdout).IsNil(),
stderr: stderr != nil && !reflect.ValueOf(stderr).IsNil(),
}
// Ensure golang can determine that interfaces are "really" nil
if !isSet.stdin {
@ -138,7 +138,7 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
return err
}
if !(response.IsSuccess() || response.IsInformational()) {
if !response.IsSuccess() && !response.IsInformational() {
defer response.Body.Close()
return response.Process(nil)
}
@ -496,7 +496,7 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
}
defer response.Body.Close()
if !(response.IsSuccess() || response.IsInformational()) {
if !response.IsSuccess() && !response.IsInformational() {
return response.Process(nil)
}

View File

@ -36,7 +36,7 @@ func Logs(ctx context.Context, nameOrID string, options *LogOptions, stdoutChan,
defer response.Body.Close()
// if not success handle and return possible error message
if !(response.IsSuccess() || response.IsInformational()) {
if !response.IsSuccess() && !response.IsInformational() {
return response.Process(nil)
}

View File

@ -300,7 +300,7 @@ func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []strin
// Issue #7384 and #11384: If the container is configured for
// auto-removal, it might already have been removed at this point.
// We still need to clean up since we do not know if the other cleanup process is successful
if !(errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved)) {
if !errors.Is(err, define.ErrNoSuchCtr) && !errors.Is(err, define.ErrCtrRemoved) {
return err
}
}
@ -498,7 +498,7 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
for ctr, err := range ctrsMap {
report := new(reports.RmReport)
report.Id = ctr
if !(errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved)) {
if !errors.Is(err, define.ErrNoSuchCtr) && !errors.Is(err, define.ErrCtrRemoved) {
report.Err = err
}
report.RawInput = idToRawInput[ctr]

View File

@ -157,7 +157,7 @@ func (ic *ContainerEngine) GenerateKube(ctx context.Context, nameOrIDs []string,
if err != nil {
return nil, err
}
if !(podConfig.UsePodIPC && podConfig.UsePodNet && podConfig.UsePodUTS) {
if !podConfig.UsePodIPC || !podConfig.UsePodNet || !podConfig.UsePodUTS {
defaultKubeNS = false
}

View File

@ -639,7 +639,7 @@ func removeErrorsToExitCode(rmErrors []error) int {
// One of the specified images has child images or is
// being used by a container.
return 2
case noSuchImageErrors && !(otherErrors || inUseErrors):
case noSuchImageErrors && (!otherErrors && !inUseErrors):
// One of the specified images did not exist, and no other
// failures.
return 1

View File

@ -192,7 +192,7 @@ func (ic *ContainerEngine) PodUnpause(ctx context.Context, namesOrIds []string,
func (ic *ContainerEngine) PodStop(ctx context.Context, namesOrIds []string, options entities.PodStopOptions) ([]*entities.PodStopReport, error) {
reports := []*entities.PodStopReport{}
pods, err := getPodsByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
if err != nil && !(options.Ignore && errors.Is(err, define.ErrNoSuchPod)) {
if err != nil && (!options.Ignore || !errors.Is(err, define.ErrNoSuchPod)) {
return nil, err
}
for _, p := range pods {
@ -276,7 +276,7 @@ func (ic *ContainerEngine) PodStart(ctx context.Context, namesOrIds []string, op
func (ic *ContainerEngine) PodRm(ctx context.Context, namesOrIds []string, options entities.PodRmOptions) ([]*entities.PodRmReport, error) {
pods, err := getPodsByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
if err != nil && !(options.Ignore && errors.Is(err, define.ErrNoSuchPod)) {
if err != nil && (!options.Ignore || !errors.Is(err, define.ErrNoSuchPod)) {
return nil, err
}
reports := make([]*entities.PodRmReport, 0, len(pods))

View File

@ -166,7 +166,7 @@ func (n UsernsMode) GetKeepIDOptions() (*KeepIDUserNsOptions, error) {
// IsPrivate indicates whether the container uses the a private userns.
func (n UsernsMode) IsPrivate() bool {
return !(n.IsHost() || n.IsContainer())
return !n.IsHost() && !n.IsContainer()
}
// Valid indicates whether the userns is valid.
@ -306,7 +306,7 @@ type PidMode string
// IsPrivate indicates whether the container uses its own new pid namespace.
func (n PidMode) IsPrivate() bool {
return !(n.IsHost() || n.IsContainer())
return !n.IsHost() && !n.IsContainer()
}
// IsHost indicates whether the container uses the host's pid namespace.
@ -364,7 +364,7 @@ func (n NetworkMode) IsDefault() bool {
// IsPrivate indicates whether container uses its private network stack.
func (n NetworkMode) IsPrivate() bool {
return !(n.IsHost() || n.IsContainer())
return !n.IsHost() && !n.IsContainer()
}
// IsContainer indicates whether container uses a container network stack.

View File

@ -160,7 +160,7 @@ func GenVolumeMounts(volumeFlag []string) (map[string]spec.Mount, map[string]*Na
if (workDirFlag && !upperDirFlag) || (!workDirFlag && upperDirFlag) {
return nil, nil, nil, errors.New("must set both `upperdir` and `workdir`")
}
if len(options) > 2 && !(len(options) == 3 && upperDirFlag && workDirFlag) || (len(options) == 2 && !chownFlag) {
if len(options) > 2 && (len(options) != 3 || !upperDirFlag || !workDirFlag) || (len(options) == 2 && !chownFlag) {
return nil, nil, nil, errors.New("can't use 'O' with other options")
}
}

View File

@ -26,7 +26,7 @@ func FindMountType(input string) (mountType string, tokens []string, err error)
}
for _, s := range records[0] {
kv := strings.Split(s, "=")
if found || !(len(kv) == 2 && kv[0] == "type") {
if found || (len(kv) != 2 || kv[0] != "type") {
tokens = append(tokens, s)
continue
}

View File

@ -255,7 +255,7 @@ loop1:
goto finishForceTerminate
case strings.ContainsRune(separators, rune(c)):
if flags&SplitDontCoalesceSeparators != 0 {
if !(flags&SplitRetainSeparators != 0) {
if flags&SplitRetainSeparators == 0 {
p++
}
goto finishForceNext
@ -332,7 +332,7 @@ loop1:
if flags&SplitUnquote != 0 {
break quoteloop
}
case c == '\\' && !(flags&SplitRetainEscape != 0):
case c == '\\' && (flags&SplitRetainEscape == 0):
backslash = true
break quoteloop
}
@ -354,18 +354,18 @@ loop1:
if flags&SplitUnquote != 0 {
break nonquoteloop
}
case c == '\\' && !(flags&SplitRetainEscape != 0):
case c == '\\' && (flags&SplitRetainEscape == 0):
backslash = true
break nonquoteloop
case strings.ContainsRune(separators, rune(c)):
if flags&SplitDontCoalesceSeparators != 0 {
if !(flags&SplitRetainSeparators != 0) {
if flags&SplitRetainSeparators == 0 {
p++
}
goto finishForceNext
}
if !(flags&SplitRetainSeparators != 0) {
if flags&SplitRetainSeparators == 0 {
/* Skip additional coalesced separators. */
for ; ; c = nextChar() {
if c == 0 {

View File

@ -579,7 +579,7 @@ func ConvertContainer(container *parser.UnitFile, isUser bool, unitsInfoMap map[
// Only allow mixed or control-group, as nothing else works well
killMode, ok := service.Lookup(ServiceGroup, "KillMode")
if !ok || !(killMode == "mixed" || killMode == "control-group") {
if !ok || (killMode != "mixed" && killMode != "control-group") {
if ok {
return nil, warnings, fmt.Errorf("invalid KillMode '%s'", killMode)
}
@ -1222,7 +1222,7 @@ func ConvertKube(kube *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isUse
// Only allow mixed or control-group, as nothing else works well
killMode, ok := service.Lookup(ServiceGroup, "KillMode")
if !ok || !(killMode == "mixed" || killMode == "control-group") {
if !ok || (killMode != "mixed" && killMode != "control-group") {
if ok {
return nil, fmt.Errorf("invalid KillMode '%s'", killMode)
}

View File

@ -32,7 +32,7 @@ func GetTimestamp(value string, reference time.Time) (string, error) {
var format string
// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation
parseInLocation := !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)
parseInLocation := !strings.ContainsAny(value, "zZ+") && strings.Count(value, "-") != 3
switch {
case strings.Contains(value, "."):