Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool/gem to find commented code

Over the course of our project with multiple developers and styles, we have some tests and code that are commented out. Is there an easy way to find all code that is commented out?

The tool should be smart enough to find out that it is ruby code that is being commented not, real comments.

At this point I can only think of grep like grep #, but it should be something smarter and less manual.

like image 542
satyajit Avatar asked Nov 14 '12 23:11

satyajit


People also ask

How do I find commented codes in Visual Studio?

Visual Studio 17.2 Preview 3 introduces a brand-new All-In-One search experience that merges the existing VS Search (Ctrl + Q) and Go To (Ctrl + T) to allow you to search both your code and Visual Studio features quicker and easier than ever, all in the same place.

Is commented out code dead code?

Dead code is code that is never executed. This can be a method that's no longer called, a commented out block of code, or code appearing after a return statement that's unreachable. In any case, it often reflects functionality that no longer exists in the software and offers no value.

How do I get commented code from Eclipse?

Finding comments is easy: search for "/*" or "//". And since comments have no formal relation to code, when is a comment "about" the code nearby, and when is it just a comment ("a sonnet to ...")?


1 Answers

This may be ugly but I think you can inspect each ".rb" file with a rake task, line per line, matching it with a regexp (something like /#.*\n/), and run an eval("matching_string") on each match. If the comment isn't ruby code it will simply fail.

like image 161
ichigolas Avatar answered Oct 05 '22 22:10

ichigolas