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

Add new run script phrase…


This content originally appeared on DEV Community and was authored by Liang Wang

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

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

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"

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


This content originally appeared on DEV Community and was authored by Liang Wang


Print Share Comment Cite Upload Translate Updates
APA

Liang Wang | Sciencx (2024-08-06T18:09:17+00:00) Add SwiftLint to Xcode 15.4 on M1 mac. Retrieved from https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/

MLA
" » Add SwiftLint to Xcode 15.4 on M1 mac." Liang Wang | Sciencx - Tuesday August 6, 2024, https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/
HARVARD
Liang Wang | Sciencx Tuesday August 6, 2024 » Add SwiftLint to Xcode 15.4 on M1 mac., viewed ,<https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/>
VANCOUVER
Liang Wang | Sciencx - » Add SwiftLint to Xcode 15.4 on M1 mac. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/
CHICAGO
" » Add SwiftLint to Xcode 15.4 on M1 mac." Liang Wang | Sciencx - Accessed . https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/
IEEE
" » Add SwiftLint to Xcode 15.4 on M1 mac." Liang Wang | Sciencx [Online]. Available: https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/. [Accessed: ]
rf:citation
» Add SwiftLint to Xcode 15.4 on M1 mac | Liang Wang | Sciencx | https://www.scien.cx/2024/08/06/add-swiftlint-to-xcode-15-4-on-m1-mac/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.