问题
Is there a way to check if the file is using LFs only and no CRLFs or vice versa in checkstyle?
The only check which I have found is
NewlineAtEndOfFile
But I search for more as only at the end of the file?
回答1:
Only to supplement the Michal Kordas's good answer.
Below is a slightly modified configuration, which will only match the first wrong newline and forbid also the Mac OS Line Endings (CR):
<module name="RegexpMultiline">
<property name="format" value="(?s:(\r\n|\r).*)"/>
<property name="message" value="CRLF and CR line endings are prohibited, but this file uses them."/>
</module>
It has been posted by Michael Vorburger in this discussion, so kudos for him - I've posted it here for completeness.
回答2:
There is nothing out-of-the box in Checkstyle yet. If you want to prohibit CRLF you can use the following config:
<module name="RegexpMultiline">
<property name="format" value="\r\n"/>
<property name="message" value="CRLF line endings are prohibited"/>
</module>
and this one to ban LFs:
<module name="RegexpMultiline">
<property name="format" value="(?<!\r)\n"/>
<property name="message" value="LF line endings are prohibited"/>
</module>
来源:https://stackoverflow.com/questions/32903412/how-to-tell-checkstyle-to-check-all-lines-for-linefeed-newline-lf-and-not-crlf