From 283ba84978a4be320e1a219e64d3aa4bdaae9517 Mon Sep 17 00:00:00 2001 From: Ignacio Calderon Date: Fri, 6 Mar 2020 13:25:24 +0100 Subject: [PATCH 1/6] add support for the --no-cache flag on autocorrect and lint --- fastlane/lib/fastlane/actions/swiftlint.rb | 7 +++ fastlane/spec/actions_specs/swiftlint_spec.rb | 59 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/fastlane/lib/fastlane/actions/swiftlint.rb b/fastlane/lib/fastlane/actions/swiftlint.rb index 8ab2fd82aaa..2057d7e5ecf 100644 --- a/fastlane/lib/fastlane/actions/swiftlint.rb +++ b/fastlane/lib/fastlane/actions/swiftlint.rb @@ -19,6 +19,7 @@ def self.run(params) command << " --reporter #{params[:reporter]}" if params[:reporter] command << supported_option_switch(params, :quiet, "0.9.0", true) command << supported_option_switch(params, :format, "0.11.0", true) if params[:mode] == :autocorrect + command << " --no-cache" if params[:no_cache] and (params[:mode] == :autocorrect or params[:mode] == :lint) command << " --compiler-log-path #{params[:compiler_log_path].shellescape}" if params[:compiler_log_path] if params[:files] @@ -139,6 +140,12 @@ def self.available_options is_string: false, type: Boolean, optional: true), + FastlaneCore::ConfigItem.new(key: :no_cache, + description: "Ignore the cache when mode is :autocorrect or :lint", + default_value: false, + is_string: false, + type: Boolean, + optional: true), FastlaneCore::ConfigItem.new(key: :compiler_log_path, description: "Compiler log path when mode is :analyze", is_string: true, diff --git a/fastlane/spec/actions_specs/swiftlint_spec.rb b/fastlane/spec/actions_specs/swiftlint_spec.rb index fc3902cdfeb..4a71dc91f0e 100644 --- a/fastlane/spec/actions_specs/swiftlint_spec.rb +++ b/fastlane/spec/actions_specs/swiftlint_spec.rb @@ -352,6 +352,65 @@ expect(result).to eq("swiftlint autocorrect") end end + + context "when specify no-cache option" do + it "adds no-cache option if mode is :autocorrect" do + result = Fastlane::FastFile.new.parse("lane :test do + swiftlint( + mode: :autocorrect, + no_cache: true + ) + end").runner.execute(:test) + + expect(result).to eq("swiftlint autocorrect --no-cache") + end + + it "adds no-cache option if mode is :lint" do + result = Fastlane::FastFile.new.parse("lane :test do + swiftlint( + mode: :lint, + no_cache: true + ) + end").runner.execute(:test) + + expect(result).to eq("swiftlint lint --no-cache") + end + + it "omits format option if mode is :analyze" do + result = Fastlane::FastFile.new.parse("lane :test do + swiftlint( + mode: :analyze, + no_cache: true + ) + end").runner.execute(:test) + + expect(result).to eq("swiftlint analyze") + end + end + + context "when specify false for no-cache option" do + it "doesn't add no-cache option if mode is :autocorrect" do + result = Fastlane::FastFile.new.parse("lane :test do + swiftlint( + mode: :autocorrect, + no_cache: false + ) + end").runner.execute(:test) + + expect(result).to eq("swiftlint autocorrect") + end + + it "doesn't add no-cache option if mode is :lint" do + result = Fastlane::FastFile.new.parse("lane :test do + swiftlint( + mode: :lint, + no_cache: false + ) + end").runner.execute(:test) + + expect(result).to eq("swiftlint lint") + end + end context "when using analyzer mode" do it "adds compiler-log-path option" do From 42a00f097fc75dd216115acf0e1b9e4f7ff12683 Mon Sep 17 00:00:00 2001 From: Ignacio Calderon Date: Fri, 6 Mar 2020 13:48:47 +0100 Subject: [PATCH 2/6] removed trailing spaces --- fastlane/spec/actions_specs/swiftlint_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastlane/spec/actions_specs/swiftlint_spec.rb b/fastlane/spec/actions_specs/swiftlint_spec.rb index 4a71dc91f0e..717a56f0346 100644 --- a/fastlane/spec/actions_specs/swiftlint_spec.rb +++ b/fastlane/spec/actions_specs/swiftlint_spec.rb @@ -352,7 +352,7 @@ expect(result).to eq("swiftlint autocorrect") end end - + context "when specify no-cache option" do it "adds no-cache option if mode is :autocorrect" do result = Fastlane::FastFile.new.parse("lane :test do @@ -364,7 +364,7 @@ expect(result).to eq("swiftlint autocorrect --no-cache") end - + it "adds no-cache option if mode is :lint" do result = Fastlane::FastFile.new.parse("lane :test do swiftlint( @@ -387,7 +387,7 @@ expect(result).to eq("swiftlint analyze") end end - + context "when specify false for no-cache option" do it "doesn't add no-cache option if mode is :autocorrect" do result = Fastlane::FastFile.new.parse("lane :test do @@ -399,7 +399,7 @@ expect(result).to eq("swiftlint autocorrect") end - + it "doesn't add no-cache option if mode is :lint" do result = Fastlane::FastFile.new.parse("lane :test do swiftlint( From e4803db1d5a75f6cd2b4497b7bb43cf4dd9e9ad4 Mon Sep 17 00:00:00 2001 From: kronenthaler Date: Sat, 7 Mar 2020 15:19:41 +0100 Subject: [PATCH 3/6] fix rubocop lint issues --- fastlane/lib/fastlane/actions/swiftlint.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fastlane/lib/fastlane/actions/swiftlint.rb b/fastlane/lib/fastlane/actions/swiftlint.rb index 2057d7e5ecf..33e5332368e 100644 --- a/fastlane/lib/fastlane/actions/swiftlint.rb +++ b/fastlane/lib/fastlane/actions/swiftlint.rb @@ -19,7 +19,7 @@ def self.run(params) command << " --reporter #{params[:reporter]}" if params[:reporter] command << supported_option_switch(params, :quiet, "0.9.0", true) command << supported_option_switch(params, :format, "0.11.0", true) if params[:mode] == :autocorrect - command << " --no-cache" if params[:no_cache] and (params[:mode] == :autocorrect or params[:mode] == :lint) + command << supported_no_cache_option(params) if params[:no_cache] command << " --compiler-log-path #{params[:compiler_log_path].shellescape}" if params[:compiler_log_path] if params[:files] @@ -41,12 +41,20 @@ def self.run(params) raise if params[:raise_if_swiftlint_error] end end - + # Get current SwiftLint version def self.swiftlint_version(executable: nil) binary = executable || 'swiftlint' Gem::Version.new(`#{binary} version`.chomp) end + + def self.supported_no_cache_option(params) + if (params[:mode] == :autocorrect || params[:mode] == :lint) + return " --no-cache" + else + return "" + end + end # Return "--option" switch if option is on and current SwiftLint version is greater or equal than min version. # Return "" otherwise. From d186a76cce05b2e090ae87bacaaf9c5a86776021 Mon Sep 17 00:00:00 2001 From: kronenthaler Date: Sat, 7 Mar 2020 15:24:01 +0100 Subject: [PATCH 4/6] fix rubocop lint issues 2 --- fastlane/lib/fastlane/actions/swiftlint.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fastlane/lib/fastlane/actions/swiftlint.rb b/fastlane/lib/fastlane/actions/swiftlint.rb index 33e5332368e..3d78f75f4ad 100644 --- a/fastlane/lib/fastlane/actions/swiftlint.rb +++ b/fastlane/lib/fastlane/actions/swiftlint.rb @@ -41,15 +41,15 @@ def self.run(params) raise if params[:raise_if_swiftlint_error] end end - + # Get current SwiftLint version def self.swiftlint_version(executable: nil) binary = executable || 'swiftlint' Gem::Version.new(`#{binary} version`.chomp) end - + def self.supported_no_cache_option(params) - if (params[:mode] == :autocorrect || params[:mode] == :lint) + if params[:mode] == :autocorrect || params[:mode] == :lint return " --no-cache" else return "" @@ -218,3 +218,4 @@ def self.handle_swiftlint_error(ignore_exit_status, exit_status) end end end +d From e66844a6272dab23325949562eb0b0371975c4d7 Mon Sep 17 00:00:00 2001 From: kronenthaler Date: Sat, 7 Mar 2020 15:27:24 +0100 Subject: [PATCH 5/6] fix rubocop lint issues 3 --- fastlane/lib/fastlane/actions/swiftlint.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fastlane/lib/fastlane/actions/swiftlint.rb b/fastlane/lib/fastlane/actions/swiftlint.rb index 3d78f75f4ad..e9592310617 100644 --- a/fastlane/lib/fastlane/actions/swiftlint.rb +++ b/fastlane/lib/fastlane/actions/swiftlint.rb @@ -217,5 +217,4 @@ def self.handle_swiftlint_error(ignore_exit_status, exit_status) end end end -end -d +end \ No newline at end of file From 170d3e4749a12d67e48e7672bc7539b2749f5618 Mon Sep 17 00:00:00 2001 From: kronenthaler Date: Sat, 7 Mar 2020 16:00:22 +0100 Subject: [PATCH 6/6] refactor to reduce complexity of run method --- fastlane/lib/fastlane/actions/swiftlint.rb | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/fastlane/lib/fastlane/actions/swiftlint.rb b/fastlane/lib/fastlane/actions/swiftlint.rb index e9592310617..d0a70270738 100644 --- a/fastlane/lib/fastlane/actions/swiftlint.rb +++ b/fastlane/lib/fastlane/actions/swiftlint.rb @@ -13,14 +13,7 @@ def self.run(params) command = (params[:executable] || "swiftlint").dup command << " #{params[:mode]}" - command << " --path #{params[:path].shellescape}" if params[:path] - command << supported_option_switch(params, :strict, "0.9.2", true) - command << " --config #{params[:config_file].shellescape}" if params[:config_file] - command << " --reporter #{params[:reporter]}" if params[:reporter] - command << supported_option_switch(params, :quiet, "0.9.0", true) - command << supported_option_switch(params, :format, "0.11.0", true) if params[:mode] == :autocorrect - command << supported_no_cache_option(params) if params[:no_cache] - command << " --compiler-log-path #{params[:compiler_log_path].shellescape}" if params[:compiler_log_path] + command << optional_flags(params) if params[:files] if version < Gem::Version.new('0.5.1') @@ -42,6 +35,19 @@ def self.run(params) end end + def self.optional_flags(params) + command = "" + command << " --path #{params[:path].shellescape}" if params[:path] + command << supported_option_switch(params, :strict, "0.9.2", true) + command << " --config #{params[:config_file].shellescape}" if params[:config_file] + command << " --reporter #{params[:reporter]}" if params[:reporter] + command << supported_option_switch(params, :quiet, "0.9.0", true) + command << supported_option_switch(params, :format, "0.11.0", true) if params[:mode] == :autocorrect + command << supported_no_cache_option(params) if params[:no_cache] + command << " --compiler-log-path #{params[:compiler_log_path].shellescape}" if params[:compiler_log_path] + return command + end + # Get current SwiftLint version def self.swiftlint_version(executable: nil) binary = executable || 'swiftlint' @@ -217,4 +223,4 @@ def self.handle_swiftlint_error(ignore_exit_status, exit_status) end end end -end \ No newline at end of file +end