Top Level Namespace
Defined Under Namespace
Modules: Carson
Constant Summary collapse
- EXIT_OK =
0- EXIT_ERROR =
1- EXIT_BLOCK =
2
Instance Method Summary collapse
- #lint_exit_code(result:) ⇒ Object
- #print_stream(io, text) ⇒ Object
- #rubocop_config_path ⇒ Object
- #run_rubocop(files:) ⇒ Object
Instance Method Details
#lint_exit_code(result:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/carson/policy/ruby/lint.rb', line 34 def lint_exit_code( result: ) case result.fetch( :status ) when :unavailable EXIT_BLOCK when :runtime_error EXIT_ERROR else case result.fetch( :exit_code ) when 0 EXIT_OK when 1 EXIT_BLOCK else EXIT_ERROR end end end |
#print_stream(io, text) ⇒ Object
13 14 15 16 17 |
# File 'lib/carson/policy/ruby/lint.rb', line 13 def print_stream( io, text ) content = text.to_s return if content.empty? io.print( content ) end |
#rubocop_config_path ⇒ Object
9 10 11 |
# File 'lib/carson/policy/ruby/lint.rb', line 9 def rubocop_config_path File.( "~/.carson/lint/rubocop.yml" ) end |
#run_rubocop(files:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/carson/policy/ruby/lint.rb', line 19 def run_rubocop( files: ) stdout_text, stderr_text, status = Open3.capture3( "rubocop", "--config", rubocop_config_path, *files ) print_stream( $stdout, stdout_text ) print_stream( $stderr, stderr_text ) { status: :completed, exit_code: status.exitstatus.to_i } rescue Errno::ENOENT $stderr.puts "ERROR: RuboCop executable `rubocop` is unavailable in PATH. Install the pinned RuboCop gem before running carson audit." { status: :unavailable, exit_code: nil } rescue StandardError => e $stderr.puts "ERROR: RuboCop execution failed (#{e.})" { status: :runtime_error, exit_code: nil } end |