New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--auto-correct
stops with error when parsing invalid encoding file
#8590
Comments
Probably the file encoding is not If the result of % nkf --guess invalid_encoding.rb
UTF-8 (LF)
% nkf --overwrite -s invalid_encoding.rb
% nkf --guess invalid_encoding.rb
Shift_JIS (LF) Thank you. |
@koic Thank you for your comment. In the case of I think this parser error should be treated as fatal issue like How do you think? |
…h file Fixes rubocop#8590. This PR fixes the following error when auto-correcting encoding mismatch file. ```ruby % cat example.rb # encoding: Shift_JIS puts 'This file encoding is UTF-8.' ``` ## Before ```console % bundle exec rubocop --cache false -a (snip) Cannot extract source from uninitialized Source::Buffer /Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/parser-2.7.1.4/lib/ parser/source/buffer.rb:148:in `source' /Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/parser-2.7.1.4/lib/ parser/source/buffer.rb:297:in `source_range' /Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/parser-2.7.1.4/lib/ parser/source/tree_rewriter.rb:116:in `initialize' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/corrector.rb:18:in `initialize' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/team.rb:182:in `new' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/team.rb:182:in `collate_corrections' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/team.rb:176:in `autocorrect_report' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/team.rb:121:in `autocorrect' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/cop/team.rb:79:in `investigate' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:295:in `inspect_file' ``` ## After ```console % bundle exec rubocop --cache false -a (snip) Inspecting 1 file F Offenses: example.rb:1:1: F: Lint/Syntax: "\xef\xbc" from shift_jis to utf-8. 1 file inspected, 1 offense detected ```
Ah, get it. I've opened a PR #8591. |
[Fix #8590] Fix an error when auto-correcting encoding mismatch file
Thank you so much!! |
Expected behavior
shows offence as
Lint/Syntax
and inspect next file.Actual behavior
stops on parser error
Steps to reproduce the problem
rubocop --auto-correct ./invalid_encoding.rb
output
rubocop --cache false ./invalid_encoding.rb
shows:RuboCop version
The text was updated successfully, but these errors were encountered: