[Codenarc-user] BracesForClassRule not working with enums
Brought to you by:
chrismair
From: Marcin G. <ma...@gr...> - 2012-12-15 17:14:11
|
BracesForClassRule doesn't work well for enums. If you add a new test case to BracesForClassRuleTest: @Test void testEnum() { final SOURCE = ''' enum MyClass { } ''' rule.sameLine = false assertSingleViolation(SOURCE, 2, 'class MyClass {', 'Opening brace for the class MyClass should start on a new line') } Then the assertion message is following: java.lang.AssertionError: Wrong line number for violation: Violation[rule=BracesForClassRule[name=BracesForClass, priority=2], lineNumber=-1, sourceLine=null, message=Opening brace for the class MyClass should start on a new line] Expected: 2 Found: -1 After debugging, it seems to be a Groovy issue. AstUtil.findFirstNonAnnotationLine calls node.getLineNumber() and the ClassNode represeting an enum returns -1. Any ideas on how to fix this issue (or find a feasible workaround)? Parse the source code and find out the line number? Background: we are working on some CodeNarc issues during our open source days. Marcin Gryszko <http://twitter.com/mgryszko> <https://plus.google.com/112949188816397592850> <http://xing.com/profile/Marcin_Gryszko> <http://linkedin.com/in/mgryszko> <http://grysz.com> <http://slideshare.net/mgryszko> |