Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ The script for an app should look like:
```
"${SRCROOT}/Submodules/SMF-iOS-CommonProjectSetupFiles/setup-common-project-files.sh" --buildconfig "${CONFIGURATION}" --targettype "${PRODUCT_TYPE}"
```

If the App uses SwiftUI, this call should be used:

```
"${SRCROOT}/Submodules/SMF-iOS-CommonProjectSetupFiles/setup-common-project-files.sh" --buildconfig "${CONFIGURATION}" --targettype "${PRODUCT_TYPE}" --SwiftUI
```

If you're developing on a framework use this line on the all of your Unit Test targets:

```
Expand Down
89 changes: 83 additions & 6 deletions SwiftLint/copy-and-run-swiftlint-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ readonly temporarySwiftLintConfigFilename=".$(uuidgen)-swiftlint.yml"

projectDir="$1"
isFramework=$2
swiftUI=$3

#
# Check requirements
#

# Check if project dir is provided. If not: Use the scripts base directory.
if [ -z "$1" ]; then
projectDir="$scriptBaseFolderPath"
projectDir="$scriptBaseFolderPath"
fi

# Contains the local SwiftLint settings (.project-swiftlint.yml). Global so we dont read it multiple times.
Expand All @@ -35,7 +36,7 @@ declare -a local_lines
function read_local_settings() {
let i=0
while IFS=$'\n' read -r -a line_data; do
local_lines[i]="${line_data}"
local_lines[i]="${line_data}"
((++i))
done < $1
}
Expand Down Expand Up @@ -64,7 +65,7 @@ function write_local_settings() {
done
}

function merge_commons_with_project_excluded_paths () {
function merge_commons_with_project_excluded_paths() {

read_local_settings "$projectDir/.project-swiftlint.yml"

Expand All @@ -83,6 +84,73 @@ function merge_commons_with_project_excluded_paths () {
return 0
}

# Adds disabled rules to diabled section and removes custom rules for the custom rules section
function add_swiftUI_disabled_rules() {
disabled_pattern="disabled_rules:"
disabled_flag_1=false
disabled_flag_2=false
in_rule=false
temporarySwiftUILintConfigFilename=".$(uuidgen)-swiftlint-swift-ui.yml"
local base_file=$1

touch "$temporarySwiftUILintConfigFilename"

while IFS= read -r line_1 || [[ -n "$line_1" ]]; do

if [[ $disabled_flag_1 == true ]]; then

while IFS= read -r line_2 || [[ -n "$line_2" ]]; do

if [[ $disabled_flag_2 == true ]]; then
echo "$line_2" >> "$temporarySwiftUILintConfigFilename"
fi

if [[ $line_2 =~ $disabled_pattern ]]; then
disabled_flag_2=true
fi
done < "swiftlint+swiftUI.yml"
disabled_flag_1=false
fi

disabled_flag_2=false

if [[ $line_1 =~ $disabled_pattern ]]; then
disabled_flag_1=true
echo $line_1 >> "$temporarySwiftUILintConfigFilename"
else
while IFS= read -r line_2 || [[ -n "$line_2" ]]; do
if [[ $disabled_flag_2 == true ]]; then
if [[ $line_1 =~ ${line_2:3} ]]; then
in_rule=first
fi
fi

if [[ $line_2 =~ $disabled_pattern ]]; then
disabled_flag_2=true
fi
done < "swiftlint+swiftUI.yml"

if [[ $in_rule == false ]]; then
echo "$line_1" >> "$temporarySwiftUILintConfigFilename"
elif [[ $in_rule == first ]]; then
in_rule=true
elif [[ ${line_1:3:1} != " " ]]; then
echo "$line_1" >> "$temporarySwiftUILintConfigFilename"
in_rule=false
fi

if [[ $line_1 =~ $disabled_pattern ]]; then
disabled_flag_1=true
fi
fi

done < "$base_file"

cp "$temporarySwiftUILintConfigFilename" "$temporarySwiftLintConfigFilename"
rm "$temporarySwiftUILintConfigFilename"
return 0
}

#
# Logic
#
Expand All @@ -92,10 +160,19 @@ cd "$scriptBaseFolderPath"

# Merge the excluded paths of the commons and the project specific configuration
if [ -f "$projectDir/.project-swiftlint.yml" ]; then
merge_commons_with_project_excluded_paths
merge_commons_with_project_excluded_paths

if [[ $swiftUI == true ]]; then
add_swiftUI_disabled_rules "$temporarySwiftLintConfigFilename"
fi
else
# Copy the normal swiftlint file as tempoary one as this file is used later
cp "swiftlint.yml" "$temporarySwiftLintConfigFilename"
# Disabled certain rules listet in swiftlint+swiftUI.yml if this is a swiftUI project
if [[ $swiftUI == true ]]; then
add_swiftUI_disabled_rules "swiftlint.yml"
else
# Copy the normal swiftlint file as tempoary one as this file is used later
cp "swiftlint.yml" "$temporarySwiftLintConfigFilename"
fi
fi

if [ $isFramework = true ]; then
Expand Down
11 changes: 11 additions & 0 deletions SwiftLint/swiftlint+swiftUI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
###
# swiftlint+swiftUI.yml
# For a swiftUI projects only
#
# This list of disabled rules gets appended to the swiftlint.yml when it gets copied into the root project directory.
# You can add more "disabled_rules" here.

# rule identifiers to exclude from running
disabled_rules:
- multiple_closures_with_trailing_closure
- missing_closure_name
10 changes: 9 additions & 1 deletion setup-common-project-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ readonly noXcodeCheck="--no-xcodecheck"
readonly buildConfigurationFlag="--buildconfig"
readonly targetTypeFlag="--targettype"
readonly breakingInternalFrameworkVersioningFlag="--use-breaking-internal-framework-versioning"
readonly swiftUIFlag="--SwiftUI"

readonly scriptBaseFolderPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

Expand All @@ -33,6 +34,7 @@ callCodeClimate=true
checkXcodeVersion=true
projectDir="$(pwd)"
isDebugConfiguration=false
isSwiftUIProject=false

#
# Methods
Expand All @@ -45,6 +47,7 @@ function display_usage () {
echo -e "$noCodebeatFlag\t\t\t\t- Don't copy the default SMF codebeat configuration"
echo -e "$noCodeClimateFlag\t\t\t- Don't copy the default SMF Code Climate configuration"
echo -e "$breakingInternalFrameworkVersioningFlag\t -Use the \"BreakingInternal framework versioning system\" (only for frameworks)"
echo -e "$swiftUIFlag\t\t\t\t- Use custom SwiftLint rules for swift ui projects"
echo -e "\nUsage:\n$ $0 $noCodebeatFlag"
echo -e "or:\n$ $0 $noCodebeatFlag /Code/Project/Test"
}
Expand Down Expand Up @@ -93,6 +96,11 @@ while test $# -gt 0; do
shift
# break
;;
$swiftUIFlag)
isSwiftUIProject=true
shift
# break
;;
$noCodeClimateFlag)
callCodeClimate=false
shift
Expand Down Expand Up @@ -123,7 +131,7 @@ cd "$scriptBaseFolderPath"
#

if [ $callSwiftlint = true ]; then
./SwiftLint/copy-and-run-swiftlint-config.sh "$projectDir" $isFramework || exit 1;
./SwiftLint/copy-and-run-swiftlint-config.sh "$projectDir" $isFramework $isSwiftUIProject || exit 1;
fi

if [ $callCodebeat = true ]; then
Expand Down