Skip to content

Commit 708e63b

Browse files
author
Raymond McCrae
committed
Fixup formatting for SwiftLint rules
1 parent 0ba5c21 commit 708e63b

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

.swiftlint.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ opt_in_rules:
1010
disabled_rules:
1111
- todo # todo and fixme should be avoided. Use custom script for this
1212
- vertical_parameter_alignment # parameter alignment in functions. Xcode use another alignment logic
13+
file_length:
14+
warning: 600
15+
error: 1000
1316
line_length: 120
1417
function_body_length:
15-
- 20
16-
- 40
18+
- 30
19+
- 50
1720
nesting:
1821
type_level:
1922
warning: 3

Sources/HTMLSAXParser/EscapeSpecialCharacters.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,25 @@ public enum HTMLQuoteCharacter: Character {
4040

4141
public extension Data {
4242

43-
fileprivate func encodeHTMLEntitiesBytes(_ outputLength: inout Int, _ outputLengthBytes: UnsafeMutablePointer<CInt>, _ inputLengthBytes: UnsafeMutablePointer<CInt>, _ quoteCharacter: HTMLQuoteCharacter, _ inputLength: Int, _ loop: inout Bool, _ bufferGrowthFactor: Double) -> Data? {
43+
// swiftlint:disable:next function_parameter_count
44+
fileprivate func encodeHTMLEntitiesBytes(_ outputLength: inout Int,
45+
_ outputLengthBytes: UnsafeMutablePointer<CInt>,
46+
_ inputLengthBytes: UnsafeMutablePointer<CInt>,
47+
_ quoteCharacter: HTMLQuoteCharacter,
48+
_ inputLength: Int,
49+
_ loop: inout Bool,
50+
_ bufferGrowthFactor: Double) -> Data? {
4451
return self.withUnsafeBytes { (inputBytes: UnsafePointer<UInt8>) -> Data? in
4552
let outputBufferCapacity = outputLength
4653
let outputBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: outputBufferCapacity)
4754
defer {
4855
outputBuffer.deallocate(capacity: Int(outputBufferCapacity))
4956
}
50-
let result = htmlEncodeEntities(outputBuffer, outputLengthBytes, inputBytes, inputLengthBytes, quoteCharacter.characterCode)
57+
let result = htmlEncodeEntities(outputBuffer,
58+
outputLengthBytes,
59+
inputBytes,
60+
inputLengthBytes,
61+
quoteCharacter.characterCode)
5162

5263
if result == 0 { // zero represents success
5364
// Have we consumed the length of the input buffer
@@ -87,7 +98,13 @@ public extension Data {
8798
inputLengthBytes.pointee = CInt(inputLength)
8899
outputLengthBytes.pointee = CInt(outputLength)
89100

90-
let outputData = encodeHTMLEntitiesBytes(&outputLength, outputLengthBytes, inputLengthBytes, quoteCharacter, inputLength, &loop, bufferGrowthFactor)
101+
let outputData = encodeHTMLEntitiesBytes(&outputLength,
102+
outputLengthBytes,
103+
inputLengthBytes,
104+
quoteCharacter,
105+
inputLength,
106+
&loop,
107+
bufferGrowthFactor)
91108

92109
if let outputData = outputData {
93110
return outputData

Sources/HTMLSAXParser/HTMLSAXParser+libxml2.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ internal extension HTMLSAXParser {
4646
let handlerContext = HandlerContext(handler: handler)
4747
let handlerContextPtr = Unmanaged<HandlerContext>.passUnretained(handlerContext).toOpaque()
4848
var libxmlHandler = HTMLSAXParser.libxmlSAXHandler
49-
guard let parserContext = htmlCreatePushParserCtxt(&libxmlHandler, handlerContextPtr, dataBytes, Int32(dataLength), nil, charEncoding) else {
49+
guard let parserContext = htmlCreatePushParserCtxt(&libxmlHandler,
50+
handlerContextPtr,
51+
dataBytes,
52+
Int32(dataLength),
53+
nil,
54+
charEncoding) else {
5055
throw Error.unknown
5156
}
5257
defer {

Sources/HTMLSAXParser/HTMLSAXParser.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ open class HTMLSAXParser {
5757
public static let ignoreEncodingHint = ParseOptions(rawValue: Int(HTML_PARSE_IGNORE_ENC.rawValue))
5858

5959
/// Default set of parse options.
60-
public static let `default`: ParseOptions = [.recover, .noBlanks, .noNetwork, .noImpliedElements, .compactTextNodes]
60+
public static let `default`: ParseOptions = [
61+
.recover,
62+
.noBlanks,
63+
.noNetwork,
64+
.noImpliedElements,
65+
.compactTextNodes]
6166
}
6267

6368
public struct Location {

Tests/HTMLSAXParser/HTMLParserTests.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,31 @@ class HTMLParserTests: XCTestCase {
4141
do {
4242
let parser = HTMLSAXParser()
4343
try parser.parse(data: data, handler: { (_, _) in
44-
XCTFail()
44+
XCTFail("Empty document should not generate any events")
4545
})
46-
XCTFail()
46+
XCTFail("Empty document should throw an error")
4747
} catch HTMLSAXParser.Error.emptyDocument {
4848
threwError = true
4949
} catch {
50-
XCTFail()
50+
XCTFail("Wrong type of error thrown")
5151
}
5252

5353
XCTAssertTrue(threwError)
5454
}
5555

56-
func test_parse_strint_empty() {
56+
func test_parse_string_empty() {
5757
let string = ""
5858
var threwError = false
5959
do {
6060
let parser = HTMLSAXParser()
6161
try parser.parse(string: string, handler: { (_, _) in
62-
XCTFail()
62+
XCTFail("Empty document should not generate any events")
6363
})
64-
XCTFail()
64+
XCTFail("Empty document should throw an error")
6565
} catch HTMLSAXParser.Error.emptyDocument {
6666
threwError = true
6767
} catch {
68-
XCTFail()
68+
XCTFail("Wrong type of error thrown")
6969
}
7070

7171
XCTAssertTrue(threwError)
@@ -92,7 +92,7 @@ class HTMLParserTests: XCTestCase {
9292
}
9393
}
9494
} catch {
95-
XCTFail()
95+
XCTFail("Unexpected error thrown")
9696
}
9797

9898
XCTAssertTrue(calledStartElement)
@@ -134,10 +134,12 @@ class HTMLParserTests: XCTestCase {
134134
func testImageExtraction() {
135135
do {
136136
let imageSources = try self.imageSources(from: HTMLParserTests.testHTMLArticleWithImages)
137+
// swiftlint:disable line_length
137138
XCTAssertEqual(imageSources, [
138139
"https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/01-COBRA-SUCURI-3M-WAGNER-MEIER_MG_2458.JPG/640px-01-COBRA-SUCURI-3M-WAGNER-MEIER_MG_2458.JPG",
139140
"https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Brachypelma_smithi_2009_G03.jpg/640px-Brachypelma_smithi_2009_G03.jpg",
140141
"https://upload.wikimedia.org/wikipedia/commons/d/d7/Panamanian_night_monkey.jpg"])
142+
// swiftlint:enable line_length
141143
} catch {
142144
XCTFail("Error thrown while parsing")
143145
}

0 commit comments

Comments
 (0)