Skip to content

Commit 76d47d4

Browse files
author
UrsKahmann
committed
Added new file with disabled rules for swift UI projects, and logic to add these rules to the disabled rule set when the script is run and the --swiftUI flag is set
1 parent ab1011b commit 76d47d4

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

SwiftLint/copy-and-run-swiftlint-config.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ readonly temporarySwiftLintConfigFilename=".$(uuidgen)-swiftlint.yml"
1818

1919
projectDir="$1"
2020
isFramework=$2
21+
swiftUI=$3
2122

2223
#
2324
# Check requirements
@@ -83,13 +84,51 @@ function merge_commons_with_project_excluded_paths () {
8384
return 0
8485
}
8586

87+
function add_swiftUI_disabled_rules () {
88+
disabled_pattern="disabled_rules:"
89+
disabled_flag_1=false
90+
disabled_flag_2=false
91+
92+
touch "$temporarySwiftLintConfigFilename"
93+
94+
while IFS= read -r line_1 || [[ -n "$line_1" ]]; do
95+
96+
if [[ $disabled_flag_1 == true ]]; then
97+
98+
while IFS= read -r line_2 || [[ -n "$line_2" ]]; do
99+
100+
if [[ $disabled_flag_2 == true ]]; then
101+
echo "$line_2" >> "$temporarySwiftLintConfigFilename"
102+
fi
103+
104+
if [[ $line_2 =~ $disabled_pattern ]]; then
105+
disabled_flag_2=true
106+
fi
107+
done < "swiftlint+swiftUI.yml"
108+
disabled_flag_1=false
109+
fi
110+
111+
if [[ $line_1 =~ $disabled_pattern ]]; then
112+
disabled_flag_1=true
113+
fi
114+
echo "$line_1" >> "$temporarySwiftLintConfigFilename"
115+
done < "swiftlint.yml"
116+
117+
return 0
118+
}
119+
86120
#
87121
# Logic
88122
#
89123

90124
# Go the folder which contains this script
91125
cd "$scriptBaseFolderPath"
92126

127+
# Disabled certain rules listet in swiftlint+swiftUI.yml if this is a swiftUI project
128+
if [ $swiftUI = true]; then
129+
add_swiftUI_disabled_rules
130+
fi
131+
93132
# Merge the excluded paths of the commons and the project specific configuration
94133
if [ -f "$projectDir/.project-swiftlint.yml" ]; then
95134
merge_commons_with_project_excluded_paths

SwiftLint/swiftlint+swiftUI.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
###
2+
# swiftlint+swiftUI.yml
3+
# For a swiftUI projects only
4+
#
5+
# This list of disabled rules gets appended to the swiftlint.yml when it gets copied into the root project directory.
6+
# You can add more "disabled_rules" here.
7+
8+
# rule identifiers to exclude from running
9+
disabled_rules:
10+
- multiple_closures_with_trailing_closure
11+
- missing_closure_name
12+
- missing_closure_datatype

0 commit comments

Comments
 (0)