Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"spaceAroundOperators" is not being applied #1755

Open
Ahbee opened this issue Jul 15, 2024 · 3 comments
Open

"spaceAroundOperators" is not being applied #1755

Ahbee opened this issue Jul 15, 2024 · 3 comments

Comments

@Ahbee
Copy link

Ahbee commented Jul 15, 2024

Im using the Xcode source editor extension with the default options,
However the space around the + and * is not being applied for this input:

import Foundation

func test() -> Double {
  let T = 5.0
  let e = 6.1
  let c0 = 1.0
  let c1 = -1.0
  let p = c0+T*(c1+T)
  return (e / pow(p, 8))*100.0
}

the formatting does nothing but I expect it to look like this:

import Foundation

func test() -> Double {
  let T = 5.0
  let e = 6.1
  let c0 = 1.0
  let c1 = -1.0
  let p = c0 + T * (c1 + T)
  return (e / pow(p, 8)) * 100.0
}
@nicklockwood
Copy link
Owner

nicklockwood commented Jul 15, 2024

The explanation here is the same as for your other report - in Swift a+ b is not legal code.

In this case since the intent is obvious I can probably add a workaround, but there are other cases like a+ -b that are legal in C but would be ambiguous in Swift.

Sorry, my reading comprehension is not good today 🤦‍♂️ I'm not sure why the formatting isn't being applied here - I will investigate.

@nicklockwood
Copy link
Owner

@Ahbee I think what's happening here is that by default the SwiftFormat Xcode extension has the "Infer Options Automatically" option enabled, which means that it looks at the existing contents of the file to decide which settings to use. If your file has more unspaced operators than spaced ones, it will assume that's the style you wanted.

Uncheck the "Infer Options Automatically" option in the SwiftFormat for Xcode app and see if that solves it.

@Ahbee
Copy link
Author

Ahbee commented Jul 17, 2024

yeah that seems to solve it thanks! But I feel that option should not be part of the default? I think most new users would just be confused why the code is not formatting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants