Skip to content

Commit

Permalink
PrettyPrinter reports wrong line LineNumbersTests
Browse files Browse the repository at this point in the history
This is to reproduce issue swiftlang#882.
No fix is provided yet.

Issue: swiftlang#882
  • Loading branch information
bkolb committed Nov 23, 2024
1 parent 5a0ac33 commit 27172d6
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/LineNumbersTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import SwiftFormat
import _SwiftFormatTestSupport

final class LineNumbersTests: PrettyPrintTestCase {
func testLineNumbers() {
let input =
"""
final class A {
@Test func b() throws {
doSomethingInAFunctionWithAVeryLongName() 1️⃣// Here we have a very long comment that should not be here because it is far too long
}
}
"""

let expected =
"""
final class A {
@Test func b() throws {
doSomethingInAFunctionWithAVeryLongName() // Here we have a very long comment that should not be here because it is far too long
}
}
"""

assertPrettyPrintEqual(input: input,
expected: expected,
linelength: 120,
configuration: LineNumbersTests.myConfig,
whitespaceOnly: true,
findings: [
FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")
])
}

func testLineNumbersWithComments() {
let input =
"""
// Copyright (C) 2024 My Coorp. All rights reserved.
//
// This document is the property of My Coorp.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// My Coorp.
final class A {
@Test func b() throws {
doSomethingInAFunctionWithAVeryLongName() 1️⃣// Here we have a very long comment that should not be here because it is far too long
}
}
"""

let expected =
"""
// Copyright (C) 2024 My Coorp. All rights reserved.
//
// This document is the property of My Coorp.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// My Coorp.
final class A {
@Test func b() throws {
doSomethingInAFunctionWithAVeryLongName() // Here we have a very long comment that should not be here because it is far too long
}
}
"""

assertPrettyPrintEqual(input: input,
expected: expected,
linelength: 120,
configuration: LineNumbersTests.myConfig,
whitespaceOnly: true,
findings: [
FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")
])
}

public static var myConfig: Configuration {
var config = Configuration()
config.rules = Configuration.defaultRuleEnablements
config.maximumBlankLines = 1
config.lineLength = 120
config.tabWidth = 8
config.indentation = .spaces(4)
config.respectsExistingLineBreaks = true
config.lineBreakBeforeControlFlowKeywords = false
config.lineBreakBeforeEachArgument = false
config.lineBreakBeforeEachGenericRequirement = false
config.prioritizeKeepingFunctionOutputTogether = true
config.indentConditionalCompilationBlocks = false
config.lineBreakAroundMultilineExpressionChainComponents = false
config.fileScopedDeclarationPrivacy = FileScopedDeclarationPrivacyConfiguration()
config.indentSwitchCaseLabels = true
config.spacesAroundRangeFormationOperators = false
config.noAssignmentInExpressions = NoAssignmentInExpressionsConfiguration()
config.multiElementCollectionTrailingCommas = true
config.indentBlankLines = false
return config
}

}

0 comments on commit 27172d6

Please sign in to comment.