How can I detect misspelled words in source code?

1

I have been given some code written by a developer that could not spell to save his life.

For example, in the OUTPUT of the program, he has spelled the word 'circular' as both "Circual" and "circiual", and the word 'following' as 'follwing' (not to mention all the typos in the code and comments).

I want to clean up some of the typos in the code, but since some of the spelling is inconsistent, it wouldn't be easy to find all variants of misspellings of the word.

Does there exist a fuzzy search tool (such as a plugin for Notepad++ or vim) I could use to look for substrings that are similar to 'circular'? A simple spell-check tool wouldn't work (it's code -- the word 'circular' could appear in part of a variable name).

Casey Kuball

Posted 2012-07-20T16:10:56.210

Reputation: 337

What IDE are you using right now? – Brad – 2012-07-20T16:16:21.493

@Brad I am using Notepad++ (editor), but I am familiar with many others (including vim, eclipse, Visual Studio). – Casey Kuball – 2012-07-20T16:21:20.860

How much 'extra' information is in the word names, e.g. are we talking nCircular or much more, e.g. nCircularMotion? – snowdude – 2012-08-07T13:14:59.563

@snowdude If 'Circular' appears in the word it should match it. – Casey Kuball – 2012-08-07T14:50:56.033

Answers

1

Visual Studio (and I'm sure others hopefully NP++ which I have not used) allows you to search/find and replace using Regular Expressions. You can make them pretty fuzzy.

I like to test out my Regex on this site before using it in code. http://regexpal.com/

i.e. use circ(\S){0,4} to find

  • "Circual"
  • "circular"
  • "circiual"

then use "circular" as your replace term.

Brad

Posted 2012-07-20T16:10:56.210

Reputation: 486

Notepad++ definitely has regex, so this could work as a general-purpose solution. I was hoping that I might be able to avoid thinking too much about each word though (e.g. what happens if he misspells it 'cricular': c[irua]{1,3}c[irual]{1,5}). – Casey Kuball – 2012-07-20T16:35:24.433

yeah...sounds like a pretty crappy problem to have! Regex can help and generally make it easier but you're right, it won't catch the worst spelling mistakes. This is my only idea other than spending a day or two going through the project. Maybe someone else will have more insight. – Brad – 2012-07-20T16:40:06.267