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

Disable "respectsExistingLineBreaks" in .swift-format for more consistent styling #230

Closed
czechboy0 opened this issue Aug 30, 2023 · 7 comments · Fixed by #346
Closed

Disable "respectsExistingLineBreaks" in .swift-format for more consistent styling #230

czechboy0 opened this issue Aug 30, 2023 · 7 comments · Fixed by #346
Assignees
Labels
area/generator Affects: plugin, CLI, config file. area/runtime Affects: the runtime library. area/transport Affects: Client or server transport library. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.)
Milestone

Comments

@czechboy0
Copy link
Contributor

Disable "respectsExistingLineBreaks" in .swift-format for more consistent styling.

Today, respectsExistingLineBreaks is enabled, which means that it depends on how you write the code before running the formatter, and it affects the output. That's not ideal, and is different than the setting we have for formatted code, so affects #40.

This should be done as a single PR, as it'll cause some churn.

@czechboy0 czechboy0 added area/generator Affects: plugin, CLI, config file. area/runtime Affects: the runtime library. area/transport Affects: Client or server transport library. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.) labels Aug 30, 2023
@czechboy0 czechboy0 added this to the 1.0 milestone Aug 30, 2023
@glbrntt
Copy link
Contributor

glbrntt commented Aug 30, 2023

Would disabling this rule remove all unnecessary line breaks?

E.g. would

func foo() {
  let bar = try makeBar()
  
  let baz = process(bar)
  baz.doSomething()
}

become the following?

func foo() {
  let bar = try makeBar()
  let baz = process(bar)
  baz.doSomething()
}

@czechboy0
Copy link
Contributor Author

No, it leaves those alone. It only reformats line breaks around source code, it seems: #231

@glbrntt
Copy link
Contributor

glbrntt commented Aug 30, 2023

Oh that seems reasonable then. Saying that, from the diff I'm not convinced this makes the code any easier to read. In fact some places it worsens readability. Perhaps other rules need tweaking when enabling this as well.

A few examples:

} catch {
        XCTFail(error.localizedDescription, file: file, line: line)
}

changed to

} catch { XCTFail(error.localizedDescription, file: file, line: line) }

and

    public static func error(
        message: String,
        location: Location? = nil,
        context: [String: String] = [:]
    ) -> Diagnostic {
        .init(severity: .error, message: message, location: location, context: context)
    }

changed to

    public static func error(message: String, location: Location? = nil, context: [String: String] = [:]) -> Diagnostic
    { .init(severity: .error, message: message, location: location, context: context) }

@czechboy0
Copy link
Contributor Author

Yeah I don't love the bias towards single line scopes either. I'll take a look at the rules if we can't opt out of that.

@czechboy0 czechboy0 modified the milestones: 1.0, Post-1.0 Aug 31, 2023
@PARAIPAN9
Copy link
Contributor

Hello, I would be interested in working on this issue if it's available

@czechboy0
Copy link
Contributor Author

czechboy0 commented Oct 5, 2023

Sure @PARAIPAN9, although it might result in a big diff, so maybe you could look into landing this one first? #188

@PARAIPAN9
Copy link
Contributor

Sure, thanks!!

czechboy0 pushed a commit that referenced this issue Oct 25, 2023
…tent styling (#346)

### Motivation

- Fixes #230

### Modifications

- Disable respectsExistingLineBreaks .swift-format rule and address
changes requested

### Result

- One of the .swift-format rules will be disabled

### Test Plan

- Run Tests
czechboy0 pushed a commit to swift-server/swift-openapi-async-http-client that referenced this issue Nov 1, 2023
…tent styling (#23)

### Motivation

- Relates to
[#230](apple/swift-openapi-generator#230)

### Modifications

- Disable respectsExistingLineBreaks .swift-format rule and address
changes requested

### Result

- One of the .swift-format rules will be disabled

### Test Plan

- Run Tests
czechboy0 added a commit to apple/swift-openapi-urlsession that referenced this issue Nov 1, 2023
…tent styling (#20)

### Motivation

- Relates to
[#230](apple/swift-openapi-generator#230)

### Modifications

- Disable respectsExistingLineBreaks .swift-format rule and address
changes requested

### Result

- One of the .swift-format rules will be disabled

### Test Plan

- Run Tests

Co-authored-by: Honza Dvorsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/generator Affects: plugin, CLI, config file. area/runtime Affects: the runtime library. area/transport Affects: Client or server transport library. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.)
Projects
None yet
3 participants