Skip to content

Commit

Permalink
Enable Style/Encoding by default
Browse files Browse the repository at this point in the history
This cop was made a disabled by default cop back when Ruby 1.9 was still
supported and there was no `never` enforced style. This is not the case
any more, so we can start making sure that projects do not include
unnecessary encoding magic comments by default.
  • Loading branch information
deivid-rodriguez authored and bbatsov committed May 30, 2017
1 parent 17034e7 commit 5faf140
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
4 changes: 0 additions & 4 deletions .rubocop.yml
Expand Up @@ -10,10 +10,6 @@ AllCops:
- 'tmp/**/*'
TargetRubyVersion: 2.0

Style/Encoding:
EnforcedStyle: never
Enabled: true

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@

* [#4443](https://github.com/bbatsov/rubocop/pull/4443): Prevent `Style/YodaCondition` from breaking `not LITERAL`. ([@pocke][])

### Changes

* [#4444](https://github.com/bbatsov/rubocop/pull/4444): Make `Style/Encoding` cop enabled by default. ([@deivid-rodriguez][])

## 0.49.1 (2017-05-29)

### Bug fixes
Expand Down
5 changes: 0 additions & 5 deletions config/disabled.yml
Expand Up @@ -59,11 +59,6 @@ Style/DocumentationMethod:
- 'spec/**/*'
- 'test/**/*'

Style/Encoding:
Description: 'Use UTF-8 as the source file encoding.'
StyleGuide: '#utf-8'
Enabled: false

Style/ImplicitRuntimeError:
Description: >-
Use `raise` or `fail` with an explicit exception class and
Expand Down
5 changes: 5 additions & 0 deletions config/enabled.yml
Expand Up @@ -514,6 +514,11 @@ Style/EndBlock:
StyleGuide: '#no-END-blocks'
Enabled: true

Style/Encoding:
Description: 'Use UTF-8 as the source file encoding.'
StyleGuide: '#utf-8'
Enabled: true

Style/EvenOdd:
Description: 'Favor the use of Integer#even? && Integer#odd?'
StyleGuide: '#predicate-methods'
Expand Down
2 changes: 1 addition & 1 deletion manual/cops_style.md
Expand Up @@ -1021,7 +1021,7 @@ SupportedStyles | compact, expanded
Enabled by default | Supports autocorrection
--- | ---
Disabled | Yes
Enabled | Yes
This cop checks whether the source file has a utf-8 encoding
comment or not.
Expand Down
2 changes: 1 addition & 1 deletion spec/isolated_environment_spec.rb
Expand Up @@ -12,7 +12,7 @@
# rspec.
it 'is not affected by a config file above the work directory' do
create_file('../.rubocop.yml', ['inherit_from: missing_file.yml'])
create_file('ex.rb', ['# encoding: utf-8'])
create_file('ex.rb', ['# frozen_string_literal: true'])
# A return value of 0 means that the erroneous config file was not read.
expect(cli.run([])).to eq(0)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cli/cli_auto_gen_config_spec.rb
Expand Up @@ -88,7 +88,7 @@
'y ',
'puts x'])
create_file('example2.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
\tx = 0
puts x
Expand Down Expand Up @@ -193,7 +193,7 @@ def a; end
'#' * 85,
'y ',
'puts x'])
create_file('example2.rb', ['# encoding: utf-8',
create_file('example2.rb', ['# frozen_string_literal: true',
'',
'#' * 85,
"\tx = 0",
Expand Down Expand Up @@ -272,13 +272,13 @@ def a; end

it 'does not generate configuration for the Syntax cop' do
create_file('example1.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
x = < # Syntax error
puts x
END
create_file('example2.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
\tx = 0
puts x
Expand Down Expand Up @@ -376,7 +376,7 @@ def a; end
'y ',
'puts x'])
create_file('example2.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
\tx = 0
puts x
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cli/cli_autocorrect_spec.rb
Expand Up @@ -1088,14 +1088,14 @@ def primes(limit)

it 'can correct TrailingBlankLines and TrailingWhitespace offenses' do
create_file('example.rb',
['# encoding: utf-8',
['# frozen_string_literal: true',
'',
' ',
'',
''])
expect(cli.run(%w[--auto-correct --format emacs])).to eq(0)
expect(IO.read('example.rb')).to eq(<<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
END
expect($stdout.string)
.to eq(["#{abs('example.rb')}:2:1: C: [Corrected] 3 trailing " \
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -787,7 +787,7 @@ def 文
'y ',
'puts x'])
create_file('example2.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
\tx
def a
Expand Down Expand Up @@ -822,8 +822,8 @@ def badName
' ^',
'example2.rb:1:1: C: Incorrect indentation detected' \
' (column 0 instead of 1).',
'# encoding: utf-8',
'^^^^^^^^^^^^^^^^^',
'# frozen_string_literal: true',
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^',
'example2.rb:3:1: C: Tab detected.',
"\tx",
'^',
Expand Down Expand Up @@ -863,13 +863,13 @@ def badName

context 'when emacs format is specified' do
it 'outputs with emacs format' do
create_file('example1.rb', ['# encoding: utf-8',
create_file('example1.rb', ['# frozen_string_literal: true',
'',
'x= 0 ',
'y ',
'puts x'])
create_file('example2.rb', <<-END.strip_indent)
# encoding: utf-8
# frozen_string_literal: true
\tx = 0
puts x
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/formatter/base_formatter_spec.rb
Expand Up @@ -15,7 +15,7 @@ module Formatter

create_file('4_offenses.rb', ['puts x ', 'test;', 'top;', '#' * 90])

create_file('no_offense.rb', '# encoding: utf-8')
create_file('no_offense.rb', '# frozen_string_literal: true')

allow(SimpleTextFormatter).to receive(:new).and_return(formatter)
$stdout = StringIO.new
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/runner_spec.rb
Expand Up @@ -21,7 +21,7 @@ class Runner
subject(:runner) { described_class.new(options, RuboCop::ConfigStore.new) }
context 'if there are no offenses in inspected files' do
let(:source) { <<-END.strip_indent }
# coding: utf-8
# frozen_string_literal: true
def valid_code; end
END
Expand All @@ -33,7 +33,7 @@ def valid_code; end

context 'if there is an offense in an inspected file' do
let(:source) { <<-END.strip_indent }
# coding: utf-8
# frozen_string_literal: true
def INVALID_CODE; end
END
Expand Down Expand Up @@ -92,7 +92,7 @@ def INVALID_CODE; end
{
formatters: [['progress', formatter_output_path]],
stdin: <<-END.strip_indent
# coding: utf-8
# frozen_string_literal: true
def INVALID_CODE; end
END
Expand Down Expand Up @@ -146,7 +146,7 @@ def mobilized_cop_classes(_config)

context 'if there is an offense in an inspected file' do
let(:source) { <<-END.strip_indent }
# coding: utf-8
# frozen_string_literal: true
class Klass
end
END
Expand Down

0 comments on commit 5faf140

Please sign in to comment.