@@ -26,7 +26,7 @@ swiftUI=$3
2626
2727# Check if project dir is provided. If not: Use the scripts base directory.
2828if [ -z " $1 " ]; then
29- projectDir=" $scriptBaseFolderPath "
29+ projectDir=" $scriptBaseFolderPath "
3030fi
3131
3232# Contains the local SwiftLint settings (.project-swiftlint.yml). Global so we dont read it multiple times.
@@ -36,7 +36,7 @@ declare -a local_lines
3636function read_local_settings() {
3737 let i=0
3838 while IFS=$' \n ' read -r -a line_data; do
39- local_lines[i]=" ${line_data} "
39+ local_lines[i]=" ${line_data} "
4040 (( ++ i))
4141 done < $1
4242}
@@ -65,7 +65,7 @@ function write_local_settings() {
6565 done
6666}
6767
68- function merge_commons_with_project_excluded_paths () {
68+ function merge_commons_with_project_excluded_paths() {
6969
7070 read_local_settings " $projectDir /.project-swiftlint.yml"
7171
@@ -84,12 +84,16 @@ function merge_commons_with_project_excluded_paths () {
8484 return 0
8585}
8686
87- function add_swiftUI_disabled_rules () {
87+ # Adds disabled rules to diabled section and removes custom rules for the custom rules section
88+ function add_swiftUI_disabled_rules() {
8889 disabled_pattern=" disabled_rules:"
8990 disabled_flag_1=false
9091 disabled_flag_2=false
92+ in_rule=false
93+ temporarySwiftUILintConfigFilename=" .$( uuidgen) -swiftlint-swift-ui.yml"
94+ local base_file=$1
9195
92- touch " $temporarySwiftLintConfigFilename "
96+ touch " $temporarySwiftUILintConfigFilename "
9397
9498 while IFS= read -r line_1 || [[ -n " $line_1 " ]]; do
9599
@@ -98,7 +102,7 @@ function add_swiftUI_disabled_rules () {
98102 while IFS= read -r line_2 || [[ -n " $line_2 " ]]; do
99103
100104 if [[ $disabled_flag_2 == true ]]; then
101- echo " $line_2 " >> " $temporarySwiftLintConfigFilename "
105+ echo " $line_2 " >> " $temporarySwiftUILintConfigFilename "
102106 fi
103107
104108 if [[ $line_2 =~ $disabled_pattern ]]; then
@@ -108,12 +112,42 @@ function add_swiftUI_disabled_rules () {
108112 disabled_flag_1=false
109113 fi
110114
115+ disabled_flag_2=false
116+
111117 if [[ $line_1 =~ $disabled_pattern ]]; then
112118 disabled_flag_1=true
119+ echo $line_1 >> " $temporarySwiftUILintConfigFilename "
120+ else
121+ while IFS= read -r line_2 || [[ -n " $line_2 " ]]; do
122+ if [[ $disabled_flag_2 == true ]]; then
123+ if [[ $line_1 =~ ${line_2: 3} ]]; then
124+ in_rule=first
125+ fi
126+ fi
127+
128+ if [[ $line_2 =~ $disabled_pattern ]]; then
129+ disabled_flag_2=true
130+ fi
131+ done < " swiftlint+swiftUI.yml"
132+
133+ if [[ $in_rule == false ]]; then
134+ echo " $line_1 " >> " $temporarySwiftUILintConfigFilename "
135+ elif [[ $in_rule == first ]]; then
136+ in_rule=true
137+ elif [[ ${line_1: 3: 1} != " " ]]; then
138+ echo " $line_1 " >> " $temporarySwiftUILintConfigFilename "
139+ in_rule=false
140+ fi
141+
142+ if [[ $line_1 =~ $disabled_pattern ]]; then
143+ disabled_flag_1=true
144+ fi
113145 fi
114- echo " $line_1 " >> " $temporarySwiftLintConfigFilename "
115- done < " swiftlint.yml"
116146
147+ done < " $base_file "
148+
149+ cp " $temporarySwiftUILintConfigFilename " " $temporarySwiftLintConfigFilename "
150+ rm " $temporarySwiftUILintConfigFilename "
117151 return 0
118152}
119153
@@ -124,20 +158,24 @@ function add_swiftUI_disabled_rules () {
124158# Go the folder which contains this script
125159cd " $scriptBaseFolderPath "
126160
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-
132161# Merge the excluded paths of the commons and the project specific configuration
133162if [ -f " $projectDir /.project-swiftlint.yml" ]; then
134- merge_commons_with_project_excluded_paths
163+ merge_commons_with_project_excluded_paths
164+
165+ if [[ $swiftUI == true ]]; then
166+ add_swiftUI_disabled_rules " $temporarySwiftLintConfigFilename "
167+ fi
135168else
136- # Copy the normal swiftlint file as tempoary one as this file is used later
137- cp " swiftlint.yml" " $temporarySwiftLintConfigFilename "
169+ # Disabled certain rules listet in swiftlint+swiftUI.yml if this is a swiftUI project
170+ if [[ $swiftUI == true ]]; then
171+ add_swiftUI_disabled_rules " swiftlint.yml"
172+ else
173+ # Copy the normal swiftlint file as tempoary one as this file is used later
174+ cp " swiftlint.yml" " $temporarySwiftLintConfigFilename "
175+ fi
138176fi
139177
140- if [ $isFramework = true ]; then
178+ if [[ $isFramework == true ] ]; then
141179 # Merge with framework config
142180 temporaryMergedSwiftLintConfigFilename=" $temporarySwiftLintConfigFilename .merged"
143181 cat " $temporarySwiftLintConfigFilename " " swiftlint+frameworks.yml" > " $temporaryMergedSwiftLintConfigFilename "
0 commit comments