Skip to content

Commit

Permalink
Set default PreferredName to e for `Naming/RescuedExceptionsVaria…
Browse files Browse the repository at this point in the history
…bleName`

Follow up f0959e8.

The default `PreferredName` of `Naming/RescuedExceptionsVariableName` cop
is `e` in the following discussion.

#6460 (comment)

This PR sets default `PreferredName` to `e` for `Naming/RescuedExceptionsVariableName`.
  • Loading branch information
koic authored and bbatsov committed Apr 4, 2019
1 parent 1d0e480 commit d0677d7
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#6881](https://github.com/rubocop-hq/rubocop/pull/6881): Set default `PreferredName` to `e` for `Naming/RescuedExceptionsVariableName`. ([@koic][])

## 0.67.0 (2019-04-04)

### New features
Expand Down
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require 'bundler'
require 'bundler/gem_tasks'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => ex
warn ex.message
rescue Bundler::BundlerError => e
warn e.message
warn 'Run `bundle install` to install missing gems'
exit ex.status_code
exit e.status_code
end
require 'rake'
require 'rubocop/rake_task'
Expand Down Expand Up @@ -110,9 +110,9 @@ task documentation_syntax_check: :yard_for_generate_documentation do
parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
parser.diagnostics.all_errors_are_fatal = true
parser.parse(buffer)
rescue Parser::SyntaxError => ex
rescue Parser::SyntaxError => e
path = example.object.file
puts "#{path}: Syntax Error in an example. #{ex}"
puts "#{path}: Syntax Error in an example. #{e}"
ok = false
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ Naming/RescuedExceptionsVariableName:
Description: 'Use consistent rescued exceptions variables naming.'
Enabled: true
VersionAdded: '0.67'
PreferredName: ex
PreferredName: e

Naming/UncommunicativeBlockParamName:
Description: >-
Expand Down
20 changes: 9 additions & 11 deletions lib/rubocop/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,21 @@ def run(args = ARGV)
act_on_options
apply_default_formatter
execute_runners(paths)
rescue ConfigNotFoundError,
IncorrectCopNameError,
OptionArgumentError => ex
warn ex.message
rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
warn e.message
STATUS_ERROR
rescue RuboCop::Error => ex
warn Rainbow("Error: #{ex.message}").red
rescue RuboCop::Error => e
warn Rainbow("Error: #{e.message}").red
STATUS_ERROR
rescue Finished
STATUS_SUCCESS
rescue OptionParser::InvalidOption => ex
warn ex.message
rescue OptionParser::InvalidOption => e
warn e.message
warn 'For usage information, use --help'
STATUS_ERROR
rescue StandardError, SyntaxError, LoadError => ex
warn ex.message
warn ex.backtrace
rescue StandardError, SyntaxError, LoadError => e
warn e.message
warn e.backtrace
STATUS_ERROR
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/config_loader_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def transform(config)
def gem_config_path(gem_name, relative_config_path)
spec = Gem::Specification.find_by_name(gem_name)
File.join(spec.gem_dir, relative_config_path)
rescue Gem::LoadError => ex
rescue Gem::LoadError => e
raise Gem::LoadError,
"Unable to find gem #{gem_name}; is the gem installed? #{ex}"
"Unable to find gem #{gem_name}; is the gem installed? #{e}"
end
end
end
6 changes: 3 additions & 3 deletions lib/rubocop/cop/commissioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ def invoke_custom_processing(cops_or_forces, processed_source)
# cops' `#investigate` methods.
def with_cop_error_handling(cop, node = nil)
yield
rescue StandardError => ex
raise ex if @options[:raise_error]
rescue StandardError => e
raise e if @options[:raise_error]

if node
line = node.first_line
column = node.loc.column
end
error = CopError.new(ex, line, column)
error = CopError.new(e, line, column)
@errors[cop] << error
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Naming
# # bad
# begin
# # do something
# rescue MyException => exc
# rescue MyException => exception
# # do something
# end
#
Expand All @@ -35,7 +35,7 @@ module Naming
# # good
# begin
# # do something
# rescue MyException => ex
# rescue MyException => exception
# # do something
# end
#
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/path_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def match_path?(pattern, path)
when Regexp
begin
path =~ pattern
rescue ArgumentError => ex
return false if ex.message.start_with?('invalid byte sequence')
rescue ArgumentError => e
return false if e.message.start_with?('invalid byte sequence')

raise exception
raise e
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/processed_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def parse(source, ruby_version)

begin
@buffer.source = source
rescue EncodingError => ex
@parser_error = ex
rescue EncodingError => e
@parser_error = e
return
end

Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/remote_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def request(uri = @uri, limit = 10, &block)
generate_request(uri) do |request|
begin
handle_response(http.request(request), limit, &block)
rescue SocketError => ex
handle_response(ex, limit, &block)
rescue SocketError => e
handle_response(e, limit, &block)
end
end
end
Expand All @@ -72,10 +72,10 @@ def handle_response(response, limit, &block)
else
begin
response.error!
rescue StandardError => ex
message = "#{ex.message} while downloading remote config"\
rescue StandardError => e
message = "#{e.message} while downloading remote config"\
" file #{uri}"
raise ex, message
raise e, message
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/result_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def save(offenses)

begin
FileUtils.mkdir_p(dir)
rescue Errno::EACCES => ex
rescue Errno::EACCES => e
warn "Couldn't create cache directory. Continuing without cache."\
"\n #{ex.message}"
"\n #{e.message}"
return
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def process_file(file)
end
formatter_set.file_finished(file, offenses)
offenses
rescue InfiniteCorrectionLoop => ex
formatter_set.file_finished(file, ex.offenses.compact.sort.freeze)
rescue InfiniteCorrectionLoop => e
formatter_set.file_finished(file, e.offenses.compact.sort.freeze)
raise
end

Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/target_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,8 @@ def ruby_executable?(file)

first_line = File.open(file, &:readline)
!(first_line =~ /#!.*(#{ruby_interpreters(file).join('|')})/).nil?
rescue EOFError, ArgumentError => ex
if debug?
warn(
"Unprocessable file #{file}: #{ex.class}, #{ex.message}"
)
end
rescue EOFError, ArgumentError => e
warn("Unprocessable file #{file}: #{e.class}, #{e.message}") if debug?

false
end
Expand Down
6 changes: 3 additions & 3 deletions manual/cops_naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ the required name of the variable. Its default is `e`.
# bad
begin
# do something
rescue MyException => exc
rescue MyException => exception
# do something
end

Expand All @@ -521,7 +521,7 @@ end
# good
begin
# do something
rescue MyException => ex
rescue MyException => exception
# do something
end
```
Expand All @@ -530,7 +530,7 @@ end
Name | Default value | Configurable values
--- | --- | ---
PreferredName | `ex` | String
PreferredName | `e` | String
## Naming/UncommunicativeBlockParamName
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1602,9 +1602,9 @@ def method(foo, bar, qux, fred, arg5, f) end #{'#' * 45}
it 'shows an error if the input file cannot be found' do
begin
cli.run(%w[/tmp/not_a_file])
rescue SystemExit => ex
expect(ex.status).to eq(1)
expect(ex.message)
rescue SystemExit => e
expect(e.status).to eq(1)
expect(e.message)
.to eq 'rubocop: No such file or directory -- /tmp/not_a_file'
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/custom_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
match do |block|
begin
block.call
rescue SystemExit => ex
actual = ex.status
rescue SystemExit => e
actual = e.status
end
actual && actual == code
end
Expand Down

0 comments on commit d0677d7

Please sign in to comment.