From ccf85e87c3dd97d651ee83894110456e92cb0135 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Wed, 12 Apr 2017 22:36:27 +0900 Subject: [PATCH 1/3] Make `emoji` and `checkstyle` reporter to output report sorted by file name Fixes #1429 --- CHANGELOG.md | 4 +++- .../SwiftLintFramework/Reporters/CheckstyleReporter.swift | 1 + Source/SwiftLintFramework/Reporters/EmojiReporter.swift | 7 ++++--- .../Resources/CannedCheckstyleReporterOutput.xml | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5571a90164..d4a2d6fec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,9 @@ ##### Bug Fixes -* None. +* `emoji` and `checkstyle` reporter output report sorted by file name. + [norio-nomura](https://github.com/norio-nomura) + [#1429](https://github.com/realm/SwiftLint/issues/1429) ## 0.18.1: Misaligned Drum diff --git a/Source/SwiftLintFramework/Reporters/CheckstyleReporter.swift b/Source/SwiftLintFramework/Reporters/CheckstyleReporter.swift index bc349c2a5f..adabf4475e 100644 --- a/Source/SwiftLintFramework/Reporters/CheckstyleReporter.swift +++ b/Source/SwiftLintFramework/Reporters/CheckstyleReporter.swift @@ -21,6 +21,7 @@ public struct CheckstyleReporter: Reporter { "\n", violations .group(by: { ($0.location.file ?? "").escapedForXML() }) + .sorted(by: { $0.key < $1.key }) .map(generateForViolationFile).joined(), "\n" ].joined() diff --git a/Source/SwiftLintFramework/Reporters/EmojiReporter.swift b/Source/SwiftLintFramework/Reporters/EmojiReporter.swift index 20fd9255b2..65fd1d5a25 100644 --- a/Source/SwiftLintFramework/Reporters/EmojiReporter.swift +++ b/Source/SwiftLintFramework/Reporters/EmojiReporter.swift @@ -17,9 +17,10 @@ public struct EmojiReporter: Reporter { } public static func generateReport(_ violations: [StyleViolation]) -> String { - return violations.group { violation in - violation.location.file ?? "Other" - }.map(report).joined(separator: "\n") + return violations + .group(by: { $0.location.file ?? "Other" }) + .sorted(by: { $0.key < $1.key }) + .map(report).joined(separator: "\n") } private static func report(for file: String, with violations: [StyleViolation]) -> String { diff --git a/Tests/SwiftLintFrameworkTests/Resources/CannedCheckstyleReporterOutput.xml b/Tests/SwiftLintFrameworkTests/Resources/CannedCheckstyleReporterOutput.xml index a833b2e536..ad30976630 100644 --- a/Tests/SwiftLintFrameworkTests/Resources/CannedCheckstyleReporterOutput.xml +++ b/Tests/SwiftLintFrameworkTests/Resources/CannedCheckstyleReporterOutput.xml @@ -1,11 +1,11 @@ + + + - - - \ No newline at end of file From e0dfdb1d4762a57a2ff3d6e407c2b97e772dc1dd Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Fri, 14 Apr 2017 19:53:29 +0900 Subject: [PATCH 2/3] Update expected output of `testEmojiReporter()` --- .../Resources/CannedEmojiReporterOutput.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutput.txt b/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutput.txt index b9cfda2964..7b55f15b85 100644 --- a/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutput.txt +++ b/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutput.txt @@ -1,6 +1,6 @@ +Other +⛔️ Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. filename ⛔️ Line 1: Violation Reason. ⛔️ Line 1: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. -⚠️ Line 1: Violation Reason. -Other -⛔️ Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. \ No newline at end of file +⚠️ Line 1: Violation Reason. \ No newline at end of file From 45049e8cdf48296e752dae9538290fc316a3db64 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Fri, 14 Apr 2017 20:03:12 +0900 Subject: [PATCH 3/3] Apply workaround for https://bugs.swift.org/browse/SR-530 --- SwiftLint.xcodeproj/project.pbxproj | 4 ++++ Tests/SwiftLintFrameworkTests/ReporterTests.swift | 4 ++++ .../Resources/CannedEmojiReporterOutputNonObjC.txt | 6 ++++++ 3 files changed, 14 insertions(+) create mode 100644 Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutputNonObjC.txt diff --git a/SwiftLint.xcodeproj/project.pbxproj b/SwiftLint.xcodeproj/project.pbxproj index a5f5605f2f..db9c222706 100644 --- a/SwiftLint.xcodeproj/project.pbxproj +++ b/SwiftLint.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ 6CB8A80C1D11A7E10052816E /* Commandant.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8BA7E101B07A3EC003E02D0 /* Commandant.framework */; }; 6CB8A80D1D11A7E10052816E /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8BA7E121B07A3F3003E02D0 /* Result.framework */; }; 6CC4259B1C77046200AEA885 /* SyntaxMap+SwiftLint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CC4259A1C77046200AEA885 /* SyntaxMap+SwiftLint.swift */; }; + 6CC898A71EA0E1F7003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6CC898A61EA0E1EF003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt */; }; 6CCFCF2A1CFEF729003239EB /* Commandant.framework in Embed Frameworks into SwiftLintFramework.framework */ = {isa = PBXBuildFile; fileRef = E8BA7E101B07A3EC003E02D0 /* Commandant.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCF2C1CFEF72D003239EB /* Result.framework in Embed Frameworks into SwiftLintFramework.framework */ = {isa = PBXBuildFile; fileRef = E8BA7E121B07A3F3003E02D0 /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 6CCFCF2D1CFEF731003239EB /* SourceKittenFramework.framework in Embed Frameworks into SwiftLintFramework.framework */ = {isa = PBXBuildFile; fileRef = E876BFBD1B07828500114ED5 /* SourceKittenFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -332,6 +333,7 @@ 6C7045431C6ADA450003F15A /* SourceKitCrashTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceKitCrashTests.swift; sourceTree = ""; }; 6CB514E81C760C6900FA02C4 /* Structure+SwiftLint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Structure+SwiftLint.swift"; sourceTree = ""; }; 6CC4259A1C77046200AEA885 /* SyntaxMap+SwiftLint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SyntaxMap+SwiftLint.swift"; sourceTree = ""; }; + 6CC898A61EA0E1EF003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CannedEmojiReporterOutputNonObjC.txt; sourceTree = ""; }; 725094881D0855760039B353 /* StatementPositionConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementPositionConfiguration.swift; sourceTree = ""; }; 78F032441D7C877800BE709A /* OverriddenSuperCallRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverriddenSuperCallRule.swift; sourceTree = ""; }; 78F032471D7D614300BE709A /* OverridenSuperCallConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverridenSuperCallConfiguration.swift; sourceTree = ""; }; @@ -551,6 +553,7 @@ B3935939C8366514D2694722 /* CannedCSVReporterOutput.csv */, B39352E4EA2A06BE66BD661A /* CannedXcodeReporterOutput.txt */, B3935001033261E5A70CE101 /* CannedEmojiReporterOutput.txt */, + 6CC898A61EA0E1EF003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt */, B39350463894A3FC1338E0AF /* CannedJSONReporterOutput.json */, ); path = Resources; @@ -1106,6 +1109,7 @@ B39357173B43C9B5E351C360 /* CannedCheckstyleReporterOutput.xml in Resources */, B3935A32BE03C4D11B4364D6 /* CannedCSVReporterOutput.csv in Resources */, B3935522DC192D38D4852FA3 /* CannedXcodeReporterOutput.txt in Resources */, + 6CC898A71EA0E1F7003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt in Resources */, B39358AA2D2AF5219D3FD7C0 /* CannedEmojiReporterOutput.txt in Resources */, B3935A1C3BCA03A6B902E7AF /* CannedJSONReporterOutput.json in Resources */, ); diff --git a/Tests/SwiftLintFrameworkTests/ReporterTests.swift b/Tests/SwiftLintFrameworkTests/ReporterTests.swift index 83b83f092e..21e181afc3 100644 --- a/Tests/SwiftLintFrameworkTests/ReporterTests.swift +++ b/Tests/SwiftLintFrameworkTests/ReporterTests.swift @@ -61,7 +61,11 @@ class ReporterTests: XCTestCase { } func testEmojiReporter() { + #if _runtime(_ObjC) let expectedOutput = stringFromFile("CannedEmojiReporterOutput.txt") + #else + let expectedOutput = stringFromFile("CannedEmojiReporterOutputNonObjC.txt") + #endif let result = EmojiReporter.generateReport(generateViolations()) XCTAssertEqual(result, expectedOutput) } diff --git a/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutputNonObjC.txt b/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutputNonObjC.txt new file mode 100644 index 0000000000..b9cfda2964 --- /dev/null +++ b/Tests/SwiftLintFrameworkTests/Resources/CannedEmojiReporterOutputNonObjC.txt @@ -0,0 +1,6 @@ +filename +⛔️ Line 1: Violation Reason. +⛔️ Line 1: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array. +⚠️ Line 1: Violation Reason. +Other +⛔️ Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. \ No newline at end of file