@@ -18,14 +18,15 @@ readonly temporarySwiftLintConfigFilename=".$(uuidgen)-swiftlint.yml"
1818
1919projectDir=" $1 "
2020isFramework=$2
21+ swiftUI=$3
2122
2223#
2324# Check requirements
2425#
2526
2627# Check if project dir is provided. If not: Use the scripts base directory.
2728if [ -z " $1 " ]; then
28- projectDir=" $scriptBaseFolderPath "
29+ projectDir=" $scriptBaseFolderPath "
2930fi
3031
3132# Contains the local SwiftLint settings (.project-swiftlint.yml). Global so we dont read it multiple times.
@@ -35,7 +36,7 @@ declare -a local_lines
3536function read_local_settings() {
3637 let i=0
3738 while IFS=$' \n ' read -r -a line_data; do
38- local_lines[i]=" ${line_data} "
39+ local_lines[i]=" ${line_data} "
3940 (( ++ i))
4041 done < $1
4142}
@@ -64,7 +65,7 @@ function write_local_settings() {
6465 done
6566}
6667
67- function merge_commons_with_project_excluded_paths () {
68+ function merge_commons_with_project_excluded_paths() {
6869
6970 read_local_settings " $projectDir /.project-swiftlint.yml"
7071
@@ -83,6 +84,73 @@ function merge_commons_with_project_excluded_paths () {
8384 return 0
8485}
8586
87+ # Adds disabled rules to diabled section and removes custom rules for the custom rules section
88+ function add_swiftUI_disabled_rules() {
89+ disabled_pattern=" disabled_rules:"
90+ disabled_flag_1=false
91+ disabled_flag_2=false
92+ in_rule=false
93+ temporarySwiftUILintConfigFilename=" .$( uuidgen) -swiftlint-swift-ui.yml"
94+ local base_file=$1
95+
96+ touch " $temporarySwiftUILintConfigFilename "
97+
98+ while IFS= read -r line_1 || [[ -n " $line_1 " ]]; do
99+
100+ if [[ $disabled_flag_1 == true ]]; then
101+
102+ while IFS= read -r line_2 || [[ -n " $line_2 " ]]; do
103+
104+ if [[ $disabled_flag_2 == true ]]; then
105+ echo " $line_2 " >> " $temporarySwiftUILintConfigFilename "
106+ fi
107+
108+ if [[ $line_2 =~ $disabled_pattern ]]; then
109+ disabled_flag_2=true
110+ fi
111+ done < " swiftlint+swiftUI.yml"
112+ disabled_flag_1=false
113+ fi
114+
115+ disabled_flag_2=false
116+
117+ if [[ $line_1 =~ $disabled_pattern ]]; then
118+ 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
145+ fi
146+
147+ done < " $base_file "
148+
149+ cp " $temporarySwiftUILintConfigFilename " " $temporarySwiftLintConfigFilename "
150+ rm " $temporarySwiftUILintConfigFilename "
151+ return 0
152+ }
153+
86154#
87155# Logic
88156#
@@ -92,10 +160,19 @@ cd "$scriptBaseFolderPath"
92160
93161# Merge the excluded paths of the commons and the project specific configuration
94162if [ -f " $projectDir /.project-swiftlint.yml" ]; then
95- 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
96168else
97- # Copy the normal swiftlint file as tempoary one as this file is used later
98- 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
99176fi
100177
101178if [ $isFramework = true ]; then
0 commit comments