Skip to content
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

fix staticcheck errors and run gofmt #69

Merged
merged 4 commits into from
Jan 6, 2023
Merged

fix staticcheck errors and run gofmt #69

merged 4 commits into from
Jan 6, 2023

Conversation

llimllib
Copy link
Contributor

@llimllib llimllib commented Jan 5, 2023

  • Fix shadowed variables reported by staticcheck
  • Use os.MkTempDirs instead of the deprecated ioutil.TempDir
  • Un-name some unused variables
  • 301 -> http.StatusMovedPermanently
  • remove unreachable code
  • simplify some boolean returns
  • change some switches to switch on the character when possible
    • If you want me to remove these switch changes for stylistic reasons, I'm totally open to that. I think they read better this way, but they don't exactly rhyme now, and future changes might require undoing switching on the character
  • gofmt

Before:

$ staticcheck . ./_runtime
_runtime/pushup_support.go:87:5: error var NotFound should have name of the form ErrFoo (ST1012)
_runtime/pushup_support.go:97:46: should use constant http.StatusMovedPermanently instead of numeric literal 301 (ST1013)
_runtime/pushup_support.go:180:6: func getParam is unused (U1000)
_runtime/pushup_support.go:189:5: var layouts is unused (U1000)
_runtime/pushup_support.go:191:6: func getLayout is unused (U1000)
_runtime/pushup_support.go:202:6: type nilLayout is unused (U1000)
_runtime/pushup_support.go:204:21: func (*nilLayout).Respond is unused (U1000)
_runtime/pushup_support.go:230:6: func printEscaped is unused (U1000)
_runtime/pushup_support.go:296:3: should use 'return route.path != mainRoute' instead of 'if route.path == mainRoute { return false }; return true' (S1008)
_runtime/pushup_support.go:314:3: should use 'return matchURLPathSegmentPrefix(match.route.regex, requestPath)' instead of 'if matchURLPathSegmentPrefix(match.route.regex, requestPath) { return true }; return false' (S1008)
_runtime/pushup_support.go:386:2: should use 'return len(segments) <= len(reSegments)' instead of 'if len(segments) > len(reSegments) { return false }; return true' (S1008)
main.go:17:2: \"io/ioutil\" has been deprecated since Go 1.16: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
main.go:566:24: func (*projectFiles).debug is unused (U1000)
main.go:843:3: this value of err is never used (SA4006)
main.go:850:3: this value of err is never used (SA4006)
main.go:871:2: should merge variable declaration with assignment on next line (S1021)
main.go:3683:22: func (*codeParser).offset is unused (U1000)
$ go vet . ./_runtime
# github.com/adhocteam/pushup/_runtime
_runtime/pushup_support.go:117:2: unreachable code

After:

$ staticcheck . ./_runtime
_runtime/pushup_support.go:179:6: func getParam is unused (U1000)
_runtime/pushup_support.go:188:5: var layouts is unused (U1000)
_runtime/pushup_support.go:190:6: func getLayout is unused (U1000)
_runtime/pushup_support.go:201:6: type nilLayout is unused (U1000)
_runtime/pushup_support.go:203:21: func (*nilLayout).Respond is unused (U1000)
_runtime/pushup_support.go:229:6: func printEscaped is unused (U1000)
main.go:565:24: func (*projectFiles).debug is unused (U1000)
main.go:3675:22: func (*codeParser).offset is unused (U1000)
$ go vet . ./_runtime
  • obviously runtime functions being unused is not an issue
  • I didn't want to rename NotFound without putting it in front of you first
  • I thought maybe you wanted to keep the unused functions in main.go around for future use
  • In the future, we may want to add checks like these to CI

Copy link
Contributor

@paulsmith paulsmith left a comment

Choose a reason for hiding this comment

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

Mostly fine with these changes, thanks, just a couple small things, mostly deleting commented-out debugging.

_runtime/pushup_support.go Outdated Show resolved Hide resolved
_runtime/pushup_support.go Outdated Show resolved Hide resolved
_runtime/pushup_support.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@@ -94,7 +94,7 @@ func Respond(w http.ResponseWriter, r *http.Request) error {
case routeNotFound:
return NotFound
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm OK with renaming this ErrNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm almost certain that build.NotFound referred to this variable, but I wanted to make sure that I was correct that this usage:

_runtime/cmd/main.go
114:		if errors.Is(err, build.ErrNotFound) {

was in fact correct to change

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is correct.

@paulsmith
Copy link
Contributor

Running staticcheck on _runtime is a bit weird because it's sort of an incomplete templatized package. We should do it, and try to address issues that are not related to integrating it with generated Pushup code, but not block CI on it.

Copy link
Contributor

@paulsmith paulsmith left a comment

Choose a reason for hiding this comment

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

LGTM! :shipit:

@@ -94,7 +94,7 @@ func Respond(w http.ResponseWriter, r *http.Request) error {
case routeNotFound:
return NotFound
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is correct.

@paulsmith paulsmith merged commit e6a0242 into main Jan 6, 2023
@paulsmith paulsmith deleted the fix-nits branch January 6, 2023 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants