From 4ebcbadea299f5cd5bcc627684e9a1e02bbc27da Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Mon, 15 Jun 2020 14:38:44 +0300 Subject: [PATCH 01/13] multiple swiftlint rules script --- xcode/build_phases/multiple_swiftlint.sh | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 xcode/build_phases/multiple_swiftlint.sh diff --git a/xcode/build_phases/multiple_swiftlint.sh b/xcode/build_phases/multiple_swiftlint.sh new file mode 100644 index 0000000..2fe8633 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +sourceDirectiry=${1:-${TARGET_NAME}}/.. # first argument or TARGET_NAME +sourceTimestamp=$(date -j -f "%Y:%m:%d %H:%M:%S" '2020:05:20 00:00:00' +%s) +touchInstinctYml="$sourceDirectiry/build-scripts/xcode/.swiftlint.yml" +swiftlint=${PODS_ROOT}/SwiftLint/swiftlint +oldYml="$sourceDirectiry/.swiftlint.yml" +excludeDirectories=("vendor" "Tests" "Mock" "Pods" "build-scripts" "nmir-loyaltyTests" "common" ".gem" "node_modules" "Framework" "fastlane") +availableExtensions=(".swift") + +function runSwiftlint() { + config="" + if [[ $2 = "true" ]]; then + config=$touchInstinctYml + else + config=$oldYml + fi + + $swiftlint autocorrect --path $1 --config $config && $swiftlint --path $1 --config $config +} + +function compareTimestamp() { + currentFileTimestamp=$(stat -f%B "$1") + diff=$(($sourceTimestamp - $currentFileTimestamp)) + if [[ $diff -lt 0 ]]; then + runSwiftlint "$filePath" true + else + runSwiftlint "$filePath" false + fi +} + +function isExcludedDirectory() { + for excludeFile in ${excludeDirectories[*]} ; do + if [[ $1 == *$excludeFile* ]]; then + return 1 + fi + done + + return 0 +} + +function isValidExtensions() { + for extension in ${availableExtensions[*]} ; do + if [[ $1 == *$extension* ]]; then + return 1 + fi + done + + return 0 +} + +function findFiles() { + for filePath in "$1"/* ; do + if [[ -d "$filePath" ]]; then + isExcludedDirectory "$filePath" + isExcludedDirectory=$? + if [[ ($isExcludedDirectory == 0) ]]; then + findFiles "$filePath" + fi + else + isValidExtensions "$filePath" + isValidExtensions=$? + if [[ $isValidExtensions == 1 ]]; then + compareTimestamp "$filePath" + fi + fi + done +} + +findFiles "$sourceDirectiry" From 2e64ab92d47bb0e85fbe6652f50914bd04284b1a Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Mon, 29 Jun 2020 16:55:56 +0300 Subject: [PATCH 02/13] multiple swiftlint rules script --- xcode/build_phases/swiftlint.rb | 392 ++++++++++++++++++++++++++++++++ 1 file changed, 392 insertions(+) create mode 100644 xcode/build_phases/swiftlint.rb diff --git a/xcode/build_phases/swiftlint.rb b/xcode/build_phases/swiftlint.rb new file mode 100644 index 0000000..55ea565 --- /dev/null +++ b/xcode/build_phases/swiftlint.rb @@ -0,0 +1,392 @@ +require 'yaml' +require 'optparse' +require 'ostruct' +require 'date' +require 'fileutils' + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +class String + def with_wrapped_whitespace + self.gsub(/\s+/, '\ ') + end + + def filter_allowed_symbol_into_path + self.gsub!(/[^0-9A-Za-z \-+.\/]/, '') + end + + def true? + self.to_s.downcase == "true" + end + + def add_back_to_path(count) + string = self + count.to_i.times { |i| + string = '../' + string + } + return string + end + + def nilOrEmpty? + self.nil? or self.empty? + end +end + +class Array + def nilOrEmpty? + self.nil? or self.empty? + end +end + +class YamlManager + def initialize(swiftlint_yaml_path) + @swiftlint_yaml_path = swiftlint_yaml_path + @configuration ||= YAML.load(File.read(@swiftlint_yaml_path)) + end + + def get_configuration(key) + @configuration[key] + end + + def update(key, new_configuration_values) + @configuration[key] = new_configuration_values + save_settings(@configuration) + end + + private + + def save_settings(settings) + File.write(@swiftlint_yaml_path, settings.to_yaml) + end +end + +class SettingOption + def initialize + @options = OpenStruct.new + OptionParser.new do |opt| + opt.on('-s', '--source_directory STRING', 'The directory of start') { |option| @options.source_directory = option } + opt.on('-p', '--pods_directory STRING', 'The directory of pods') { |option| @options.pods_directory = option } + opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } + opt.on('-u', '--use_multiple BOOL', 'the flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } + opt.on('-d', '--source_date DATE', 'The date of grouping files according new and old swiftlint rules') { |option| @options.source_date = option } + opt.on('-y', '--touchin_swiftlint_yaml_path STRING', 'The path to the touchin swiftlint yaml relative to the source directory') { |option| @options.touchin_swiftlint_yaml_path = option } + opt.on('-g', '--depth_git_count Int', 'The depth between the git directory and sources directory') { |option| @options.depth_git_count = option } + end.parse! + + if @options.check_mode.to_s.nilOrEmpty? + @options.check_mode = 'fully' + end + + if @options.use_multiple.to_s.nilOrEmpty? + @options.use_multiple = 'false' + end + + if @options.depth_git_count.to_s.nilOrEmpty? + @options.depth_git_count = 0 + end + + if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? + @options.touchin_swiftlint_yaml_path = '/build-scripts/xcode/.swiftlint.yml' + end + end + + def source_directory + @options.source_directory + end + + def source_date + @options.source_date + end + + def pods_directory + @options.pods_directory + end + + def check_mode + @options.check_mode + end + + def use_multiple + @options.use_multiple + end + + def depth_git_count + @options.depth_git_count + end + + def touchin_swiftlint_yaml_path + @options.touchin_swiftlint_yaml_path + end +end + +class CommandUtils + def self.make_command(command) + command = command.to_s + return `#{command}` + end +end + +class GitСaretaker < CommandUtils + def self.get_modified_files + non_indexed_files = get_files_from('git diff --name-only | sed s/.*/"&,"/ ') + indexed_files = get_files_from('git diff --cached --name-only | sed s/.*/"&,"/ ') + + modified_files = non_indexed_files + indexed_files + unique_modified_files = modified_files.uniq + + unique_modified_swift_files = [] + if not unique_modified_files.nilOrEmpty? + unique_modified_swift_files = unique_modified_files.select { |file_path| + file_path.to_s.filter_allowed_symbol_into_path + file_path.to_s.include? '.swift' + } + end + + return unique_modified_swift_files + end + + def self.get_creation_date(file_path) + git_command = 'git log --follow --format=%cD --reverse -- ' + file_path + ' | head -1' + return make_command(git_command) + end + + private + + def self.get_files_from(command) + files_as_string = make_command(command) + return files_as_string.split(',') + end +end + +class SwiftFileManager + def initialize(excluded_files, source_date) + if not source_date.nilOrEmpty? + @source_date = Date.parse(source_date) + end + @excluded_files = excluded_files + @new_files = [] + @old_files = [] + end + + def old_files + @old_files + end + + def new_files + @new_files + end + + def find_list_file_paths(start_folder) + swift_files = File.join('**', '*.swift') + Dir.glob(swift_files, base: start_folder) { |file_path| + if not is_excluded_file(file_path) + compare_timestamp(file_path) + end + } + end + + def find_list_file_paths_from(files_path) + files_path.each { |file_path| + if not is_excluded_file(file_path) + compare_timestamp(file_path) + end + } + end + + def is_excluded_file(file_path) + @excluded_files.each do |exclude_file_path| + if file_path.include? exclude_file_path + return true + end + end + return false + end + + private + + def compare_timestamp(file_path) + wrapped_whitespace_file_path = file_path.with_wrapped_whitespace + creation_date_string = GitСaretaker.get_creation_date(wrapped_whitespace_file_path) + puts file_path + if creation_date_string.nilOrEmpty? + @old_files.push(file_path) + puts 'Not found the creation date' + else + creation_date = Date.parse(creation_date_string) + puts creation_date + if @source_date < creation_date + @new_files.push(file_path) + else + @old_files.push(file_path) + end + end + end +end + +class StrategyMaker + def initialize(source_directory, pods_directory, touchin_swiftlint_yaml_path) + @source_directory = source_directory + @pods_directory = pods_directory + @swiftlint = pods_directory + '/SwiftLint/swiftlint' + + @touchin_swiftlint_yaml_path = source_directory + touchin_swiftlint_yaml_path + @old_swiftlint_yaml_path = source_directory + '/.swiftlint.yml' + + @temporary_swiftlint_folder_name = source_directory + '/temporary_swiftlint' + @touchin_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.touchin_swiftlint.yml' + @old_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.old_swiftlint.yml' + + @swiftlint_autocorrect_command = @swiftlint + ' autocorrect --path ' + @source_directory + ' --config ' + @swiftlint_lint_command = @swiftlint + ' --path ' + @source_directory + ' --config ' + end + + def make_fully_multiple_strategy(source_date) + create_copy_temporary_files + + touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) + old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + + touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') + old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') + common_exclude_files = touchin_excluded_files + old_excluded_files + unique_exclude_files = common_exclude_files.uniq + + swift_files = SwiftFileManager.new(unique_exclude_files, source_date) + swift_files.find_list_file_paths(@source_directory) + + total_touchin_excluded_files = unique_exclude_files + swift_files.old_files + total_old_excluded_files = unique_exclude_files + swift_files.new_files + + touchin_swiftlint_yaml_manager.update('excluded', total_touchin_excluded_files) + old_swiftlint_yaml_manager.update('excluded', total_old_excluded_files) + + make_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) + end + + def make_simplified_multiple_strategy(source_date, depth_git_count) + included_files = GitСaretaker.get_modified_files + + if included_files.nilOrEmpty? + puts 'Git did not found swift files to check' + return + end + + create_copy_temporary_files + + touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) + old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + + touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') + old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') + common_exclude_files = touchin_excluded_files + old_excluded_files + unique_exclude_files = common_exclude_files.uniq + + included_files = included_files.map { |file_path| file_path.add_back_to_path(depth_git_count) } + + swift_file_manager = SwiftFileManager.new(unique_exclude_files, source_date) + swift_file_manager.find_list_file_paths_from(included_files) + + total_touchin_included_files = swift_file_manager.new_files + total_old_included_files = swift_file_manager.old_files + + touchin_swiftlint_yaml_manager.update('excluded', []) + old_swiftlint_yaml_manager.update('excluded', []) + + touchin_swiftlint_yaml_manager.update('included', total_touchin_included_files) + old_swiftlint_yaml_manager.update('included', total_old_included_files) + + is_exist_total_touchin_included_files = (not total_touchin_included_files.nilOrEmpty?) + is_exist_total_old_included_files = (not total_old_included_files.nilOrEmpty?) + + if is_exist_total_touchin_included_files and is_exist_total_old_included_files + make_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) + elsif is_exist_total_touchin_included_files and not is_exist_total_old_included_files + make_single_strategy(@touchin_swiftlint_yaml_temporary_path) + elsif not is_exist_total_touchin_included_files and is_exist_total_old_included_files + make_single_strategy(@old_swiftlint_yaml_temporary_path) + else + puts 'Git did not found swift files to check' + end + end + + def make_fully_single_strategy + make_single_strategy(@touchin_swiftlint_yaml_path) + end + + def make_simplified_single_strategy(depth_git_count) + included_files = GitСaretaker.get_modified_files + + if included_files.nilOrEmpty? + puts 'Git did not found swift files to check' + return + end + + create_copy_temporary_touchin_files + + touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) + touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') + swift_files = SwiftFileManager.new(touchin_excluded_files, '') + + included_files = included_files.select { |file_name| not swift_files.is_excluded_file(file_name) } + included_files = included_files.map { |file_path| file_path.add_back_to_path(depth_git_count) } + + touchin_swiftlint_yaml_manager.update('excluded', []) + touchin_swiftlint_yaml_manager.update('included', included_files) + + if not included_files.nilOrEmpty? + make_single_strategy(@touchin_swiftlint_yaml_temporary_path) + else + puts 'Git found the swift files to check, but they are excluded in yaml' + end + end + + private + + def make_single_strategy(swiftlint_yaml_path) + result_swiftlint_command = get_swiftlint_command(swiftlint_yaml_path) + puts result_swiftlint_command + make_bash_command(result_swiftlint_command) + end + + def make_multiple_strategy(touchin_swiftlint_yaml_temporary_path, old_swiftlint_yaml_temporary_path) + touchin_swiftlint_command = get_swiftlint_command(touchin_swiftlint_yaml_temporary_path) + old_swiftlint_command = get_swiftlint_command(old_swiftlint_yaml_temporary_path) + result_swiftlint_command = touchin_swiftlint_command + ' && ' + old_swiftlint_command + puts result_swiftlint_command + make_bash_command(result_swiftlint_command) + end + + def get_swiftlint_command(swiftlint_yaml_path) + autocorrect_command = @swiftlint_autocorrect_command + swiftlint_yaml_path + lint_command = @swiftlint_lint_command + swiftlint_yaml_path + return autocorrect_command + ' && ' + lint_command + end + + def make_bash_command(bash_command) + exit (exec bash_command) + end + + def create_copy_temporary_files + create_copy_temporary_touchin_files + FileUtils.cp @old_swiftlint_yaml_path, @old_swiftlint_yaml_temporary_path + end + + def create_copy_temporary_touchin_files + Dir.mkdir(@temporary_swiftlint_folder_name) unless Dir.exist?(@temporary_swiftlint_folder_name) + FileUtils.cp @touchin_swiftlint_yaml_path, @touchin_swiftlint_yaml_temporary_path + end +end + +setting = SettingOption.new +maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) + +if setting.check_mode.eql? 'fully' and setting.use_multiple.true? + maker.make_fully_multiple_strategy(setting.source_date) +elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? + maker.make_fully_single_strategy +elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? + maker.make_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) +elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? + maker.make_simplified_single_strategy(setting.depth_git_count) +end From 6b299828f04ef03b8535f63c2c523d82f0450c4b Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Tue, 30 Jun 2020 16:22:47 +0300 Subject: [PATCH 03/13] remove multiple_swiftlint.sh --- xcode/build_phases/multiple_swiftlint.sh | 70 ------------------------ 1 file changed, 70 deletions(-) delete mode 100644 xcode/build_phases/multiple_swiftlint.sh diff --git a/xcode/build_phases/multiple_swiftlint.sh b/xcode/build_phases/multiple_swiftlint.sh deleted file mode 100644 index 2fe8633..0000000 --- a/xcode/build_phases/multiple_swiftlint.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash - -sourceDirectiry=${1:-${TARGET_NAME}}/.. # first argument or TARGET_NAME -sourceTimestamp=$(date -j -f "%Y:%m:%d %H:%M:%S" '2020:05:20 00:00:00' +%s) -touchInstinctYml="$sourceDirectiry/build-scripts/xcode/.swiftlint.yml" -swiftlint=${PODS_ROOT}/SwiftLint/swiftlint -oldYml="$sourceDirectiry/.swiftlint.yml" -excludeDirectories=("vendor" "Tests" "Mock" "Pods" "build-scripts" "nmir-loyaltyTests" "common" ".gem" "node_modules" "Framework" "fastlane") -availableExtensions=(".swift") - -function runSwiftlint() { - config="" - if [[ $2 = "true" ]]; then - config=$touchInstinctYml - else - config=$oldYml - fi - - $swiftlint autocorrect --path $1 --config $config && $swiftlint --path $1 --config $config -} - -function compareTimestamp() { - currentFileTimestamp=$(stat -f%B "$1") - diff=$(($sourceTimestamp - $currentFileTimestamp)) - if [[ $diff -lt 0 ]]; then - runSwiftlint "$filePath" true - else - runSwiftlint "$filePath" false - fi -} - -function isExcludedDirectory() { - for excludeFile in ${excludeDirectories[*]} ; do - if [[ $1 == *$excludeFile* ]]; then - return 1 - fi - done - - return 0 -} - -function isValidExtensions() { - for extension in ${availableExtensions[*]} ; do - if [[ $1 == *$extension* ]]; then - return 1 - fi - done - - return 0 -} - -function findFiles() { - for filePath in "$1"/* ; do - if [[ -d "$filePath" ]]; then - isExcludedDirectory "$filePath" - isExcludedDirectory=$? - if [[ ($isExcludedDirectory == 0) ]]; then - findFiles "$filePath" - fi - else - isValidExtensions "$filePath" - isValidExtensions=$? - if [[ $isValidExtensions == 1 ]]; then - compareTimestamp "$filePath" - fi - fi - done -} - -findFiles "$sourceDirectiry" From 77d5642b7aea83bebc182d958d0a2f788beff681 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Tue, 30 Jun 2020 16:48:38 +0300 Subject: [PATCH 04/13] fix indent --- xcode/build_phases/swiftlint.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcode/build_phases/swiftlint.rb b/xcode/build_phases/swiftlint.rb index 55ea565..3fd404a 100644 --- a/xcode/build_phases/swiftlint.rb +++ b/xcode/build_phases/swiftlint.rb @@ -46,18 +46,18 @@ class YamlManager end def get_configuration(key) - @configuration[key] + @configuration[key] end def update(key, new_configuration_values) - @configuration[key] = new_configuration_values - save_settings(@configuration) + @configuration[key] = new_configuration_values + save_settings(@configuration) end private def save_settings(settings) - File.write(@swiftlint_yaml_path, settings.to_yaml) + File.write(@swiftlint_yaml_path, settings.to_yaml) end end From 635fa8dc98ed370331fd3c5c948f5b9b50d2584d Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Tue, 30 Jun 2020 16:55:06 +0300 Subject: [PATCH 05/13] added style guide and fixed naming --- xcode/build_phases/swiftlint.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xcode/build_phases/swiftlint.rb b/xcode/build_phases/swiftlint.rb index 3fd404a..c954d4a 100644 --- a/xcode/build_phases/swiftlint.rb +++ b/xcode/build_phases/swiftlint.rb @@ -1,3 +1,4 @@ +#https://github.com/TouchInstinct/Styleguide/blob/multiple_swiftlint/IOS/Guides/BuildScripts/Multiple_Swiftlint_Guide.md require 'yaml' require 'optparse' require 'ostruct' @@ -65,11 +66,11 @@ class SettingOption def initialize @options = OpenStruct.new OptionParser.new do |opt| - opt.on('-s', '--source_directory STRING', 'The directory of start') { |option| @options.source_directory = option } + opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } opt.on('-p', '--pods_directory STRING', 'The directory of pods') { |option| @options.pods_directory = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } - opt.on('-u', '--use_multiple BOOL', 'the flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } - opt.on('-d', '--source_date DATE', 'The date of grouping files according new and old swiftlint rules') { |option| @options.source_date = option } + opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } + opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } opt.on('-y', '--touchin_swiftlint_yaml_path STRING', 'The path to the touchin swiftlint yaml relative to the source directory') { |option| @options.touchin_swiftlint_yaml_path = option } opt.on('-g', '--depth_git_count Int', 'The depth between the git directory and sources directory') { |option| @options.depth_git_count = option } end.parse! From ce8f6746bf65c169fc52282dcceadc2e1fe82f12 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Tue, 28 Jul 2020 21:02:37 +0300 Subject: [PATCH 06/13] some refactoring, and remove copy paste --- xcode/build_phases/swiftlint.rb | 62 +++++++++++++++++---------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/xcode/build_phases/swiftlint.rb b/xcode/build_phases/swiftlint.rb index c954d4a..a940bcf 100644 --- a/xcode/build_phases/swiftlint.rb +++ b/xcode/build_phases/swiftlint.rb @@ -243,24 +243,18 @@ class StrategyMaker end def make_fully_multiple_strategy(source_date) - create_copy_temporary_files + create_yaml_managers_and_copy_temporary_files - touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) - old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) - touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') - old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') - common_exclude_files = touchin_excluded_files + old_excluded_files - unique_exclude_files = common_exclude_files.uniq - - swift_files = SwiftFileManager.new(unique_exclude_files, source_date) + swift_files = SwiftFileManager.new(exclude_files, source_date) swift_files.find_list_file_paths(@source_directory) - total_touchin_excluded_files = unique_exclude_files + swift_files.old_files - total_old_excluded_files = unique_exclude_files + swift_files.new_files + total_touchin_excluded_files = exclude_files + swift_files.old_files + total_old_excluded_files = exclude_files + swift_files.new_files - touchin_swiftlint_yaml_manager.update('excluded', total_touchin_excluded_files) - old_swiftlint_yaml_manager.update('excluded', total_old_excluded_files) + @touchin_swiftlint_yaml_manager.update('excluded', total_touchin_excluded_files) + @old_swiftlint_yaml_manager.update('excluded', total_old_excluded_files) make_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) end @@ -273,29 +267,22 @@ class StrategyMaker return end - create_copy_temporary_files - - touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) - old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + create_yaml_managers_and_copy_temporary_files - touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') - old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') - common_exclude_files = touchin_excluded_files + old_excluded_files - unique_exclude_files = common_exclude_files.uniq - + exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) included_files = included_files.map { |file_path| file_path.add_back_to_path(depth_git_count) } - swift_file_manager = SwiftFileManager.new(unique_exclude_files, source_date) + swift_file_manager = SwiftFileManager.new(exclude_files, source_date) swift_file_manager.find_list_file_paths_from(included_files) total_touchin_included_files = swift_file_manager.new_files total_old_included_files = swift_file_manager.old_files - touchin_swiftlint_yaml_manager.update('excluded', []) - old_swiftlint_yaml_manager.update('excluded', []) + @touchin_swiftlint_yaml_manager.update('excluded', []) + @old_swiftlint_yaml_manager.update('excluded', []) - touchin_swiftlint_yaml_manager.update('included', total_touchin_included_files) - old_swiftlint_yaml_manager.update('included', total_old_included_files) + @touchin_swiftlint_yaml_manager.update('included', total_touchin_included_files) + @old_swiftlint_yaml_manager.update('included', total_old_included_files) is_exist_total_touchin_included_files = (not total_touchin_included_files.nilOrEmpty?) is_exist_total_old_included_files = (not total_old_included_files.nilOrEmpty?) @@ -347,7 +334,7 @@ class StrategyMaker def make_single_strategy(swiftlint_yaml_path) result_swiftlint_command = get_swiftlint_command(swiftlint_yaml_path) puts result_swiftlint_command - make_bash_command(result_swiftlint_command) + run_bash_command(result_swiftlint_command) end def make_multiple_strategy(touchin_swiftlint_yaml_temporary_path, old_swiftlint_yaml_temporary_path) @@ -355,7 +342,7 @@ class StrategyMaker old_swiftlint_command = get_swiftlint_command(old_swiftlint_yaml_temporary_path) result_swiftlint_command = touchin_swiftlint_command + ' && ' + old_swiftlint_command puts result_swiftlint_command - make_bash_command(result_swiftlint_command) + run_bash_command(result_swiftlint_command) end def get_swiftlint_command(swiftlint_yaml_path) @@ -364,7 +351,7 @@ class StrategyMaker return autocorrect_command + ' && ' + lint_command end - def make_bash_command(bash_command) + def run_bash_command(bash_command) exit (exec bash_command) end @@ -377,6 +364,21 @@ class StrategyMaker Dir.mkdir(@temporary_swiftlint_folder_name) unless Dir.exist?(@temporary_swiftlint_folder_name) FileUtils.cp @touchin_swiftlint_yaml_path, @touchin_swiftlint_yaml_temporary_path end + + def create_yaml_managers_and_copy_temporary_files + create_copy_temporary_files + + @touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) + @old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + end + + def unique_exclude_files(touchin_swiftlint_yaml_manager, old_swiftlint_yaml_manager) + touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') + old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') + common_exclude_files = touchin_excluded_files + old_excluded_files + unique_exclude_files = common_exclude_files.uniq + return unique_exclude_files + end end setting = SettingOption.new From 2285e1d18ef98bb61adfd3dac9d211c4ade8a3e4 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Wed, 29 Jul 2020 11:41:36 +0300 Subject: [PATCH 07/13] split swiftlint.rb file to some files --- .../multiple_swiftlint/array_extension.rb | 5 + .../multiple_swiftlint/command_utils.rb | 6 + .../multiple_swiftlint/git_caretaker.rb | 35 +++ .../multiple_swiftlint/setting_option.rb | 63 +++++ .../strategy_maker.rb} | 258 +----------------- .../multiple_swiftlint/string_extension.rb | 25 ++ .../multiple_swiftlint/swift_file_manager.rb | 69 +++++ .../multiple_swiftlint/swiftlint.rb | 19 ++ .../multiple_swiftlint/yaml_manager.rb | 24 ++ 9 files changed, 259 insertions(+), 245 deletions(-) create mode 100644 xcode/build_phases/multiple_swiftlint/array_extension.rb create mode 100644 xcode/build_phases/multiple_swiftlint/command_utils.rb create mode 100644 xcode/build_phases/multiple_swiftlint/git_caretaker.rb create mode 100644 xcode/build_phases/multiple_swiftlint/setting_option.rb rename xcode/build_phases/{swiftlint.rb => multiple_swiftlint/strategy_maker.rb} (50%) create mode 100644 xcode/build_phases/multiple_swiftlint/string_extension.rb create mode 100644 xcode/build_phases/multiple_swiftlint/swift_file_manager.rb create mode 100644 xcode/build_phases/multiple_swiftlint/swiftlint.rb create mode 100644 xcode/build_phases/multiple_swiftlint/yaml_manager.rb diff --git a/xcode/build_phases/multiple_swiftlint/array_extension.rb b/xcode/build_phases/multiple_swiftlint/array_extension.rb new file mode 100644 index 0000000..e5bebf6 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/array_extension.rb @@ -0,0 +1,5 @@ +class Array + def nilOrEmpty? + self.nil? or self.empty? + end +end diff --git a/xcode/build_phases/multiple_swiftlint/command_utils.rb b/xcode/build_phases/multiple_swiftlint/command_utils.rb new file mode 100644 index 0000000..cf12d07 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/command_utils.rb @@ -0,0 +1,6 @@ +class CommandUtils + def self.make_command(command) + command = command.to_s + return `#{command}` + end +end \ No newline at end of file diff --git a/xcode/build_phases/multiple_swiftlint/git_caretaker.rb b/xcode/build_phases/multiple_swiftlint/git_caretaker.rb new file mode 100644 index 0000000..323464a --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/git_caretaker.rb @@ -0,0 +1,35 @@ +require_relative 'array_extension.rb' +require_relative 'command_utils.rb' +require_relative 'string_extension.rb' + +class GitСaretaker < CommandUtils + def self.get_modified_files + non_indexed_files = get_files_from('git diff --name-only | sed s/.*/"&,"/ ') + indexed_files = get_files_from('git diff --cached --name-only | sed s/.*/"&,"/ ') + + modified_files = non_indexed_files + indexed_files + unique_modified_files = modified_files.uniq + + unique_modified_swift_files = [] + if not unique_modified_files.nilOrEmpty? + unique_modified_swift_files = unique_modified_files.select { |file_path| + file_path.to_s.filter_allowed_symbol_into_path + file_path.to_s.include? '.swift' + } + end + + return unique_modified_swift_files + end + + def self.get_creation_date(file_path) + git_command = 'git log --follow --format=%cD --reverse -- ' + file_path + ' | head -1' + return make_command(git_command) + end + + private + + def self.get_files_from(command) + files_as_string = make_command(command) + return files_as_string.split(',') + end +end \ No newline at end of file diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb new file mode 100644 index 0000000..338d56e --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -0,0 +1,63 @@ +require 'optparse' +require 'ostruct' + +require_relative 'array_extension.rb' + +class SettingOption + def initialize + @options = OpenStruct.new + OptionParser.new do |opt| + opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } + opt.on('-p', '--pods_directory STRING', 'The directory of pods') { |option| @options.pods_directory = option } + opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } + opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } + opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } + opt.on('-y', '--touchin_swiftlint_yaml_path STRING', 'The path to the touchin swiftlint yaml relative to the source directory') { |option| @options.touchin_swiftlint_yaml_path = option } + opt.on('-g', '--depth_git_count Int', 'The depth between the git directory and sources directory') { |option| @options.depth_git_count = option } + end.parse! + + if @options.check_mode.to_s.nilOrEmpty? + @options.check_mode = 'fully' + end + + if @options.use_multiple.to_s.nilOrEmpty? + @options.use_multiple = 'false' + end + + if @options.depth_git_count.to_s.nilOrEmpty? + @options.depth_git_count = 0 + end + + if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? + @options.touchin_swiftlint_yaml_path = '/build-scripts/xcode/.swiftlint.yml' + end + end + + def source_directory + @options.source_directory + end + + def source_date + @options.source_date + end + + def pods_directory + @options.pods_directory + end + + def check_mode + @options.check_mode + end + + def use_multiple + @options.use_multiple + end + + def depth_git_count + @options.depth_git_count + end + + def touchin_swiftlint_yaml_path + @options.touchin_swiftlint_yaml_path + end +end \ No newline at end of file diff --git a/xcode/build_phases/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb similarity index 50% rename from xcode/build_phases/swiftlint.rb rename to xcode/build_phases/multiple_swiftlint/strategy_maker.rb index a940bcf..74419b7 100644 --- a/xcode/build_phases/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -1,229 +1,10 @@ -#https://github.com/TouchInstinct/Styleguide/blob/multiple_swiftlint/IOS/Guides/BuildScripts/Multiple_Swiftlint_Guide.md -require 'yaml' -require 'optparse' -require 'ostruct' -require 'date' require 'fileutils' -Encoding.default_external = Encoding::UTF_8 -Encoding.default_internal = Encoding::UTF_8 - -class String - def with_wrapped_whitespace - self.gsub(/\s+/, '\ ') - end - - def filter_allowed_symbol_into_path - self.gsub!(/[^0-9A-Za-z \-+.\/]/, '') - end - - def true? - self.to_s.downcase == "true" - end - - def add_back_to_path(count) - string = self - count.to_i.times { |i| - string = '../' + string - } - return string - end - - def nilOrEmpty? - self.nil? or self.empty? - end -end - -class Array - def nilOrEmpty? - self.nil? or self.empty? - end -end - -class YamlManager - def initialize(swiftlint_yaml_path) - @swiftlint_yaml_path = swiftlint_yaml_path - @configuration ||= YAML.load(File.read(@swiftlint_yaml_path)) - end - - def get_configuration(key) - @configuration[key] - end - - def update(key, new_configuration_values) - @configuration[key] = new_configuration_values - save_settings(@configuration) - end - - private - - def save_settings(settings) - File.write(@swiftlint_yaml_path, settings.to_yaml) - end -end - -class SettingOption - def initialize - @options = OpenStruct.new - OptionParser.new do |opt| - opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } - opt.on('-p', '--pods_directory STRING', 'The directory of pods') { |option| @options.pods_directory = option } - opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } - opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } - opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } - opt.on('-y', '--touchin_swiftlint_yaml_path STRING', 'The path to the touchin swiftlint yaml relative to the source directory') { |option| @options.touchin_swiftlint_yaml_path = option } - opt.on('-g', '--depth_git_count Int', 'The depth between the git directory and sources directory') { |option| @options.depth_git_count = option } - end.parse! - - if @options.check_mode.to_s.nilOrEmpty? - @options.check_mode = 'fully' - end - - if @options.use_multiple.to_s.nilOrEmpty? - @options.use_multiple = 'false' - end - - if @options.depth_git_count.to_s.nilOrEmpty? - @options.depth_git_count = 0 - end - - if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? - @options.touchin_swiftlint_yaml_path = '/build-scripts/xcode/.swiftlint.yml' - end - end - - def source_directory - @options.source_directory - end - - def source_date - @options.source_date - end - - def pods_directory - @options.pods_directory - end - - def check_mode - @options.check_mode - end - - def use_multiple - @options.use_multiple - end - - def depth_git_count - @options.depth_git_count - end - - def touchin_swiftlint_yaml_path - @options.touchin_swiftlint_yaml_path - end -end - -class CommandUtils - def self.make_command(command) - command = command.to_s - return `#{command}` - end -end - -class GitСaretaker < CommandUtils - def self.get_modified_files - non_indexed_files = get_files_from('git diff --name-only | sed s/.*/"&,"/ ') - indexed_files = get_files_from('git diff --cached --name-only | sed s/.*/"&,"/ ') - - modified_files = non_indexed_files + indexed_files - unique_modified_files = modified_files.uniq - - unique_modified_swift_files = [] - if not unique_modified_files.nilOrEmpty? - unique_modified_swift_files = unique_modified_files.select { |file_path| - file_path.to_s.filter_allowed_symbol_into_path - file_path.to_s.include? '.swift' - } - end - - return unique_modified_swift_files - end - - def self.get_creation_date(file_path) - git_command = 'git log --follow --format=%cD --reverse -- ' + file_path + ' | head -1' - return make_command(git_command) - end - - private - - def self.get_files_from(command) - files_as_string = make_command(command) - return files_as_string.split(',') - end -end - -class SwiftFileManager - def initialize(excluded_files, source_date) - if not source_date.nilOrEmpty? - @source_date = Date.parse(source_date) - end - @excluded_files = excluded_files - @new_files = [] - @old_files = [] - end - - def old_files - @old_files - end - - def new_files - @new_files - end - - def find_list_file_paths(start_folder) - swift_files = File.join('**', '*.swift') - Dir.glob(swift_files, base: start_folder) { |file_path| - if not is_excluded_file(file_path) - compare_timestamp(file_path) - end - } - end - - def find_list_file_paths_from(files_path) - files_path.each { |file_path| - if not is_excluded_file(file_path) - compare_timestamp(file_path) - end - } - end - - def is_excluded_file(file_path) - @excluded_files.each do |exclude_file_path| - if file_path.include? exclude_file_path - return true - end - end - return false - end - - private - - def compare_timestamp(file_path) - wrapped_whitespace_file_path = file_path.with_wrapped_whitespace - creation_date_string = GitСaretaker.get_creation_date(wrapped_whitespace_file_path) - puts file_path - if creation_date_string.nilOrEmpty? - @old_files.push(file_path) - puts 'Not found the creation date' - else - creation_date = Date.parse(creation_date_string) - puts creation_date - if @source_date < creation_date - @new_files.push(file_path) - else - @old_files.push(file_path) - end - end - end -end +require_relative 'array_extension.rb' +require_relative 'git_caretaker.rb' +require_relative 'string_extension.rb' +require_relative 'swift_file_manager.rb' +require_relative 'yaml_manager.rb' class StrategyMaker def initialize(source_directory, pods_directory, touchin_swiftlint_yaml_path) @@ -354,6 +135,13 @@ class StrategyMaker def run_bash_command(bash_command) exit (exec bash_command) end + + def create_yaml_managers_and_copy_temporary_files + create_copy_temporary_files + + @touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) + @old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) + end def create_copy_temporary_files create_copy_temporary_touchin_files @@ -365,13 +153,6 @@ class StrategyMaker FileUtils.cp @touchin_swiftlint_yaml_path, @touchin_swiftlint_yaml_temporary_path end - def create_yaml_managers_and_copy_temporary_files - create_copy_temporary_files - - @touchin_swiftlint_yaml_manager = YamlManager.new(@touchin_swiftlint_yaml_temporary_path) - @old_swiftlint_yaml_manager = YamlManager.new(@old_swiftlint_yaml_temporary_path) - end - def unique_exclude_files(touchin_swiftlint_yaml_manager, old_swiftlint_yaml_manager) touchin_excluded_files = touchin_swiftlint_yaml_manager.get_configuration('excluded') old_excluded_files = old_swiftlint_yaml_manager.get_configuration('excluded') @@ -379,17 +160,4 @@ class StrategyMaker unique_exclude_files = common_exclude_files.uniq return unique_exclude_files end -end - -setting = SettingOption.new -maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) - -if setting.check_mode.eql? 'fully' and setting.use_multiple.true? - maker.make_fully_multiple_strategy(setting.source_date) -elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? - maker.make_fully_single_strategy -elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? - maker.make_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) -elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? - maker.make_simplified_single_strategy(setting.depth_git_count) -end +end \ No newline at end of file diff --git a/xcode/build_phases/multiple_swiftlint/string_extension.rb b/xcode/build_phases/multiple_swiftlint/string_extension.rb new file mode 100644 index 0000000..5b409e1 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/string_extension.rb @@ -0,0 +1,25 @@ +class String + def with_wrapped_whitespace + self.gsub(/\s+/, '\ ') + end + + def filter_allowed_symbol_into_path + self.gsub!(/[^0-9A-Za-z \-+.\/]/, '') + end + + def true? + self.to_s.downcase == "true" + end + + def add_back_to_path(count) + string = self + count.to_i.times { |i| + string = '../' + string + } + return string + end + + def nilOrEmpty? + self.nil? or self.empty? + end +end diff --git a/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb b/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb new file mode 100644 index 0000000..dd0d0f7 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb @@ -0,0 +1,69 @@ +require 'fileutils' +require 'date' + +require_relative 'git_caretaker.rb' + +class SwiftFileManager + def initialize(excluded_files, source_date) + if not source_date.nilOrEmpty? + @source_date = Date.parse(source_date) + end + @excluded_files = excluded_files + @new_files = [] + @old_files = [] + end + + def old_files + @old_files + end + + def new_files + @new_files + end + + def find_list_file_paths(start_folder) + swift_files = File.join('**', '*.swift') + Dir.glob(swift_files, base: start_folder) { |file_path| + if not is_excluded_file(file_path) + compare_timestamp(file_path) + end + } + end + + def find_list_file_paths_from(files_path) + files_path.each { |file_path| + if not is_excluded_file(file_path) + compare_timestamp(file_path) + end + } + end + + def is_excluded_file(file_path) + @excluded_files.each do |exclude_file_path| + if file_path.include? exclude_file_path + return true + end + end + return false + end + + private + + def compare_timestamp(file_path) + wrapped_whitespace_file_path = file_path.with_wrapped_whitespace + creation_date_string = GitСaretaker.get_creation_date(wrapped_whitespace_file_path) + puts file_path + if creation_date_string.nilOrEmpty? + @old_files.push(file_path) + puts 'Not found the creation date' + else + creation_date = Date.parse(creation_date_string) + puts creation_date + if @source_date < creation_date + @new_files.push(file_path) + else + @old_files.push(file_path) + end + end + end +end \ No newline at end of file diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb new file mode 100644 index 0000000..a499be7 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -0,0 +1,19 @@ +#https://github.com/TouchInstinct/Styleguide/blob/multiple_swiftlint/IOS/Guides/BuildScripts/Multiple_Swiftlint_Guide.md +require_relative 'setting_option.rb' +require_relative 'strategy_maker.rb' + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +setting = SettingOption.new +maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) + +if setting.check_mode.eql? 'fully' and setting.use_multiple.true? + maker.make_fully_multiple_strategy(setting.source_date) +elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? + maker.make_fully_single_strategy +elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? + maker.make_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) +elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? + maker.make_simplified_single_strategy(setting.depth_git_count) +end diff --git a/xcode/build_phases/multiple_swiftlint/yaml_manager.rb b/xcode/build_phases/multiple_swiftlint/yaml_manager.rb new file mode 100644 index 0000000..cb3bbd8 --- /dev/null +++ b/xcode/build_phases/multiple_swiftlint/yaml_manager.rb @@ -0,0 +1,24 @@ +require 'yaml' +require 'fileutils' + +class YamlManager + def initialize(swiftlint_yaml_path) + @swiftlint_yaml_path = swiftlint_yaml_path + @configuration ||= YAML.load(File.read(@swiftlint_yaml_path)) + end + + def get_configuration(key) + @configuration[key] + end + + def update(key, new_configuration_values) + @configuration[key] = new_configuration_values + save_settings(@configuration) + end + + private + + def save_settings(settings) + File.write(@swiftlint_yaml_path, settings.to_yaml) + end +end From e819248df2bcb59f6ed16457e2f9537b468e2608 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Wed, 29 Jul 2020 12:30:58 +0300 Subject: [PATCH 08/13] =?UTF-8?q?rename=20make=5F=20=E2=80=93>=20run=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../multiple_swiftlint/strategy_maker.rb | 24 +++++++++---------- .../multiple_swiftlint/swiftlint.rb | 10 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb index 74419b7..14fcdf0 100644 --- a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -23,7 +23,7 @@ class StrategyMaker @swiftlint_lint_command = @swiftlint + ' --path ' + @source_directory + ' --config ' end - def make_fully_multiple_strategy(source_date) + def run_fully_multiple_strategy(source_date) create_yaml_managers_and_copy_temporary_files exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) @@ -37,10 +37,10 @@ class StrategyMaker @touchin_swiftlint_yaml_manager.update('excluded', total_touchin_excluded_files) @old_swiftlint_yaml_manager.update('excluded', total_old_excluded_files) - make_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) + run_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) end - def make_simplified_multiple_strategy(source_date, depth_git_count) + def run_simplified_multiple_strategy(source_date, depth_git_count) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -69,21 +69,21 @@ class StrategyMaker is_exist_total_old_included_files = (not total_old_included_files.nilOrEmpty?) if is_exist_total_touchin_included_files and is_exist_total_old_included_files - make_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) + run_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) elsif is_exist_total_touchin_included_files and not is_exist_total_old_included_files - make_single_strategy(@touchin_swiftlint_yaml_temporary_path) + run_single_strategy(@touchin_swiftlint_yaml_temporary_path) elsif not is_exist_total_touchin_included_files and is_exist_total_old_included_files - make_single_strategy(@old_swiftlint_yaml_temporary_path) + run_single_strategy(@old_swiftlint_yaml_temporary_path) else puts 'Git did not found swift files to check' end end - def make_fully_single_strategy - make_single_strategy(@touchin_swiftlint_yaml_path) + def run_fully_single_strategy + run_single_strategy(@touchin_swiftlint_yaml_path) end - def make_simplified_single_strategy(depth_git_count) + def run_simplified_single_strategy(depth_git_count) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -104,7 +104,7 @@ class StrategyMaker touchin_swiftlint_yaml_manager.update('included', included_files) if not included_files.nilOrEmpty? - make_single_strategy(@touchin_swiftlint_yaml_temporary_path) + run_single_strategy(@touchin_swiftlint_yaml_temporary_path) else puts 'Git found the swift files to check, but they are excluded in yaml' end @@ -112,13 +112,13 @@ class StrategyMaker private - def make_single_strategy(swiftlint_yaml_path) + def run_single_strategy(swiftlint_yaml_path) result_swiftlint_command = get_swiftlint_command(swiftlint_yaml_path) puts result_swiftlint_command run_bash_command(result_swiftlint_command) end - def make_multiple_strategy(touchin_swiftlint_yaml_temporary_path, old_swiftlint_yaml_temporary_path) + def run_multiple_strategy(touchin_swiftlint_yaml_temporary_path, old_swiftlint_yaml_temporary_path) touchin_swiftlint_command = get_swiftlint_command(touchin_swiftlint_yaml_temporary_path) old_swiftlint_command = get_swiftlint_command(old_swiftlint_yaml_temporary_path) result_swiftlint_command = touchin_swiftlint_command + ' && ' + old_swiftlint_command diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb index a499be7..cf8852c 100644 --- a/xcode/build_phases/multiple_swiftlint/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -6,14 +6,14 @@ Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 setting = SettingOption.new -maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) +strategy_maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) if setting.check_mode.eql? 'fully' and setting.use_multiple.true? - maker.make_fully_multiple_strategy(setting.source_date) + strategy_maker.run_fully_multiple_strategy(setting.source_date) elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? - maker.make_fully_single_strategy + strategy_maker.run_fully_single_strategy elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? - maker.make_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) + strategy_maker.run_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? - maker.make_simplified_single_strategy(setting.depth_git_count) + strategy_maker.run_simplified_single_strategy(setting.depth_git_count) end From c5cde472dd48c0f4550037813f251fd10f5cf1d4 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Wed, 29 Jul 2020 12:40:54 +0300 Subject: [PATCH 09/13] =?UTF-8?q?changed=20pods=5Fdirectory=20=E2=80=93>?= =?UTF-8?q?=20swiftlint=5Fexecutable=5Fpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build_phases/multiple_swiftlint/setting_option.rb | 6 +++--- .../build_phases/multiple_swiftlint/strategy_maker.rb | 11 ++++------- xcode/build_phases/multiple_swiftlint/swiftlint.rb | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb index 338d56e..923acab 100644 --- a/xcode/build_phases/multiple_swiftlint/setting_option.rb +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -8,7 +8,7 @@ class SettingOption @options = OpenStruct.new OptionParser.new do |opt| opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } - opt.on('-p', '--pods_directory STRING', 'The directory of pods') { |option| @options.pods_directory = option } + opt.on('-l', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } @@ -41,8 +41,8 @@ class SettingOption @options.source_date end - def pods_directory - @options.pods_directory + def swiftlint_executable_path + @options.swiftlint_executable_path end def check_mode diff --git a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb index 14fcdf0..28e4ee3 100644 --- a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -7,11 +7,8 @@ require_relative 'swift_file_manager.rb' require_relative 'yaml_manager.rb' class StrategyMaker - def initialize(source_directory, pods_directory, touchin_swiftlint_yaml_path) - @source_directory = source_directory - @pods_directory = pods_directory - @swiftlint = pods_directory + '/SwiftLint/swiftlint' - + def initialize(source_directory, swiftlint_executable_path, touchin_swiftlint_yaml_path) + @source_directory = source_directory @touchin_swiftlint_yaml_path = source_directory + touchin_swiftlint_yaml_path @old_swiftlint_yaml_path = source_directory + '/.swiftlint.yml' @@ -19,8 +16,8 @@ class StrategyMaker @touchin_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.touchin_swiftlint.yml' @old_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.old_swiftlint.yml' - @swiftlint_autocorrect_command = @swiftlint + ' autocorrect --path ' + @source_directory + ' --config ' - @swiftlint_lint_command = @swiftlint + ' --path ' + @source_directory + ' --config ' + @swiftlint_autocorrect_command = swiftlint_executable_path + ' autocorrect --path ' + @source_directory + ' --config ' + @swiftlint_lint_command = swiftlint_executable_path + ' --path ' + @source_directory + ' --config ' end def run_fully_multiple_strategy(source_date) diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb index cf8852c..533c927 100644 --- a/xcode/build_phases/multiple_swiftlint/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -6,7 +6,7 @@ Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 setting = SettingOption.new -strategy_maker = StrategyMaker.new(setting.source_directory, setting.pods_directory, setting.touchin_swiftlint_yaml_path) +strategy_maker = StrategyMaker.new(setting.source_directory, setting.swiftlint_executable_path, setting.touchin_swiftlint_yaml_path) if setting.check_mode.eql? 'fully' and setting.use_multiple.true? strategy_maker.run_fully_multiple_strategy(setting.source_date) From dcf88a7be578c576bb42b0d60da051978b14fa64 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Wed, 29 Jul 2020 13:54:17 +0300 Subject: [PATCH 10/13] =?UTF-8?q?replace=20depth=5Fgit=5Fcount=20=E2=80=93?= =?UTF-8?q?>=20git=5Fdirectory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build_phases/multiple_swiftlint/setting_option.rb | 10 +++++----- .../build_phases/multiple_swiftlint/strategy_maker.rb | 8 ++++---- .../multiple_swiftlint/string_extension.rb | 8 -------- xcode/build_phases/multiple_swiftlint/swiftlint.rb | 4 ++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb index 923acab..998cd83 100644 --- a/xcode/build_phases/multiple_swiftlint/setting_option.rb +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -9,11 +9,11 @@ class SettingOption OptionParser.new do |opt| opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } opt.on('-l', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } + opt.on('-g', '--git_directory STRING', 'The directory of git') { |option| @options.git_directory = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } opt.on('-y', '--touchin_swiftlint_yaml_path STRING', 'The path to the touchin swiftlint yaml relative to the source directory') { |option| @options.touchin_swiftlint_yaml_path = option } - opt.on('-g', '--depth_git_count Int', 'The depth between the git directory and sources directory') { |option| @options.depth_git_count = option } end.parse! if @options.check_mode.to_s.nilOrEmpty? @@ -24,8 +24,8 @@ class SettingOption @options.use_multiple = 'false' end - if @options.depth_git_count.to_s.nilOrEmpty? - @options.depth_git_count = 0 + if @options.git_directory.to_s.nilOrEmpty? + @options.git_directory = @options.source_directory end if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? @@ -53,8 +53,8 @@ class SettingOption @options.use_multiple end - def depth_git_count - @options.depth_git_count + def git_directory + @options.git_directory end def touchin_swiftlint_yaml_path diff --git a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb index 28e4ee3..e92c0bb 100644 --- a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -37,7 +37,7 @@ class StrategyMaker run_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) end - def run_simplified_multiple_strategy(source_date, depth_git_count) + def run_simplified_multiple_strategy(source_date, git_directory) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -48,7 +48,7 @@ class StrategyMaker create_yaml_managers_and_copy_temporary_files exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) - included_files = included_files.map { |file_path| file_path.add_back_to_path(depth_git_count) } + included_files = included_files.map { |file_path| git_directory + file_path } swift_file_manager = SwiftFileManager.new(exclude_files, source_date) swift_file_manager.find_list_file_paths_from(included_files) @@ -80,7 +80,7 @@ class StrategyMaker run_single_strategy(@touchin_swiftlint_yaml_path) end - def run_simplified_single_strategy(depth_git_count) + def run_simplified_single_strategy(git_directory) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -95,7 +95,7 @@ class StrategyMaker swift_files = SwiftFileManager.new(touchin_excluded_files, '') included_files = included_files.select { |file_name| not swift_files.is_excluded_file(file_name) } - included_files = included_files.map { |file_path| file_path.add_back_to_path(depth_git_count) } + included_files = included_files.map { |file_path| git_directory + file_path } touchin_swiftlint_yaml_manager.update('excluded', []) touchin_swiftlint_yaml_manager.update('included', included_files) diff --git a/xcode/build_phases/multiple_swiftlint/string_extension.rb b/xcode/build_phases/multiple_swiftlint/string_extension.rb index 5b409e1..33a6357 100644 --- a/xcode/build_phases/multiple_swiftlint/string_extension.rb +++ b/xcode/build_phases/multiple_swiftlint/string_extension.rb @@ -11,14 +11,6 @@ class String self.to_s.downcase == "true" end - def add_back_to_path(count) - string = self - count.to_i.times { |i| - string = '../' + string - } - return string - end - def nilOrEmpty? self.nil? or self.empty? end diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb index 533c927..74d1f6c 100644 --- a/xcode/build_phases/multiple_swiftlint/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -13,7 +13,7 @@ if setting.check_mode.eql? 'fully' and setting.use_multiple.true? elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? strategy_maker.run_fully_single_strategy elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? - strategy_maker.run_simplified_multiple_strategy(setting.source_date, setting.depth_git_count) + strategy_maker.run_simplified_multiple_strategy(setting.source_date, setting.git_directory) elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? - strategy_maker.run_simplified_single_strategy(setting.depth_git_count) + strategy_maker.run_simplified_single_strategy(setting.git_directory) end From 04c863cc14679bb6088672723d40a1c47e32b5c5 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Wed, 29 Jul 2020 17:36:14 +0300 Subject: [PATCH 11/13] fix naming and remove unnecessary code --- .../multiple_swiftlint/setting_option.rb | 12 ++++++------ .../multiple_swiftlint/strategy_maker.rb | 16 ++++++++-------- .../multiple_swiftlint/swift_file_manager.rb | 5 ++--- .../build_phases/multiple_swiftlint/swiftlint.rb | 5 +---- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb index 998cd83..0941e28 100644 --- a/xcode/build_phases/multiple_swiftlint/setting_option.rb +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -7,8 +7,8 @@ class SettingOption def initialize @options = OpenStruct.new OptionParser.new do |opt| - opt.on('-s', '--source_directory STRING', 'The directory of source') { |option| @options.source_directory = option } - opt.on('-l', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } + opt.on('-p', '--project_directory STRING', 'The directory of project') { |option| @options.project_directory = option } + opt.on('-s', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } opt.on('-g', '--git_directory STRING', 'The directory of git') { |option| @options.git_directory = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } @@ -25,7 +25,7 @@ class SettingOption end if @options.git_directory.to_s.nilOrEmpty? - @options.git_directory = @options.source_directory + @options.git_directory = @options.project_directory end if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? @@ -33,8 +33,8 @@ class SettingOption end end - def source_directory - @options.source_directory + def project_directory + @options.project_directory end def source_date @@ -60,4 +60,4 @@ class SettingOption def touchin_swiftlint_yaml_path @options.touchin_swiftlint_yaml_path end -end \ No newline at end of file +end diff --git a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb index e92c0bb..a289f5f 100644 --- a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -7,17 +7,17 @@ require_relative 'swift_file_manager.rb' require_relative 'yaml_manager.rb' class StrategyMaker - def initialize(source_directory, swiftlint_executable_path, touchin_swiftlint_yaml_path) - @source_directory = source_directory - @touchin_swiftlint_yaml_path = source_directory + touchin_swiftlint_yaml_path - @old_swiftlint_yaml_path = source_directory + '/.swiftlint.yml' + def initialize(project_directory, swiftlint_executable_path, touchin_swiftlint_yaml_path) + @project_directory = project_directory + @touchin_swiftlint_yaml_path = project_directory + touchin_swiftlint_yaml_path + @old_swiftlint_yaml_path = project_directory + '/.swiftlint.yml' - @temporary_swiftlint_folder_name = source_directory + '/temporary_swiftlint' + @temporary_swiftlint_folder_name = project_directory + '/temporary_swiftlint' @touchin_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.touchin_swiftlint.yml' @old_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.old_swiftlint.yml' - @swiftlint_autocorrect_command = swiftlint_executable_path + ' autocorrect --path ' + @source_directory + ' --config ' - @swiftlint_lint_command = swiftlint_executable_path + ' --path ' + @source_directory + ' --config ' + @swiftlint_autocorrect_command = swiftlint_executable_path + ' autocorrect --path ' + @project_directory + ' --config ' + @swiftlint_lint_command = swiftlint_executable_path + ' --path ' + @project_directory + ' --config ' end def run_fully_multiple_strategy(source_date) @@ -26,7 +26,7 @@ class StrategyMaker exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) swift_files = SwiftFileManager.new(exclude_files, source_date) - swift_files.find_list_file_paths(@source_directory) + swift_files.find_list_file_paths(@project_directory) total_touchin_excluded_files = exclude_files + swift_files.old_files total_old_excluded_files = exclude_files + swift_files.new_files diff --git a/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb b/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb index dd0d0f7..b8edf6c 100644 --- a/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb +++ b/xcode/build_phases/multiple_swiftlint/swift_file_manager.rb @@ -52,13 +52,12 @@ class SwiftFileManager def compare_timestamp(file_path) wrapped_whitespace_file_path = file_path.with_wrapped_whitespace creation_date_string = GitСaretaker.get_creation_date(wrapped_whitespace_file_path) - puts file_path if creation_date_string.nilOrEmpty? @old_files.push(file_path) - puts 'Not found the creation date' + puts ('Creation date of ' + file_path + ' was not found') else creation_date = Date.parse(creation_date_string) - puts creation_date + puts ('Creation date of ' + file_path + ' is ' + creation_date.to_s) if @source_date < creation_date @new_files.push(file_path) else diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb index 74d1f6c..e9cc0d2 100644 --- a/xcode/build_phases/multiple_swiftlint/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -2,11 +2,8 @@ require_relative 'setting_option.rb' require_relative 'strategy_maker.rb' -Encoding.default_external = Encoding::UTF_8 -Encoding.default_internal = Encoding::UTF_8 - setting = SettingOption.new -strategy_maker = StrategyMaker.new(setting.source_directory, setting.swiftlint_executable_path, setting.touchin_swiftlint_yaml_path) +strategy_maker = StrategyMaker.new(setting.project_directory, setting.swiftlint_executable_path, setting.touchin_swiftlint_yaml_path) if setting.check_mode.eql? 'fully' and setting.use_multiple.true? strategy_maker.run_fully_multiple_strategy(setting.source_date) From 0eb6a299d77ae1ee561dadc058ec880e7fa51aa5 Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Thu, 30 Jul 2020 11:51:58 +0300 Subject: [PATCH 12/13] =?UTF-8?q?rename=20project=5Fdirectory=20=E2=80=93>?= =?UTF-8?q?=20project=5Froot=5Fpath,=20git=5Fdirectory=20=E2=80=93>=20sour?= =?UTF-8?q?ce=5Froot=5Fpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../multiple_swiftlint/setting_option.rb | 16 ++++++------- .../multiple_swiftlint/strategy_maker.rb | 24 +++++++++---------- .../multiple_swiftlint/swiftlint.rb | 6 ++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb index 0941e28..e3d0ccf 100644 --- a/xcode/build_phases/multiple_swiftlint/setting_option.rb +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -7,9 +7,9 @@ class SettingOption def initialize @options = OpenStruct.new OptionParser.new do |opt| - opt.on('-p', '--project_directory STRING', 'The directory of project') { |option| @options.project_directory = option } + opt.on('-p', '--project_root_path STRING', 'The path of project directory') { |option| @options.project_root_path = option } + opt.on('-r', '--source_root_path STRING', 'The path of source directory ') { |option| @options.source_root_path = option } opt.on('-s', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } - opt.on('-g', '--git_directory STRING', 'The directory of git') { |option| @options.git_directory = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option } opt.on('-d', '--source_date DATE', 'The date of grouping files according touchin and old swiftlint rules') { |option| @options.source_date = option } @@ -24,8 +24,8 @@ class SettingOption @options.use_multiple = 'false' end - if @options.git_directory.to_s.nilOrEmpty? - @options.git_directory = @options.project_directory + if @options.source_root_path.to_s.nilOrEmpty? + @options.source_root_path = @options.project_root_path end if @options.touchin_swiftlint_yaml_path.to_s.nilOrEmpty? @@ -33,8 +33,8 @@ class SettingOption end end - def project_directory - @options.project_directory + def project_root_path + @options.project_root_path end def source_date @@ -53,8 +53,8 @@ class SettingOption @options.use_multiple end - def git_directory - @options.git_directory + def source_root_path + @options.source_root_path end def touchin_swiftlint_yaml_path diff --git a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb index a289f5f..a677892 100644 --- a/xcode/build_phases/multiple_swiftlint/strategy_maker.rb +++ b/xcode/build_phases/multiple_swiftlint/strategy_maker.rb @@ -7,17 +7,17 @@ require_relative 'swift_file_manager.rb' require_relative 'yaml_manager.rb' class StrategyMaker - def initialize(project_directory, swiftlint_executable_path, touchin_swiftlint_yaml_path) - @project_directory = project_directory - @touchin_swiftlint_yaml_path = project_directory + touchin_swiftlint_yaml_path - @old_swiftlint_yaml_path = project_directory + '/.swiftlint.yml' + def initialize(project_root_path, swiftlint_executable_path, touchin_swiftlint_yaml_path) + @project_root_path = project_root_path + @touchin_swiftlint_yaml_path = project_root_path + touchin_swiftlint_yaml_path + @old_swiftlint_yaml_path = project_root_path + '/.swiftlint.yml' - @temporary_swiftlint_folder_name = project_directory + '/temporary_swiftlint' + @temporary_swiftlint_folder_name = project_root_path + '/temporary_swiftlint' @touchin_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.touchin_swiftlint.yml' @old_swiftlint_yaml_temporary_path = @temporary_swiftlint_folder_name + '/.old_swiftlint.yml' - @swiftlint_autocorrect_command = swiftlint_executable_path + ' autocorrect --path ' + @project_directory + ' --config ' - @swiftlint_lint_command = swiftlint_executable_path + ' --path ' + @project_directory + ' --config ' + @swiftlint_autocorrect_command = swiftlint_executable_path + ' autocorrect --path ' + @project_root_path + ' --config ' + @swiftlint_lint_command = swiftlint_executable_path + ' --path ' + @project_root_path + ' --config ' end def run_fully_multiple_strategy(source_date) @@ -26,7 +26,7 @@ class StrategyMaker exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) swift_files = SwiftFileManager.new(exclude_files, source_date) - swift_files.find_list_file_paths(@project_directory) + swift_files.find_list_file_paths(@project_root_path) total_touchin_excluded_files = exclude_files + swift_files.old_files total_old_excluded_files = exclude_files + swift_files.new_files @@ -37,7 +37,7 @@ class StrategyMaker run_multiple_strategy(@touchin_swiftlint_yaml_temporary_path, @old_swiftlint_yaml_temporary_path) end - def run_simplified_multiple_strategy(source_date, git_directory) + def run_simplified_multiple_strategy(source_date, source_root_path) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -48,7 +48,7 @@ class StrategyMaker create_yaml_managers_and_copy_temporary_files exclude_files = unique_exclude_files(@touchin_swiftlint_yaml_manager, @old_swiftlint_yaml_manager) - included_files = included_files.map { |file_path| git_directory + file_path } + included_files = included_files.map { |file_path| source_root_path + file_path } swift_file_manager = SwiftFileManager.new(exclude_files, source_date) swift_file_manager.find_list_file_paths_from(included_files) @@ -80,7 +80,7 @@ class StrategyMaker run_single_strategy(@touchin_swiftlint_yaml_path) end - def run_simplified_single_strategy(git_directory) + def run_simplified_single_strategy(source_root_path) included_files = GitСaretaker.get_modified_files if included_files.nilOrEmpty? @@ -95,7 +95,7 @@ class StrategyMaker swift_files = SwiftFileManager.new(touchin_excluded_files, '') included_files = included_files.select { |file_name| not swift_files.is_excluded_file(file_name) } - included_files = included_files.map { |file_path| git_directory + file_path } + included_files = included_files.map { |file_path| source_root_path + file_path } touchin_swiftlint_yaml_manager.update('excluded', []) touchin_swiftlint_yaml_manager.update('included', included_files) diff --git a/xcode/build_phases/multiple_swiftlint/swiftlint.rb b/xcode/build_phases/multiple_swiftlint/swiftlint.rb index e9cc0d2..17f8383 100644 --- a/xcode/build_phases/multiple_swiftlint/swiftlint.rb +++ b/xcode/build_phases/multiple_swiftlint/swiftlint.rb @@ -3,14 +3,14 @@ require_relative 'setting_option.rb' require_relative 'strategy_maker.rb' setting = SettingOption.new -strategy_maker = StrategyMaker.new(setting.project_directory, setting.swiftlint_executable_path, setting.touchin_swiftlint_yaml_path) +strategy_maker = StrategyMaker.new(setting.project_root_path, setting.swiftlint_executable_path, setting.touchin_swiftlint_yaml_path) if setting.check_mode.eql? 'fully' and setting.use_multiple.true? strategy_maker.run_fully_multiple_strategy(setting.source_date) elsif setting.check_mode.eql? 'fully' and not setting.use_multiple.true? strategy_maker.run_fully_single_strategy elsif setting.check_mode.eql? 'simplified' and setting.use_multiple.true? - strategy_maker.run_simplified_multiple_strategy(setting.source_date, setting.git_directory) + strategy_maker.run_simplified_multiple_strategy(setting.source_date, setting.source_root_path) elsif setting.check_mode.eql? 'simplified' and not setting.use_multiple.true? - strategy_maker.run_simplified_single_strategy(setting.git_directory) + strategy_maker.run_simplified_single_strategy(setting.source_root_path) end From d70fc7f34dc47d7b454fb90fb1caf9696505607a Mon Sep 17 00:00:00 2001 From: Maxim Sorokin Date: Thu, 30 Jul 2020 12:19:38 +0300 Subject: [PATCH 13/13] changed description for project_root_path and source_root_path --- xcode/build_phases/multiple_swiftlint/setting_option.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/multiple_swiftlint/setting_option.rb b/xcode/build_phases/multiple_swiftlint/setting_option.rb index e3d0ccf..44b8d7e 100644 --- a/xcode/build_phases/multiple_swiftlint/setting_option.rb +++ b/xcode/build_phases/multiple_swiftlint/setting_option.rb @@ -7,8 +7,10 @@ class SettingOption def initialize @options = OpenStruct.new OptionParser.new do |opt| - opt.on('-p', '--project_root_path STRING', 'The path of project directory') { |option| @options.project_root_path = option } - opt.on('-r', '--source_root_path STRING', 'The path of source directory ') { |option| @options.source_root_path = option } + opt.on('-p', '--project_root_path STRING', 'The path of project directory and contains *.xcodeproj file always. ' + + 'Example: project_root_path=~/Projects/MyProject/Source/..') { |option| @options.project_root_path = option } + opt.on('-r', '--source_root_path STRING', 'The path of source directory and may not contains *.xcodeproj file in some cases. ' + + 'Example: source_root_path=~/Projects/MyProject/') { |option| @options.source_root_path = option } opt.on('-s', '--swiftlint_executable_path STRING', 'The executable path of swiftlint') { |option| @options.swiftlint_executable_path = option } opt.on('-c', '--check_mode MODE', 'The mode of check is "fully" or "simplified"') { |option| @options.check_mode = option } opt.on('-u', '--use_multiple BOOL', 'The flag indicates the use of multiple yaml swiftlint configurations') { |option| @options.use_multiple = option }