From 3cbddc47891ad24cc4d313979df7dc866b32c900 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Wed, 27 Jun 2018 14:32:53 +0200 Subject: [PATCH 1/6] No longer raise a RuntimeError if an input file was not formatted well. It is quite normal to accept such input. Also log 'Fixed it for you' in case a file has been fixed by gherkin_format. --- lib/gherkin_format.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index fc7202a..8d0e0b8 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -22,10 +22,12 @@ def format(file, options = {}) output = format_string input, file return if input == output - File.write(file, output) if options.key? :replace - - puts "File #{file} is not formatted well." - raise "File #{file} is not formatted well." + if options.key? :replace + File.write(file, output) + puts "File #{file} was not formatted well. Fixed it for you!" + else + puts "File #{file} is not formatted well." + end end def render(template, files) From 9cf228f935f68691a25a9e5e82fdc0bbd12daf86 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Wed, 27 Jun 2018 18:22:24 +0200 Subject: [PATCH 2/6] exit with error code 1 to allow usage in CI environment --- lib/gherkin_format.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index 8d0e0b8..3f172d5 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -26,8 +26,11 @@ def format(file, options = {}) File.write(file, output) puts "File #{file} was not formatted well. Fixed it for you!" else - puts "File #{file} is not formatted well." + puts "File #{file} is not formatted well. Please fix or re-run me with --replace switch." end + + puts "Terminating. Some files may not have been checked yet, please consider a re-run." + exit 1 end def render(template, files) From 354f93c7cd9ad43e233b7398a1f489251b867d06 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Wed, 27 Jun 2018 18:48:35 +0200 Subject: [PATCH 3/6] satisfy rubocop --- lib/gherkin_format.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index 3f172d5..10dc16f 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -26,10 +26,14 @@ def format(file, options = {}) File.write(file, output) puts "File #{file} was not formatted well. Fixed it for you!" else - puts "File #{file} is not formatted well. Please fix or re-run me with --replace switch." + puts "File #{file} is not formatted well. Re-run with --replace" end - puts "Terminating. Some files may not have been checked yet, please consider a re-run." + fail_with "Terminating. Some files may not have been checked." + end + + def fail_with(message) + puts message exit 1 end From a181bc93f8a9da18e7dffe17143a50891948ae41 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Wed, 27 Jun 2018 19:03:19 +0200 Subject: [PATCH 4/6] satisfy rubocop again --- lib/gherkin_format.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index 10dc16f..7f7c2fc 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -29,7 +29,7 @@ def format(file, options = {}) puts "File #{file} is not formatted well. Re-run with --replace" end - fail_with "Terminating. Some files may not have been checked." + fail_with 'Terminating. Some files may not have been checked.' end def fail_with(message) From 5013ed9e4aa1e292048a4626e70db5fbedfe9804 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Mon, 10 Sep 2018 19:07:16 +0200 Subject: [PATCH 5/6] fix multiple input files, exit with 1 if any files needed fixing. --- bin/gherkin_format | 11 ++++++++++- lib/gherkin_format.rb | 11 ++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/gherkin_format b/bin/gherkin_format index daf308c..ed0e6dc 100755 --- a/bin/gherkin_format +++ b/bin/gherkin_format @@ -36,6 +36,15 @@ if options.key? :template exit 0 end +exitCode = 0 + ARGV.each do |file| - formatter.format file, options + begin + formatter.format file, options + rescue StandardError => e + puts e.message + exitCode = 1 + end end + +exit exitCode diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index 7f7c2fc..b525058 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -24,17 +24,10 @@ def format(file, options = {}) if options.key? :replace File.write(file, output) - puts "File #{file} was not formatted well. Fixed it for you!" + raise "File #{file} was not formatted well. Fixed it!" else - puts "File #{file} is not formatted well. Re-run with --replace" + raise "File #{file} is not formatted well. To fix, re-run with --replace" end - - fail_with 'Terminating. Some files may not have been checked.' - end - - def fail_with(message) - puts message - exit 1 end def render(template, files) From 355460ab3bf5285a41d28814363205a243c5fc51 Mon Sep 17 00:00:00 2001 From: Vitaliy Rybalka Date: Mon, 10 Sep 2018 19:19:24 +0200 Subject: [PATCH 6/6] satisfy rubocop --- bin/gherkin_format | 6 +++--- lib/gherkin_format.rb | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/gherkin_format b/bin/gherkin_format index ed0e6dc..de7a309 100755 --- a/bin/gherkin_format +++ b/bin/gherkin_format @@ -36,15 +36,15 @@ if options.key? :template exit 0 end -exitCode = 0 +exit_code = 0 ARGV.each do |file| begin formatter.format file, options rescue StandardError => e puts e.message - exitCode = 1 + exit_code = 1 end end -exit exitCode +exit exit_code diff --git a/lib/gherkin_format.rb b/lib/gherkin_format.rb index b525058..d046509 100644 --- a/lib/gherkin_format.rb +++ b/lib/gherkin_format.rb @@ -22,12 +22,8 @@ def format(file, options = {}) output = format_string input, file return if input == output - if options.key? :replace - File.write(file, output) - raise "File #{file} was not formatted well. Fixed it!" - else - raise "File #{file} is not formatted well. To fix, re-run with --replace" - end + File.write(file, output) if options.key? :replace + raise "File #{file} was not formatted well." end def render(template, files)