groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

formatter ignoring line max length

Open scphantm opened this issue 7 years ago • 3 comments
trafficstars

I have this code

    def sphinxJson = addTaskLocal([name: BUILD_DOCS_JSON, type: SphinxDocumentationTask]) {
       type = SphinxDocType.JSON 
    }

the formatter formats it like this

def sphinxJson = addTaskLocal([name: BUILD_DOCS_JSON, type: SphinxDocumentationTask]) { type = SphinxDocType.JSON }

The problem with that is that it then blows up the line length that is configured.

here's my config file, this is being run thru spotless. What setting do i have to add in order to have it keep the formatting above? I don't want single line closures on the same line, i want them on a new line like the first example.

#Whether to use 'space', 'tab' or 'mixed' (both) characters for indentation. 
#The default value is 'tab'.
org.eclipse.jdt.core.formatter.tabulation.char=space

#Number of spaces used for indentation in case 'space' characters 
#have been selected. The default value is 4.
org.eclipse.jdt.core.formatter.tabulation.size=2

#Number of spaces used for indentation in case 'mixed' characters 
#have been selected. The default value is 4.
org.eclipse.jdt.core.formatter.indentation.size=2

#Whether or not indentation characters are inserted into empty lines.
#The default value is 'true'.
org.eclipse.jdt.core.formatter.indent_empty_lines=false

#Number of spaces used for multiline indentation.
#The default value is 2.
groovy.formatter.multiline.indentation=1

#Length after which list are considered too long. These will be wrapped.
#The default value is 30.
groovy.formatter.longListLength=100

#Whether opening braces position shall be the next line.
#The default value is 'same'.
groovy.formatter.braces.start=same

#Whether closing braces position shall be the next line.
#The default value is 'next'.
groovy.formatter.braces.end=next

#Remove unnecessary semicolons. The default value is 'false'. 
groovy.formatter.remove.unnecessary.semicolons=true

groovy.formatter.line.maxlength=100

scphantm avatar Jul 06 '18 21:07 scphantm

Actually, i don't think this is help wanted, i actually think this is a bug. look here, and all thru this file

https://github.com/groovy/groovy-eclipse/blob/b68a56be01cbe1e3067809d3b8535a2139ca1113/ide/org.codehaus.groovy.eclipse.refactoring/src/org/codehaus/groovy/eclipse/refactoring/formatter/GroovyBeautifier.java#L237

none of the closure code makes any effort to see if leaving the closure as a single line will blow up the max line length. in my example above, it does blow up the max line length. In my shop, line length takes precedence over everything else. Its the one rule that no other rule is allowed to violate.

scphantm avatar Jul 07 '18 15:07 scphantm

"help wanted" means that the (one and only) committer needs help from someone willing to spend time to fix this bug, it does not mean that this is not recognised as a bug.

mauromol avatar Aug 10 '18 07:08 mauromol

I have been marking all formatter bugs or enhancements as Help Wanted. If anyone wants to take on the formatter or replace it with a new implementation, I can consult.

eric-milles avatar Aug 10 '18 14:08 eric-milles