Greetings wise brothers, I seek your wisdom in the matter of how fat fingers, mistakes and carelessness can corrupt our beautiful code.

I am looking for a way to spellcheck perl source code. If it can be done reliably enough then I would like to add it as a pre-commit hook to our source control, but even if that is not possible, it would be good to warn developers so that they can change things.

I have done an internet search and found modules such as Perl::Critic::Policy::Documentation::PodSpelling and Test::Spelling, which look useful, but they only check the spelling of POD documents not the rest of the source code.

What I would really like to do is to intelligently check the spelling on variable and method names as well. So that if someone names a scalar as $new_varable or $newVarable it will find the variable in the source, intelligently split the name on underscores and case changes, and spellcheck the parts. (And report that varable is wrong (it should have an i). I don't need a spellchecker to offer replacements, as my editor can usually do that once I isolate the error, but I do need a better way to find error.

The reason I am after such a tool is that developers will often search for methods or variables by name. So for example, a developer might be looking for the function to increase a variable, and miss it because it is named increease_varable()

Any suggestions? do such tools exist? I know that it is impossible to write a perfect tool of this nature, because only perl can parse perl, but something that does 90% would be a great deal better than nothing. Looking at perldebguts, I was wondering if you could hook the debugger to return all the names (variables, functions, globs etc) declared in a source file, and then parse them for possible errors.


In reply to Check spelling in perl source code. by chrestomanci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.