microcks / microcks/microcks-cli
refactor: remove redundant `strings.HasPrefix` check before `strings.TrimPrefix`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 52
- Forks
- 68
- Avg merge
- 6h 54m
- Merged PRs (30d)
- 10
Description
### Describe the bug
In `cmd/import.go`, there is an `if strings.HasPrefix(...) { ... = strings.TrimPrefix(...) }` check. This is redundant boilerplate. `strings.TrimPrefix` is safe to call unconditionally because it simply returns the original string if the prefix isn't found.
### Expected behavior
The `strings.TrimPrefix` function should be called without the surrounding `if` statement to reduce cyclomatic complexity.
### Actual behavior
The codebase contains a redundant `if` statement that adds unnecessary lines of code.
### How to Reproduce?
Reproducer:
1. Look at `cmd/import.go`, specifically where path prefixes are trimmed.
2. Observe the `if strings.HasPrefix(...)` check guarding the `strings.TrimPrefix` call.
### Microcks version or git rev
`main` (Latest)
### Install method (`docker-compose`, `helm chart`, `operator`, `docker-desktop extension`,...)
CLI
### Additional information
This is a simple `good first issue` to clean up some Go syntax. Removing the `if` block and unconditionally calling `strings.TrimPrefix` fulfills the same logic cleanly and passes static checkers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open cmd/import.go and locate the path-prefix handling described in the issue. Replace the guarded strings.TrimPrefix call with an unconditional call, then verify that the static checkers pass and that the surrounding import behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Refactor
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100