#278 Carriage Return check

open
nobody
Check (274)
5
2012-10-10
2004-01-23
JC Lopez
No

This is should be done with a regular expression on
GenericIllegalRegexpCheck.java

for finding spaces at end of line is fine

<module name="GenericIllegalRegexp">
<property name="format" value="\\s+$"/>
<property name="message" value="Trailing spaces"/>
</module>

but if you try to find a carriage return, the ^M
with

<module name="GenericIllegalRegexp">
<property name="format" value="\\r$"/>
<property name="message" value="Carriage Return"/>
</module>

it won't find them at all, but if you go in with vi or vim
and do a \r$ it will find them. So I think it depends
on regexp from apache, although they do mention a
carriage return is
\r.

Would any know how to use checkstyle current version to
find carriage returns ^M?

Discussion

  • Logged In: YES
    user_id=746148

    The problem is not in jakarta-regexp. The library finds ^M
    if the line contains it. But we apply it to lines we get
    using LineNumberReader which eats all ^M (see
    LineNumberReader documentation).
    So, in current checkstyle's version the only way to find
    ^M is to write FileSetCheck for this.
    Perhaps we should reconsider algorithm we use to get lines of
    files so it will not eat annecessary ^M (if it's possible)