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

Formatting a SwiftUI view modifier surrounded by #if/#endif has extra indentation #1632

Open
lyamamot opened this issue Feb 22, 2024 · 0 comments
Labels

Comments

@lyamamot
Copy link

SwiftFormat is giving me extra indentation when formatting code inside an #if block and I don't know why.

I'd like to format the following code as shown:

Essentially, I want to disable a block of code using #if but keep what's inside the block formatted as usual.

public struct IfIndentView: View {
    public var body: some View {
        Text("Hello")
    }
#if false
    // Hi
    .task {
        print("Some work here.")
    }
#endif
}

However, when I format this using swiftformat --swiftversion 5.9 --ifdef outdent (version 0.53.2), the code inside the #if has extra indentation in the comment before .task and in part of that block itself:

public struct IfIndentView: View {
    public var body: some View {
        Text("Hello")
    }
#if false
        // Hi
    .task {
            print("Some work here.")
        }
#endif
}

I couldn't find a good combination of configuration options to try to fix this, though if I remove the #if altogether, of course it formats correctly.

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

No branches or pull requests

2 participants