Skip to content

Commit

Permalink
Merge pull request #8591 from koic/fix_an_error_when_autocorrecting
Browse files Browse the repository at this point in the history
[Fix #8590] Fix an error when auto-correcting encoding mismatch file
  • Loading branch information
koic committed Aug 26, 2020
2 parents dea6296 + 7315ad0 commit e3c930d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -28,6 +28,7 @@
* [#8518](https://github.com/rubocop-hq/rubocop/issues/8518): Fix `Lint/ConstantResolution` cop reporting offense for `module` and `class` definitions. ([@tejasbubane][])
* [#8158](https://github.com/rubocop-hq/rubocop/issues/8158): Fix `Style/MultilineWhenThen` cop to correctly handle cases with multiline body. ([@dsavochkin][])
* [#7705](https://github.com/rubocop-hq/rubocop/issues/7705): Fix `Style/OneLineConditional` cop to handle if/then/elsif/then/else/end cases. Add `AlwaysCorrectToMultiline` config option to this cop to always convert offenses to the multi-line form (false by default). ([@Lykos][], [@dsavochkin][])
* [#8590](https://github.com/rubocop-hq/rubocop/issues/8590): Fix an error when auto-correcting encoding mismatch file. ([@koic][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/team.rb
Expand Up @@ -117,6 +117,7 @@ def external_dependency_checksum
def autocorrect(processed_source, report)
@updated_source_file = false
return unless autocorrect?
return if report.processed_source.parser_error

new_source = autocorrect_report(report)

Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/team_spec.rb
Expand Up @@ -156,6 +156,24 @@ def a
end
end

context 'when autocorrection is enabled and file encoding is mismatch' do
let(:options) { { auto_correct: true } }

before do
create_file(file_path, <<~RUBY)
# encoding: Shift_JIS
puts 'This file encoding is UTF-8.'
RUBY
end

it 'no error occurs' do
source = RuboCop::ProcessedSource.from_file(file_path, ruby_version)
team.inspect_file(source)

expect(team.errors.empty?).to be(true)
end
end

context 'when Cop#on_* raises an error' do
include_context 'mock console output'
before do
Expand Down

0 comments on commit e3c930d

Please sign in to comment.