-
Notifications
You must be signed in to change notification settings - Fork 61
chore: enable and fixes rules from gocritic #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mmorel-35
wants to merge
9
commits into
moby:main
Choose a base branch
from
mmorel-35:gocritic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−29
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3855bd4
chore: enable gocritic but disable non compliant rules
mmorel-35 5541944
fix: emptyStringTest issues from gocritic
mmorel-35 1173744
fix: unnecessaryDefer issues from gocritic
mmorel-35 1e117e8
fix: ifElseChain issues from gocritic
mmorel-35 a2e681e
fix: assignOp issues from gocritic
mmorel-35 88f818b
fix: whyNoLint from gocritic
mmorel-35 f2ec85e
fix: builtinShadow from gocritic
mmorel-35 cb97502
fix: paramTypeCombine from gocritic
mmorel-35 eee6839
fix: deferInLoop from gocritic
mmorel-35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,15 +201,7 @@ func TestRecursiveUnmountTooGreedy(t *testing.T) { | |
| // a mount point, or we'll hit the fast path in RecursiveUnmount. | ||
| dirs := []string{"dir-other", "dir/subdir1", "dir/subdir1/subsub", "dir/subdir2/subsub"} | ||
| for _, d := range dirs { | ||
| dir := path.Join(tmp, d) | ||
| if err := os.MkdirAll(dir, 0o700); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := Mount("tmpfs", dir, "tmpfs", ""); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| //nolint:errcheck | ||
| defer Unmount(dir) | ||
| createAndMountTmpfs(t, tmp, d) | ||
| } | ||
| // sanity check | ||
| mounted, err := mountinfo.Mounted(path.Join(tmp, "dir-other")) | ||
|
|
@@ -232,6 +224,18 @@ func TestRecursiveUnmountTooGreedy(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func createAndMountTmpfs(t *testing.T, tmp, d string) { | ||
| dir := path.Join(tmp, d) | ||
| if err := os.MkdirAll(dir, 0o700); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := Mount("tmpfs", dir, "tmpfs", ""); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| //nolint:errcheck // Ignore error in tests | ||
| Unmount(dir) | ||
| } | ||
|
|
||
| func TestRecursiveUnmount_SubMountFailsToUnmount(t *testing.T) { | ||
| if os.Getuid() != 0 { | ||
| t.Skip("root required") | ||
|
|
@@ -255,11 +259,7 @@ func TestRecursiveUnmount_SubMountFailsToUnmount(t *testing.T) { | |
| // are listed in mountinfo, but since they are unreachable, unmount will fail. | ||
| toMount := []string{grandChild, child, parent} | ||
| for _, dir := range toMount { | ||
| dir := dir | ||
| if err := Mount("tmpfs", dir, "tmpfs", ""); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer Unmount(dir) //nolint:errcheck | ||
| mountTemporaryDirectory(t, dir) | ||
| } | ||
|
|
||
| // unmount shadowed mounts | ||
|
|
@@ -273,3 +273,10 @@ func TestRecursiveUnmount_SubMountFailsToUnmount(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func mountTemporaryDirectory(t *testing.T, dir string) { | ||
| if err := Mount("tmpfs", dir, "tmpfs", ""); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| Unmount(dir) //nolint:errcheck // Ignore error in tests | ||
| } | ||
|
Comment on lines
+276
to
+282
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here; we can also defer the unmount explicitly ignore errors here as well; _ = Unmount(dir) //nolint:errcheck // Ignore error in testsIf the |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just explicitly ignore the error, then we don't need a nolint comment;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't think moving this to a utility is correct; it changes semantics because it now unmounts immediately? If we want to keep that behavior, then we could do something like;
(either
t.Cleanupordefer, depending on go version supported, but I'd be fine bumping to a slightly newer version if needed)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly the utility of #253 could be used if it's modified to take a variadic strings.