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

ValueNotUsedInspection #882

Closed
retailcoder opened this Issue Dec 21, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@retailcoder
Member

retailcoder commented Dec 21, 2015

Sometimes a variable is both assigned and referred to, but an inspection should be able to sort the references by line position and locate an identifier that's assigned a value that's reassigned before it's used - in other words a suspiciously redundant assignment involving a value that's never used.

That one is entering the realm of execution paths: it needs to account for conditionals and only flag consecutive assignments in the same execution path.

@Hosch250

This comment has been minimized.

Show comment
Hide comment
@Hosch250

Hosch250 Dec 24, 2015

Member

The good news here is this is actually quite easy.

  1. Get all the references for a declaration in a given project.
  2. Order by start line, then by start column: .OrderBy(o => o.Selection.StartLine).ThenBy(t => t.Selection.StartColumn).
  3. If two values in a row are assignments (there is a field in IdentifierReference for this), they are assignments before usage.

One thing to note, though, is this may have false positives in the event the value is used and assigned, such as could happen with the ++ operator that many languages have (not sure if VBA has this).

Member

Hosch250 commented Dec 24, 2015

The good news here is this is actually quite easy.

  1. Get all the references for a declaration in a given project.
  2. Order by start line, then by start column: .OrderBy(o => o.Selection.StartLine).ThenBy(t => t.Selection.StartColumn).
  3. If two values in a row are assignments (there is a field in IdentifierReference for this), they are assignments before usage.

One thing to note, though, is this may have false positives in the event the value is used and assigned, such as could happen with the ++ operator that many languages have (not sure if VBA has this).

@retailcoder

This comment has been minimized.

Show comment
Hide comment
@retailcoder

retailcoder Jan 18, 2016

Member

There's no ++ increment or -- decrement operator in VBA.

Member

retailcoder commented Jan 18, 2016

There's no ++ increment or -- decrement operator in VBA.

@Hosch250 Hosch250 added this to the Version 2.0 milestone Jan 18, 2016

@Hosch250 Hosch250 self-assigned this Jan 18, 2016

@Hosch250 Hosch250 modified the milestones: v2.1, Version 2.0 Jan 22, 2016

@Hosch250

This comment has been minimized.

Show comment
Hide comment
@Hosch250

Hosch250 Feb 6, 2016

Member

Update - this is going to require at least basic execution path evaluation. That is why it is delayed.

Member

Hosch250 commented Feb 6, 2016

Update - this is going to require at least basic execution path evaluation. That is why it is delayed.

@Hosch250

This comment has been minimized.

Show comment
Hide comment
@Hosch250

Hosch250 Oct 11, 2018

Member

Mostly done with #4422

Member

Hosch250 commented Oct 11, 2018

Mostly done with #4422

@Hosch250

This comment has been minimized.

Show comment
Hide comment
@Hosch250

Hosch250 Oct 19, 2018

Member

Closing this as possible further enhancements are not detailed in this ticket, and the main work is done. Other enhancements can be brought up after the feature has been in use.

Member

Hosch250 commented Oct 19, 2018

Closing this as possible further enhancements are not detailed in this ticket, and the main work is done. Other enhancements can be brought up after the feature has been in use.

@Hosch250 Hosch250 closed this Oct 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment