No comments
As an iOS developer (or any developer for that matter), it is not uncommon (or dare I say- its “very common”) for us to defer things while coding so as to not disrupt the current coding flow. For instance, handling of a special case or updating an algorithm with a more efficient one or just a reminder to double check a certain logic . To remind ourselves, we typically include a comment like “ToDo: Handle error code -1020” in our code.
Now, before we realize it, we have several “ToDos” and “FixMe” scattered throughout our project and unfortunately, many of them go unattended . Note that “attending” to them may be as simple as removing the comment because we have in fact handled the “To Do” but have just forgotten to remove the now obsolete comment which leads to clutter and confusing code.
So here is a neat little perl script that I found (and tweaked a wee bit for my purpose) that solves the problem. The script is executed every time my project is built. The purpose of script is simple. The script greps for keywords in all the .h and .m files in the ${SRCROOT} folder and prefixes it with a “warning” label.
|
<strong id="docs-internal-guid-5020052f-ea10-5329-745c-bf466704031a"><strong id="docs-internal-guid-5020052f-ea12-e944-5f13-b7ef5d6d5114"><span style="font-weight: normal; vertical-align: baseline; word-wrap: normal;"><strong id="docs-internal-guid-5020052f-ea12-9699-d985-d72d729511e3"><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;">KEYWORDS=</span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"TODO|ToDo|TODO:|FIXME:|\?\?\?:|\!\!\!:"</span></strong> <strong id="docs-internal-guid-5020052f-ea12-9699-d985-d72d729511e3"><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;">find </span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"${SRCROOT}"</span><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;"> \( -name </span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"*.h"</span><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;"> -or -name </span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"*.m"</span><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;"> \) -print0 | xargs -</span><span style="font-size: 11px; color: #272ad8; font-weight: normal; vertical-align: baseline;">0</span><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;"> egrep --with-filename --line-number --only-matching </span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"($KEYWORDS). *\$"</span><span style="font-size: 11px; font-weight: normal; vertical-align: baseline;"> | perl -p -e </span><span style="font-size: 11px; color: #d12f1b; font-weight: normal; vertical-align: baseline;">"s/($KEYWORDS)/ warning: \$1/"</span></strong></span></strong></strong> |
Now, every time, I compile my project, the script runs and displays all statements that begin with keywords listed in the KEYWORDS reg expression show up as warnings. They are now hard to miss and I can ensure that all the “To Do”s are handled in a timely manner.
To add the script, select “Add Build Phase” under the “Build Phases” tab of Xcode project settings.
Then , cut and paste the script to the “Run Script” section
Now, when you build your app, you should see all comments that include the keywords mentioned in the script listed as warnings.
Handling ToDo(s) and FixMe(s) in your code…
No comments
As an iOS developer (or any developer for that matter), it is not uncommon (or dare I say- its “very common”) for us to defer things while coding so as to not disrupt the current coding flow. For instance, handling of a special case or updating an algorithm with a more efficient one or just a reminder to double check a certain logic . To remind ourselves, we typically include a comment like “ToDo: Handle error code -1020” in our code.
Now, before we realize it, we have several “ToDos” and “FixMe” scattered throughout our project and unfortunately, many of them go unattended . Note that “attending” to them may be as simple as removing the comment because we have in fact handled the “To Do” but have just forgotten to remove the now obsolete comment which leads to clutter and confusing code.
So here is a neat little perl script that I found (and tweaked a wee bit for my purpose) that solves the problem. The script is executed every time my project is built. The purpose of script is simple. The script greps for keywords in all the .h and .m files in the ${SRCROOT} folder and prefixes it with a “warning” label.
Now, every time, I compile my project, the script runs and displays all statements that begin with keywords listed in the KEYWORDS reg expression show up as warnings. They are now hard to miss and I can ensure that all the “To Do”s are handled in a timely manner.
Then , cut and paste the script to the “Run Script” section
Now, when you build your app, you should see all comments that include the keywords mentioned in the script listed as warnings.