eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Always put spaces around comparison operators #113

Closed bjansen closed 9 years ago

bjansen commented 9 years ago

Currently, when an expressions uses multiple operators, the formatters groups them to show the precedence, for example:

a*b + c*d instead of a * b + c * d

While this is cool for arithmetic operators, I think it doesn't look as good on comparison operators:

aa===bb || 2<3 should be aa === bb || 2 < 3

lucaswerkmeister commented 9 years ago

No love for <3? Okay :(

bjansen commented 9 years ago
List<String> D = ...
for (String happy :D) {
}
gavinking commented 9 years ago

I'm not sure I agree with this. I tend to write x==1 instead of x == 1.

bjansen commented 9 years ago

@gavinking you also tend to set the maximum line width to 80 chars ;)

gavinking commented 9 years ago

It's not that I'm advocating one or the other; I'm just saying that it's pretty much a personal preference, and so it should be selectable.

lucaswerkmeister commented 9 years ago

What part should be selectable? There’s already the option forceSpaceAroundBinaryOp to completely disable this.

gavinking commented 9 years ago

What part should be selectable?

Well if you're going to pander to @bjansen's ridiculously wrong aesthetic preference ;-P then I don't think you should force it down my throat. So forceSpaceAroundBooleanOp would force the spacing only for comparison and logical ops.

Or, even better, you could have a hierarchy of these corresponding to the layers in spec §6.8: forceSpaceAroundComparisonOp (layer 2), forceSpaceAroundLogicalOp (layer 3), forceSpaceAroundConditionalOrAssignmentOp (layer 4).

@lucaswerkmeister I assume this is not for 1.2

lucaswerkmeister commented 9 years ago

I like the hierarchy idea. I’d like to have this in 1.2, but it’s not blocking, so moving the milestone.

lucaswerkmeister commented 9 years ago

Holy shit I just noticed that this feature actually breaks code!

shared void run() {
    String ema = "ema";
    Character c = 'c';
    Boolean b = true && c in ema;
}

formats to

shared void run() {
    String ema = "ema";
    Character c = 'c';
    Boolean b = true && cinema;
}

Oops…

bjansen commented 9 years ago

Ha! Take that, people who say I have wrong aesthetic preference ;)

lucaswerkmeister commented 9 years ago

I fixed that bug (eeef892).

lucaswerkmeister commented 9 years ago

@bjansen to fix this bug, put the following in your .ceylon/default.format:

[formatter]
spaceOptionalAroundOperatorLevel=1

This omits spaces around arithmetic operators, but not comparison operators.