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

Add new static analyzer: ineffassign #7413

Merged
merged 14 commits into from
Oct 2, 2020
Merged

Add new static analyzer: ineffassign #7413

merged 14 commits into from
Oct 2, 2020

Conversation

farazdagi
Copy link
Contributor

@farazdagi farazdagi commented Oct 2, 2020

What type of PR is this?

Other / QA Toolset

What does this PR do? Why is it needed?

Which issues(s) does this PR fix?

N/A

Other notes for review

func (ds *Service) detectIncomingAttestations(ctx context.Context, ch chan *ethpb.IndexedAttestation) {
  ctx, span := trace.StartSpan(ctx, "detection.detectIncomingAttestations")
  defer span.End()
  // ctx is not used at all in this func

Although ctx after re-assigning from trace.StartSpan is not used in a func (making in ineffectual assignment), we seem to be ok with ctx argument not used within funcs (we have many places where ctx argument is defined but not used). Normally, non-used arguments are immediately removed, but with ctx we are lenient in our current code.

As such, replacing ctx, span := trace.StartSpan(ctx, "detection.detectIncomingAttestations") with _, span := trace.StartSpan(ctx, "detection.detectIncomingAttestations") will require next developer to be careful enough, to make sure ctx is overwritten again.

NB: Overall, I think even ctx variable shouldn't be used as placeholder, and if func doesn't rely on it, that argument should be removed and only reintroduced when necessary. If we decide to proceed with that, updating this analyzer will be trivial (just delete two lines of code), moreover, after the deletion this analyzer will help detect cases which need to be updated.

@farazdagi farazdagi requested a review from a team as a code owner October 2, 2020 10:16
@farazdagi farazdagi requested review from 0xKiwi, rkapka and nisdas October 2, 2020 10:16
@farazdagi farazdagi self-assigned this Oct 2, 2020
@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #7413 into master will decrease coverage by 0.00%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #7413      +/-   ##
==========================================
- Coverage   60.48%   60.47%   -0.01%     
==========================================
  Files         419      419              
  Lines       30618    30618              
==========================================
- Hits        18519    18516       -3     
- Misses       9070     9072       +2     
- Partials     3029     3030       +1     

@farazdagi farazdagi merged commit ecfdb35 into master Oct 2, 2020
@delete-merged-branch delete-merged-branch bot deleted the ineffassign-checker branch October 2, 2020 20:56
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