1
CodeIt.Right Project Statistics And Violation Detections
Question asked by Steve Marshall - 2/15/2020 at 10:31 AM
Answered
Hi all,

Just a quick question - I may be missing something because I am fogged up with a head cold, but CodeIt.Right Analysis seems to have started going wrong on me recently in that the Statistics seem to have gone way off beam, and it is persistently detecting two violations that are clearly incorrect.

I have a large project that before I started working on it was 20,000+ lines of code. Admittedly I have been refactoring and down-sizing the code, but not down to 2,011 lines of code that the Solution Summary is now reporting. I have removed some dead wood, but have added significant functionality too, so the stats just do not add up. Is there something that needs resetting? Is there something that has somehow got out of whack and needs a poke? Just FYI, I always run an analysis against the full Solution, so I am not just running against a selection of files (like open or checked out) which was my first thought.

Also, I have two persistent incorrect detections of "Remove Unused Locals". In both cases the "accused" variables are declared and used in two places - first in an interpolated string to display a message to a log file, and secondly as a parameter to a DataAdapter to write a record to a database logging table. The variables are clearly used, but CodeIt.Right is determined to hassle me continuously about them. Code clips of one such case are below - maybe there is some reason that someone else can spot:

Declaration
Dim machineOffAt As DateTime = DateTime.Now()

Use In Interpolated String
Dim logMessage As String = $"Machine Switched Off: {machineOffAt:dd/MM/yyyy HH:mm:ss}"

Use As Parameter To DataAdapter
dtoAdapter.WriteMachineSwitchedOffLog(machineOffAt, machineCode)

The declaration and two uses are within a few lines of each other, in the same function. How they are seen as unused locals is beyond me.

Any help appreciated. These are more petty annoyances than issues.

Steve

11 Replies

Reply to Thread
0
Steve Marshall Replied
Okay, I have worked round this. Although the original declaration, initialisation, and usage of the variable were all within the same block (inside a Using block), CodeIt.Right was incorrectly reporting an unused local for some reason.

If I move the declaration and initialisation outside of the Using block but leave the usage inside the block, all is well and CodeIt.Right is happy.

At least I am not being nagged for something I did not do now!!

Still have the Solution Statistics way out though …

Steve
0
Misha Zhutov Replied
Employee Post
Hi Steve, 

CodeIt.Right displays statistics for only parsed project/files. It supports only C#/VB.NET projects. 
Also, please check the ignore list (Options->Solution Ignore List) which excludes files from parsing.

We can help you if you send us to support@submain.com the log file from c:\Users\\Documents\SubMain\CodeIt.Right  for VS20XX\CodeIt.Right.log 

Also, please provide us with a code snippet that reproduces the issue with "Remove Unused Locals".

0
Steve Marshall Replied
Hi Misha,

As I said in my OP, I always do a full solution scan - so I would have thought that it would be scanning/parsing all files. My project is all VB.Net and always has been - that has not changed. There is definitely something suspicious as the stats are now reporting 1,329 lines of code, and I have added two new modules which on their own hold close to 120 lines, but the total has gone down by 682 lines!!. 

I will code up a new routine that exhibits the problem and post the code here, and I will send in the log file when back at my desk.

Steve
0
Steve Marshall Replied
Hi Misha,

I have just "edited" one of the routines back to how it was and the issue does not report. Typical. It has been parsed a few times now without the issue, so maybe something has been cleared away. Other than moving the declaration/initialisation outside of the Using block (and now back) the module has been untouched.

If I get the issue back I will come back on this - but otherwise as I cannot reproduce the issue, it has gone away.

As for the stats. Moving the declaration back inside the Using block (Note: this is the ONLY change made in the entire project), the code lines has increased from 1,329 to 2,690 - over double. If I move the declaration outside the block again, the code lines drop back to 1,329.

I think I am just going to ignore the stats for now. I have no clue what is going on with them!!

Steve

0
Misha Zhutov Replied
Employee Post
Thank you for the update. If the statistics changes after you change code it means that there is a parsing error that prevents CodeIt.Right to calculate it correctly. Please email us the log file from c:\Users\\Documents\SubMain\CodeIt.Right  for VS20XX\CodeIt.Right.log to support@submain.com for troubleshooting.
0
Steve Marshall Replied
Hi Misha,

I have emailed in the log file as requested. Note it only shows lines starting yesterday as I tried a re-install to see if that would solve the problem (before your replies). I did have a quick look and as you say there are plenty of parse errors reported.

Thanks,
Steve

0
Steve Marshall Replied
Misha,

I have has a reply back from the support desk saying that my log file has allowed a parsing issue with interpolated strings in VB.Net to be corrected and that the fix will be available "in the next release".

Is there any guidance on when this next release will be available as I am required to post the project static analysis and code statistics as part of the project completion documentation.

Many thanks,
Steve

0
Steve Marshall Replied
Misha,

Just to let you know that I have had another occurrence of an incorrect "unused local message". An example of a piece of code that shows it is below:

Public Sub TestUnusedLocal()

  Using dtoTable As New CrewDataSet.CrewLogDataTable
    Using dtoAdapter As New CrewDataSetTableAdapters.CrewLogAdapter
      Dim logWrittenBefore As DateTime = DateTime.Now

      Dim messageOnFail As String = $"Test for unused Local: {logWrittenBefore:dd/MM/yyyy HH:mm:ss}."
    End Using
  End Using

End Sub
This reports an unused local variable "logWrittenBefore". However, as I have found before, the following code does not report the same:

Public Sub TestUnusedLocal2()
  Dim logWrittenBefore As DateTime = DateTime.Now

  Using dtoTable As New CrewDataSet.CrewLogDataTable
    Using dtoAdapter As New CrewDataSetTableAdapters.CrewLogAdapter
      Dim messageOnFail As String = $"Test for unused Local: {logWrittenBefore:dd/MM/yyyy HH:mm:ss}."
    End Using
  End Using

End Sub
I have included a screen clip below showing the reported warning:


Again, there are interpolated strings involved, so maybe the same issue that you have already identified.

Hope this helps.
Steve


0
Misha Zhutov Replied
Employee Post
Yes, it is the same issue (interpolated strings) you reported before.
0
Steve Marshall Replied
Hi Misha,

Okay, I was just unsure as the second code example still has the interpolated string but does not report an unused local variable. It is only the declaration of the variable (and its initialisation) that has been moved outside the Using block.

Steve

0
Serge B. Replied
Employee Post Marked As Answer
Hi Steve,

I wanted to let you know this has been addressed and you are welcome to email us and request the most current nightly build.

Thanks!
Serge Baranovsky
SubMain Software
(800) 936-2134

Reply to Thread