vhdl-style-guide icon indicating copy to clipboard operation
vhdl-style-guide copied to clipboard

Rule to remove commented out code

Open imd1 opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe. Some people comment out code as they are changing it, and do not rely on source control to get back to the original. This leaves the code littered with "old" code as comments which looks very messy

Describe the solution you'd like A rule that parses the comments to determine if there is valid VHDL code hidden inside, and remove the comments if so

Describe alternatives you've considered Manual cleanup!

Additional context Add any other context or screenshots about the feature request here.

imd1 avatar Jun 17 '21 11:06 imd1

Hey @imd1 ,

This would be a killer feature if it could be implemented.

Do you have any thoughts on how we could differentiate between commented out code and comments?

jeremiah-c-leary avatar Jun 18 '21 00:06 jeremiah-c-leary

Hey @imd1 ,

This would be a killer feature if it could be implemented.

Do you have any thoughts on how we could differentiate between commented out code and comments?

remove the -- intelligently and check for parsable VHDL underneath?

imd1 avatar Jun 18 '21 11:06 imd1

remove the -- intelligently and check for parsable VHDL underneath?

Using this as an example:

   if a = b then
  -- if a = '0' then
   -- Do something
      c <= 5;
   end if;

I could remove the second comment. So in this case it would look like:

   if a = b then
   if a = '0' then
   -- Do something
      c <= 5;
   end if;

which would fail to parse and could be flagged.

However, what about the second comment? If we remove the -- and attempt to parse:

   if a = b then
  -- if a = '0' then
    Do something
      c <= 5;
   end if;

That would clearly fail to parse, but it is not commented out code.

jeremiah-c-leary avatar Sep 19 '21 13:09 jeremiah-c-leary

Could we make the following assumptions about commented out code?

  1. Contains at least one VHDL keyword
  2. Contains at least one of the following: signal name, constant name, variable name, function name, etc...

So in my previous example, which I have expanded:

architecture rtl of fifo is

  constant b : integer;
  signal a : integer;
  signal c : integer;

begin

  process begin
  if a = b then
    -- if a = '0' then
     -- Do something
        c <= 5;
     end if;
  end process;
end architecture;

I could then follow these steps:

  1. Collect all the signal and constant names
  2. Check if comment includes a signal or constant name
  3. Check if comment includes a VHDL keyword

So in the example above, the first comment would be flagged because a exists and if exists. The second comment would not be flagged because Do something is neither a signal/constant name nor a vhdl keyword.

I think this would only get you a certain class of commented out code.

jeremiah-c-leary avatar Sep 19 '21 14:09 jeremiah-c-leary

in your example, the if a = '0' then is valid VHDL even though it is incomplete, so I'd want this line removed...the -- Do something is clearly not.

So I would treat each comment line separately and somehow determine if it's valid VHDL or not

imd1 avatar Sep 23 '21 08:09 imd1

So I would treat each comment line separately and somehow determine if it's valid VHDL or not

I was just thinking of the possible permutations for commented out code, and it seems endless. I doubt we can make this perfect, but if we could catch a certain percentage of commented out code it would be worth it.

Maybe there should be a series of commented out code rules. For example:

commented_out_001: checks for commented out library statements:

-- library ieee;

commented_out_002: check for commented out use statements:

library ieee;
-- use ieee.std_logic_1164.all;

or it is part of the library rules:

library_???: Checks for commented out library statements:

-- library ieee;

So instead of a single rule to check for commented out code, we have multiple rules.

jeremiah-c-leary avatar Sep 25 '21 01:09 jeremiah-c-leary

Separate rules makes sense...

The underlying principle should be whether each commented out line is valid VHDL syntax if the -- was removed

imd1 avatar Dec 31 '21 09:12 imd1