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

ValueNotUsedInspection #882

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

ValueNotUsedInspection #882

retailcoder opened this issue Dec 21, 2015 · 5 comments
Assignees
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Milestone

Comments

@retailcoder
Copy link
Member

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
Copy link
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).

@retailcoder
Copy link
Member Author

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
Copy link
Member

Hosch250 commented Feb 6, 2016

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

@MDoerner MDoerner added the code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. label Mar 14, 2017
@Vogel612 Vogel612 added the enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. label Dec 7, 2017
@Hosch250
Copy link
Member

Mostly done with #4422

@Hosch250
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Projects
None yet
Development

No branches or pull requests

4 participants