Jintin / Swimat

An Xcode formatter plug-in to format your swift code.
https://jintin.github.io/Swimat/
MIT License
1.65k stars 89 forks source link

Error when formatting unary operators #220

Open giuseppebertolini opened 4 years ago

giuseppebertolini commented 4 years ago

it separates minuses and pluses from the number/variable following them which introduces errors. ex "-1" -> "- 1"

Jintin commented 4 years ago

It shouldn't, can you give me more code sample when the issue happened?

giuseppebertolini commented 4 years ago

Thanks for replying quickly! It happened to me when using the ternary operator "?:" the code would go from this: x ? -1 : 1 to x ? - 1: 1. It may help you knowing that this: x ? 1 : -1 would be formatted as x ? 1: -1, which is still correct. Have a good day!

Jintin commented 4 years ago

It should work, may I ask your app version?

OolonColoophid commented 3 years ago

Hi

This issue appears to be happening for me. Xcode Version 12.5 (12E262), Swimat Version 1.7.0 (21), macOS 11.3.

This code:

      shapeRect = NSInsetRect(
                    shapeRect,
                    CGFloat(
                        -(borderThickness - 1.0)),
                    CGFloat(
                        -(borderThickness - 1.0)))

Is changed to:

      shapeRect = NSInsetRect(
                    shapeRect,
                    CGFloat(
                        - (borderThickness - 1.0)),
                    CGFloat(
                        - (borderThickness - 1.0)))

The error from Xcode is "Unary operator cannot be separated from its operand".

Cheers

Ian