3

I'm testing SwiftLint's (experimental) analyze feature and am able to generate reports. Now I would like to get them back into Xcode and display these as warnings and errors.

Using the xcode formatter/reporter a file of this structure was created:

/absolute/path/to/source/Scenes/UpdateOS/UpdateOSViewModel.swift:10:6: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
/absolute/path/to/source/Scenes/UpdateOS/UpdateOSViewModel.swift:11:6: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
/absolute/path/to/source/Scenes/UpdateOS/UpdateOSViewController.swift:7:7: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
/absolute/path/to/source/Scenes/Home/Cells/Statistics/HomeStatisticsCellModel.swift:5:1: warning: Unused Import Violation: All imported modules should be required to make the file compile. (unused_import)
/absolute/path/to/source/Scenes/Home/Cells/Statistics/HomeStatisticsCellModel.swift:6:1: warning: Unused Import Violation: All imported modules should be required to make the file compile. (unused_import)
/absolute/path/to/source/Scenes/Home/Cells/Statistics/HomeStatisticsCard.swift:5:1: warning: Unused Import Violation: All imported modules should be required to make the file compile. (unused_import)
/absolute/path/to/source/Scenes/Home/Cells/Statistics/Extensions/SAP_Internal_Stats_Statistics+SupportedIDs.swift:5:1: warning: Unused Import Violation: All imported modules should be required to make the file compile. (unused_import)
/absolute/path/to/source/Scenes/Home/Cells/TraceLocations/HomeTraceLocationsCellModel.swift:10:6: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
/absolute/path/to/source/Scenes/Home/Cells/TraceLocations/HomeTraceLocationsCellModel.swift:11:6: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
/absolute/path/to/source/Scenes/Home/Cells/TraceLocations/HomeTraceLocationsCellModel.swift:12:6: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)

Is there a general way to 'load' a list of warnings/errors into Xcode? My first approach was an XcodeKit extension but I have hope this is already tackled.

Carsten
  • 1,029
  • 14
  • 29

1 Answers1

3

I guess you already found out the answer, but in case you didn't: error: and warning: are automatically parsed and handled in Xcode as such, so it's enough if you add the command as "Run Script" Build phase.

Daniel Bauke
  • 1,208
  • 14
  • 25
  • I want to add `swiftlint analyze` as a run script, but the command appears to require a console log to run, such as `swiftlint analyze --compiler-log-path xcodebuild.log`. Does a standard Xcode build generate such log files, and if so, where can I find them? – Steve U Aug 05 '22 at 19:43
  • @SteveU I never checked it because `analyze` took about an hour on our project. That's why I never wanted to have it inside Xcode but just run it from time to time manually. – Daniel Bauke Aug 07 '22 at 17:23
  • Thanks for the reply. The logs are stored in DerivedData//Logs/Build and are encrypted by default. They can be decrypted with the MacOS Archive Utility and then analyzed with `swiftlint analyze --compiler-log-path `. – Steve U Aug 08 '22 at 22:05
  • The documentation at https://github.com/realm/SwiftLint#analyze was also updated with a different way to obtain the logs without the decryption detour: 1) clean `DerivedData` as incremental builds won't work with analyze 2) run `xcodebuild -workspace {WORKSPACE}.xcworkspace -scheme {SCHEME} > xcodebuild.log` 3) run `swiftlint analyze --compiler-log-path xcodebuild.log` – harp Jan 19 '23 at 20:33