DEV Community

Liang Wang
Liang Wang

Posted on • Edited on

Add SwiftLint to Xcode 15.4 on M1 Mac

I noticed that SwiftLint no longer works for me in Xcode 15.4 when I switched to a M1 Mac, so I searched and found this user script that has helped me to resolve this problem.

Install SwiftLint

brew install swiftlint 
Enter fullscreen mode Exit fullscreen mode

Add new run script phrase

if [[ "$(uname -m)" == arm64 ]]; then export PATH="/opt/homebrew/bin:$PATH" fi if which swiftlint > /dev/null; then swiftlint --fix && swiftlint else echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint" fi 
Enter fullscreen mode Exit fullscreen mode

Disable User Script Sandboxing
Do not forget to disable User Script Sandboxing in Build Settings/Build options, which is enabled by default from XCode 15.

Swiftlint rules
Update the line_length warning and error so it works for you.

disabled_rules: - trailing_whitespace opt_in_rules: - empty_count - empty_string excluded: - Carthage - Pods - SwiftLint/Common/3rdPartyLib line_length: warning: 300 error: 500 ignores_function_declarations: true ignores_comments: true ignores_urls: true function_body_length: warning: 300 error: 500 function_parameter_count: warning: 10 error: 15 type_body_length: warning: 300 error: 500 file_length: warning: 1000 error: 1500 ignore_comment_only_lines: true cyclomatic_complexity: warning: 15 error: 25 reporter: "xcode" 
Enter fullscreen mode Exit fullscreen mode

SwiftLint disable rule
For example, // swiftlint:disable:next identifier_name

Top comments (0)