From 8094a04ab3968af9b6672704b1c79d1370d4fc08 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Sat, 11 Sep 2021 12:48:55 +0300 Subject: [PATCH 01/12] feat: lint only changed files --- xcode/build_phases/swiftlint.sh | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index 5052f54..4b58b46 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -41,7 +41,37 @@ if [ -z "${SWIFTLINT_CONFIG_PATH}" ]; then fi fi +# Xcode упадет, если будем использовать большое количество Script Input Files, +# так как просто переполнится стек - https://unix.stackexchange.com/questions/357843/setting-a-long-environment-variable-breaks-a-lot-of-commands +# Поэтому воспользуемся "скрытым" параметром Swiflint - https://github.com/realm/SwiftLint/pull/3313 +# Создадим временный файл swiftlint_files с префиксом @ и в нем уже определим список файлов +# необходимых для линтовки :) + +lint_files_path="${SRCROOT}/build_phases/swiftlint_files" + +if [ ! -z "${lint_files_path}" ]; then + > ${lint_files_path} # Если файл существует, то просто его отчистим +else + touch ${lint_files_path} # Если файла нет, то создадим его +fi + +# Проходимся по папкам, которые требуют линтовки for SOURCE_DIR in ${SOURCES_DIRS}; do - ${SWIFTLINT_EXECUTABLE} autocorrect --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} - ${SWIFTLINT_EXECUTABLE} --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} + + # Отбираем файлы, которые были изменены или созданы + source_unstaged_files=$(git diff --diff-filter=d --name-only ${SOURCE_DIR} | grep "\.swift$") + source_staged_files=$(git diff --diff-filter=d --name-only --cached ${SOURCE_DIR} | grep "\.swift$") + + if [ ! -z "${source_unstaged_files}" ]; then + echo "${source_unstaged_files}" >> ${lint_files_path} + fi + + if [ ! -z "${source_staged_files}" ]; then + echo "${source_staged_files}" >> ${lint_files_path} + fi done + +swiftlint_files_path="@${lint_files_path}" + +${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} +${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} From e725685a9e57510ff556c1529cd0370d92381a81 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Sat, 11 Sep 2021 13:01:10 +0300 Subject: [PATCH 02/12] refactor: add allow_zero_lintable_files to swiftlint --- xcode/.swiftlint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index df3de2c..55c4b9e 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -115,6 +115,8 @@ identifier_name: warning_threshold: 1 +allow_zero_lintable_files: true + custom_rules: # General From 40f6d12e15794cda7a22cb6e8d3e397e35f4c913 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Sat, 11 Sep 2021 13:21:48 +0300 Subject: [PATCH 03/12] refactor: enable --force-exclude --- xcode/build_phases/swiftlint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index 4b58b46..eac169c 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -73,5 +73,5 @@ done swiftlint_files_path="@${lint_files_path}" -${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} -${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} +${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude +${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude From 088114cb5c1a8dc29e0844a98fde8a6a96b41a10 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Sun, 12 Sep 2021 11:49:37 +0300 Subject: [PATCH 04/12] refactor: enable --use-alternative-excluding --- xcode/build_phases/swiftlint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index eac169c..da54880 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -73,5 +73,5 @@ done swiftlint_files_path="@${lint_files_path}" -${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude -${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude +${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding +${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding From 5a6dd866f712b8aad850309364238f7d32bbd66f Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 11:32:21 +0300 Subject: [PATCH 05/12] refactor: typo --- xcode/build_phases/swiftlint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index da54880..a7c8297 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -50,7 +50,7 @@ fi lint_files_path="${SRCROOT}/build_phases/swiftlint_files" if [ ! -z "${lint_files_path}" ]; then - > ${lint_files_path} # Если файл существует, то просто его отчистим + > ${lint_files_path} # Если файл существует, то просто его очистим else touch ${lint_files_path} # Если файла нет, то создадим его fi From 9e8d08801734096a2cd46a4ea12a45925167e7e3 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 18:47:37 +0300 Subject: [PATCH 06/12] refactor: add FORCE_LINT arg --- xcode/build_phases/swiftlint.sh | 75 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index a7c8297..13bf906 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -12,14 +12,19 @@ # SRCROOT - project directory. # PODS_ROOT - cocoapods installation directory (eg. ${SRCROOT}/Pods). # +# Available environment variables: +# FORCE_LINT - lint all project. +# # Optional environment variables: # SWIFTLINT_EXECUTABLE - path to swiftlint executable. # SWIFTLINT_CONFIG_PATH - path to swiftlint config. # SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. # SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked. +# FORCE_LINT - lint all project. # # Example of usage: # swiftlint.sh +# FORCE_LINT=true; swiftlint.sh # swiftlint.sh Pods/Swiftlint/swiftlint build-scripts/xcode/.swiftlint.yml # @@ -41,37 +46,45 @@ if [ -z "${SWIFTLINT_CONFIG_PATH}" ]; then fi fi -# Xcode упадет, если будем использовать большое количество Script Input Files, -# так как просто переполнится стек - https://unix.stackexchange.com/questions/357843/setting-a-long-environment-variable-breaks-a-lot-of-commands -# Поэтому воспользуемся "скрытым" параметром Swiflint - https://github.com/realm/SwiftLint/pull/3313 -# Создадим временный файл swiftlint_files с префиксом @ и в нем уже определим список файлов -# необходимых для линтовки :) +if [ ! -z "${FORCE_LINT}" ]; then + # Если задана переменная FORCE_LINT, то проверяем все файлы проекта + for SOURCE_DIR in ${SOURCES_DIRS}; do + ${SWIFTLINT_EXECUTABLE} autocorrect --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} + ${SWIFTLINT_EXECUTABLE} --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} + done +else + # Xcode упадет, если будем использовать большое количество Script Input Files, + # так как просто переполнится стек - https://unix.stackexchange.com/questions/357843/setting-a-long-environment-variable-breaks-a-lot-of-commands + # Поэтому воспользуемся "скрытым" параметром Swiflint - https://github.com/realm/SwiftLint/pull/3313 + # Создадим временный файл swiftlint_files с префиксом @ и в нем уже определим список файлов + # необходимых для линтовки :) -lint_files_path="${SRCROOT}/build_phases/swiftlint_files" + lint_files_path="${SRCROOT}/build_phases/swiftlint_files" -if [ ! -z "${lint_files_path}" ]; then - > ${lint_files_path} # Если файл существует, то просто его очистим -else - touch ${lint_files_path} # Если файла нет, то создадим его + if [ ! -z "${lint_files_path}" ]; then + > ${lint_files_path} # Если файл существует, то просто его очистим + else + touch ${lint_files_path} # Если файла нет, то создадим его + fi + + # Проходимся по папкам, которые требуют линтовки + for SOURCE_DIR in ${SOURCES_DIRS}; do + + # Отбираем файлы, которые были изменены или созданы + source_unstaged_files=$(git diff --diff-filter=d --name-only ${SOURCE_DIR} | grep "\.swift$") + source_staged_files=$(git diff --diff-filter=d --name-only --cached ${SOURCE_DIR} | grep "\.swift$") + + if [ ! -z "${source_unstaged_files}" ]; then + echo "${source_unstaged_files}" >> ${lint_files_path} + fi + + if [ ! -z "${source_staged_files}" ]; then + echo "${source_staged_files}" >> ${lint_files_path} + fi + done + + swiftlint_files_path="@${lint_files_path}" + + ${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding + ${SWIFTLINT_EXECUTABLE} --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding fi - -# Проходимся по папкам, которые требуют линтовки -for SOURCE_DIR in ${SOURCES_DIRS}; do - - # Отбираем файлы, которые были изменены или созданы - source_unstaged_files=$(git diff --diff-filter=d --name-only ${SOURCE_DIR} | grep "\.swift$") - source_staged_files=$(git diff --diff-filter=d --name-only --cached ${SOURCE_DIR} | grep "\.swift$") - - if [ ! -z "${source_unstaged_files}" ]; then - echo "${source_unstaged_files}" >> ${lint_files_path} - fi - - if [ ! -z "${source_staged_files}" ]; then - echo "${source_staged_files}" >> ${lint_files_path} - fi -done - -swiftlint_files_path="@${lint_files_path}" - -${SWIFTLINT_EXECUTABLE} autocorrect --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding -${SWIFTLINT_EXECUTABLE} lint --path ${swiftlint_files_path} --config ${SWIFTLINT_CONFIG_PATH} --force-exclude --use-alternative-excluding From db99ec0009a2155285fd490dd03c28fb64fd9357 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 18:47:44 +0300 Subject: [PATCH 07/12] refactor: add gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f1344f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# macOS + +.DS_Store \ No newline at end of file From 494bc4886b91d1c40ec4ca87ef7630cf13cf5c8b Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 19:10:35 +0300 Subject: [PATCH 08/12] refactor: add FORCE_LINT to fastlane --- xcode/commonFastfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index a3147d3..245e1cb 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -148,6 +148,7 @@ private_lane :buildArchive do |options| lane_name = options[:lane_name] configuration = options[:configuration] xcodeproj_path = options[:xcodeproj_path] + xcargs = "FORCE_LINT=true" # To enable linting on project without CodeLint target if configuration != "AppStore" # AppStore uses xcconfig choosen in Xcode set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) @@ -166,6 +167,7 @@ private_lane :buildArchive do |options| skip_package_ipa: options[:skip_package_ipa], include_symbols: options[:include_symbols] || false, include_bitcode: options[:compileBitcode] || false, + xcargs: xcargs ) end From 44d4ff9f741d6011ba368c1dca26c1d063ffe04a Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 19:19:37 +0300 Subject: [PATCH 09/12] refactor: correct fastfile --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 245e1cb..d2338f3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -148,7 +148,7 @@ private_lane :buildArchive do |options| lane_name = options[:lane_name] configuration = options[:configuration] xcodeproj_path = options[:xcodeproj_path] - xcargs = "FORCE_LINT=true" # To enable linting on project without CodeLint target + xcargs = "FORCE_LINT='true'" # To enable linting on project without CodeLint target if configuration != "AppStore" # AppStore uses xcconfig choosen in Xcode set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) From a455072e14d6627b6e767cfbba9db23530065b5c Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Mon, 13 Sep 2021 19:26:01 +0300 Subject: [PATCH 10/12] refactor: revert xcargs --- xcode/commonFastfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index d2338f3..a3147d3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -148,7 +148,6 @@ private_lane :buildArchive do |options| lane_name = options[:lane_name] configuration = options[:configuration] xcodeproj_path = options[:xcodeproj_path] - xcargs = "FORCE_LINT='true'" # To enable linting on project without CodeLint target if configuration != "AppStore" # AppStore uses xcconfig choosen in Xcode set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodeproj_path) @@ -167,7 +166,6 @@ private_lane :buildArchive do |options| skip_package_ipa: options[:skip_package_ipa], include_symbols: options[:include_symbols] || false, include_bitcode: options[:compileBitcode] || false, - xcargs: xcargs ) end From f98c1af7195eef0cb7af0ab20758cdb457c51de9 Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Tue, 14 Sep 2021 08:51:53 +0300 Subject: [PATCH 11/12] refactor: correct lint_files_path creation --- xcode/build_phases/swiftlint.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index 13bf906..accd774 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -61,11 +61,8 @@ else lint_files_path="${SRCROOT}/build_phases/swiftlint_files" - if [ ! -z "${lint_files_path}" ]; then - > ${lint_files_path} # Если файл существует, то просто его очистим - else - touch ${lint_files_path} # Если файла нет, то создадим его - fi + # Если файл существует, то просто его очистим, если нет - создадим + > ${lint_files_path} # Проходимся по папкам, которые требуют линтовки for SOURCE_DIR in ${SOURCES_DIRS}; do From 1678af01168af9a42edd7a2dccede2075617f13e Mon Sep 17 00:00:00 2001 From: Vlad Suhomlinov Date: Wed, 15 Sep 2021 19:29:21 +0300 Subject: [PATCH 12/12] docs: remove useless docs --- xcode/build_phases/swiftlint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index accd774..1437b19 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -12,9 +12,6 @@ # SRCROOT - project directory. # PODS_ROOT - cocoapods installation directory (eg. ${SRCROOT}/Pods). # -# Available environment variables: -# FORCE_LINT - lint all project. -# # Optional environment variables: # SWIFTLINT_EXECUTABLE - path to swiftlint executable. # SWIFTLINT_CONFIG_PATH - path to swiftlint config.