Feat: Adding a script to run SwiftLint locally#2095
Feat: Adding a script to run SwiftLint locally#2095AntAmazonian wants to merge 16 commits intomainfrom
Conversation
sichanyoo
left a comment
There was a problem hiding this comment.
Script in this PR only runs lint, not analyzer.
scripts/lint.sh
Outdated
| SCRIPT_DIR="$(dirname "$0")" | ||
| CONFIG_PATH="$SCRIPT_DIR/../.swiftlint.yml" | ||
|
|
||
| swiftlint lint --config "$CONFIG_PATH" --strict |
There was a problem hiding this comment.
This just runs lint, not analyzer.
There was a problem hiding this comment.
Script now builds logger, runs analyzer, and lint
…ld log, run SwiftLint Analylzer, than stand lint.
sichanyoo
left a comment
There was a problem hiding this comment.
Is there a particular reason SPM build log was used instead of Xcode build log like in CI? I think the main point of having a script for this is so that we can easily run the analyzer lint the same way it is done in CI, but this technically diverges from it.
Have you run this lint yourself? Not sure if it would take forever to run because it tries to build every service in the project. See
aws-sdk-swift/.github/workflows/lint.yml
Lines 44 to 60 in 4c3e4ae
My intention is to allow this to be run even without xcode, I have ran in locally from the terminal. |
…o use remote instead of local, removes service clients for efficeincy, backs up and restores services
scripts/lint.sh
Outdated
| # aws-sdk-swift | ||
| # | ||
| # Created by Felix, Anthony on 1/23/26. | ||
| # |
There was a problem hiding this comment.
nit: Replace the header with the standard Amazon header. Example:
https://github.com/awslabs/aws-sdk-swift/blob/main/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/AWSClientConfigDefaultsProvider.swift#L1-L6
Alternatively, you can simply delete the header entirely.
jbelkins
left a comment
There was a problem hiding this comment.
See individual comments
scripts/lint.sh
Outdated
| echo "✅ Build completed successfully" | ||
|
|
||
| echo "Step 4: Running SwiftLint Analyze (this may take a few minutes)..." | ||
| timeout 300 swiftlint analyze --compiler-log-path "$LOG_FILE" || echo "⚠️ SwiftLint Analyze timed out after 5 minutes" |
There was a problem hiding this comment.
What is the reason for the 5 minute timeout? I generally disfavor setting timeouts unless they're there to address an operational problem, which I don't think we have here.
There was a problem hiding this comment.
The timeout I added as a just in case for local runs by the developer, but thinking twice about it now I think this should be more on the developer to set if they want to.
scripts/lint.sh
Outdated
| export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin" | ||
|
|
||
| # Unset AWS_SWIFT_SDK_USE_LOCAL_DEPS to use remote dependencies instead of local ones | ||
| unset AWS_SWIFT_SDK_USE_LOCAL_DEPS |
There was a problem hiding this comment.
I don't think we want to do this for a locally-run development script, since SDK developers are typically using a local copy of smithy-swift with local SDK. If you've made local SDK changes that have corresponding smithy-swift changes, the xcodebuild initiated below will fail.
There was a problem hiding this comment.
Okay, I didn't think about developers making their own changes if they used a copy of the SDK locally, I'll change it so leaves the deps alone if they were set by the developer. That way it's a choice on their end.
| - multiple_closures_with_trailing_closure | ||
| - cyclomatic_complexity | ||
| - file_length | ||
| - syntactic_sugar |
There was a problem hiding this comment.
Why the specific changes to linter rules in this file?
Also, for simplicity, we typically keep the same linter rules in SDK and in smithy-swift. So if we do change rules here, there should be a 2nd PR to change them there as well.
Issue #
N/A
Description of changes
The Swiftlint analyzer is configured to run on aws-sdk-swift CI. The analyzer provides better feedback than the main linter, but it also requires setup, including building the project prior to analysis.
A script is provided that developers can run on desktop to perform the same Swiftlint analysis that CI performs.
New/existing dependencies impact assessment, if applicable
N/A
Conventional Commits
"Add SwiftLint config and local execution script"
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.