pkg/buildah/native_linux.go

Summary

Maintainability
F
6 days
Test Coverage
F
0%

File native_linux.go has 1006 lines of code (exceeds 500 allowed). Consider refactoring.
Open

//go:build linux
// +build linux

package buildah

Severity: Major
Found in pkg/buildah/native_linux.go - About 1 day to fix

    Function generateRunMounts has a Cognitive Complexity of 74 (exceeds 20 allowed). Consider refactoring.
    Open

    func generateRunMounts(mounts []*instructions.Mount) []string {
        var runMounts []string
    
        for _, mount := range mounts {
            var options []string
    Severity: Minor
    Found in pkg/buildah/native_linux.go - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function generateRunMounts has 111 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func generateRunMounts(mounts []*instructions.Mount) []string {
        var runMounts []string
    
        for _, mount := range mounts {
            var options []string
    Severity: Major
    Found in pkg/buildah/native_linux.go - About 3 hrs to fix

      NativeBuildah has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type NativeBuildah struct {
          Isolation               thirdparty.Isolation
          TmpDir                  string
          InstanceTmpDir          string
          ConfigTmpDir            string
      Severity: Minor
      Found in pkg/buildah/native_linux.go - About 3 hrs to fix

        Function NewNativeBuildah has 84 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func NewNativeBuildah(commonOpts CommonBuildahOpts, opts NativeModeOpts) (*NativeBuildah, error) {
            b := &NativeBuildah{
                Isolation: *commonOpts.Isolation,
                TmpDir:    commonOpts.TmpDir,
                Insecure:  commonOpts.Insecure,
        Severity: Major
        Found in pkg/buildah/native_linux.go - About 2 hrs to fix

          Method NativeBuildah.Config has 76 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (b *NativeBuildah) Config(ctx context.Context, container string, opts ConfigOpts) error {
              builder, err := b.getBuilderFromContainer(ctx, container)
              if err != nil {
                  return fmt.Errorf("error getting builder: %w", err)
              }
          Severity: Major
          Found in pkg/buildah/native_linux.go - About 2 hrs to fix

            Method NativeBuildah.Config has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
            Open

            func (b *NativeBuildah) Config(ctx context.Context, container string, opts ConfigOpts) error {
                builder, err := b.getBuilderFromContainer(ctx, container)
                if err != nil {
                    return fmt.Errorf("error getting builder: %w", err)
                }
            Severity: Minor
            Found in pkg/buildah/native_linux.go - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method NativeBuildah.Containers has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
            Open

            func (b *NativeBuildah) Containers(ctx context.Context, opts ContainersOptions) (image.ContainerList, error) {
                builders, err := buildah.OpenAllBuilders(b.Store)
                if err != nil {
                    return nil, err
                }
            Severity: Minor
            Found in pkg/buildah/native_linux.go - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function NewNativeBuildah has 13 return statements (exceeds 4 allowed).
            Open

            func NewNativeBuildah(commonOpts CommonBuildahOpts, opts NativeModeOpts) (*NativeBuildah, error) {
                b := &NativeBuildah{
                    Isolation: *commonOpts.Isolation,
                    TmpDir:    commonOpts.TmpDir,
                    Insecure:  commonOpts.Insecure,
            Severity: Major
            Found in pkg/buildah/native_linux.go - About 1 hr to fix

              Method NativeBuildah.BuildFromDockerfile has 54 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (b *NativeBuildah) BuildFromDockerfile(ctx context.Context, dockerfile string, opts BuildFromDockerfileOpts) (string, error) {
                  var targetPlatform string
                  var targetPlatforms []struct{ OS, Arch, Variant string }
                  if opts.TargetPlatform != "" {
                      os, arch, variant, err := parse.Platform(opts.TargetPlatform)
              Severity: Minor
              Found in pkg/buildah/native_linux.go - About 1 hr to fix

                Method NativeBuildah.Commit has 6 return statements (exceeds 4 allowed).
                Open

                func (b *NativeBuildah) Commit(ctx context.Context, container string, opts CommitOpts) (string, error) {
                    builder, err := b.getBuilderFromContainer(ctx, container)
                    if err != nil {
                        return "", fmt.Errorf("error getting builder: %w", err)
                    }
                Severity: Major
                Found in pkg/buildah/native_linux.go - About 40 mins to fix

                  Method NativeBuildah.Images has 6 return statements (exceeds 4 allowed).
                  Open

                  func (b *NativeBuildah) Images(ctx context.Context, opts ImagesOptions) (image.ImagesList, error) {
                      sysCtx, err := b.getSystemContext(opts.TargetPlatform)
                      if err != nil {
                          return nil, err
                      }
                  Severity: Major
                  Found in pkg/buildah/native_linux.go - About 40 mins to fix

                    Method NativeBuildah.Add has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    func (b *NativeBuildah) Add(ctx context.Context, container string, src []string, dst string, opts AddOpts) error {
                    Severity: Minor
                    Found in pkg/buildah/native_linux.go - About 35 mins to fix

                      Method NativeBuildah.Copy has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      func (b *NativeBuildah) Copy(ctx context.Context, container, contextDir string, src []string, dst string, opts CopyOpts) error {
                      Severity: Minor
                      Found in pkg/buildah/native_linux.go - About 35 mins to fix

                        Method NativeBuildah.Pull has 5 return statements (exceeds 4 allowed).
                        Open

                        func (b *NativeBuildah) Pull(ctx context.Context, ref string, opts PullOpts) error {
                            sysCtx, err := b.getSystemContext(opts.TargetPlatform)
                            if err != nil {
                                return err
                            }
                        Severity: Major
                        Found in pkg/buildah/native_linux.go - About 35 mins to fix

                          Function NewNativeStoreOptions has 5 return statements (exceeds 4 allowed).
                          Open

                          func NewNativeStoreOptions(rootlessUID int, driver StorageDriver) (*thirdparty.StoreOptions, error) {
                              var (
                                  runRoot string
                                  err     error
                              )
                          Severity: Major
                          Found in pkg/buildah/native_linux.go - About 35 mins to fix

                            Method NativeBuildah.Containers has 5 return statements (exceeds 4 allowed).
                            Open

                            func (b *NativeBuildah) Containers(ctx context.Context, opts ContainersOptions) (image.ContainerList, error) {
                                builders, err := buildah.OpenAllBuilders(b.Store)
                                if err != nil {
                                    return nil, err
                                }
                            Severity: Major
                            Found in pkg/buildah/native_linux.go - About 35 mins to fix

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      case instructions.MountTypeSecret:
                                          options = append(
                                              options,
                                              fmt.Sprintf("type=%s", mount.Type),
                                          )
                              Severity: Major
                              Found in pkg/buildah/native_linux.go and 1 other location - About 2 hrs to fix
                              pkg/buildah/native_linux.go on lines 1111..1133

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 242.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      case instructions.MountTypeSSH:
                                          options = append(
                                              options,
                                              fmt.Sprintf("type=%s", mount.Type),
                                          )
                              Severity: Major
                              Found in pkg/buildah/native_linux.go and 1 other location - About 2 hrs to fix
                              pkg/buildah/native_linux.go on lines 1088..1110

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 242.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if len(opts.Cmd) > 0 {
                                      var cmd []string
                                      if opts.CmdPrependShell {
                                          if builder.Shell() != nil {
                                              cmd = builder.Shell()
                              Severity: Minor
                              Found in pkg/buildah/native_linux.go and 1 other location - About 40 mins to fix
                              pkg/buildah/native_linux.go on lines 623..638

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 111.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  if len(opts.Entrypoint) > 0 {
                                      var entrypoint []string
                                      if opts.EntrypointPrependShell {
                                          if builder.Shell() != nil {
                                              entrypoint = builder.Shell()
                              Severity: Minor
                              Found in pkg/buildah/native_linux.go and 1 other location - About 40 mins to fix
                              pkg/buildah/native_linux.go on lines 606..621

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 111.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              There are no issues that match your filters.

                              Category
                              Status