Skip to content

Commit

Permalink
[Fix rubocop#4124] Enable Style/SymbolArray cop by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Mar 19, 2017
1 parent 0fbd99a commit 23dffd8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@
* [#4020](https://github.com/bbatsov/rubocop/pull/4020): Fixed `new_cop.rake` suggested path. ([@dabroz][])
* [#4055](https://github.com/bbatsov/rubocop/pull/4055): Add parameters count to offense message for `Metrics/ParameterLists` cop. ([@pocke][])
* [#4081](https://github.com/bbatsov/rubocop/pull/4081): Allow `Marshal.load` if argument is a `Marshal.dump` in `Security/MarshalLoad` cop. ([@droptheplot][])
* [#4124](https://github.com/bbatsov/rubocop/issues/4124): Make `Style/SymbolArray` cop to enable by default. ([@pocke][])

### Bug fixes

Expand Down Expand Up @@ -64,6 +65,7 @@
* [#4084](https://github.com/bbatsov/rubocop/issues/4084): Fix incorrect auto correction in `Style/TernaryParentheses` cop. ([@musialik][])
* [#4102](https://github.com/bbatsov/rubocop/issues/4102): Fix `Security/JSONLoad`, `Security/MarshalLoad` and `Security/YAMLLoad` cops patterns not matching ::Const. ([@musialik][])
* [#3580](https://github.com/bbatsov/rubocop/issues/3580): Handle combinations of `# rubocop:disable all` and `# rubocop:disable SomeCop`. ([@jonas054][])
* [#4124](https://github.com/bbatsov/rubocop/issues/4124): Fix auto correction bugs in `Style/SymbolArray` cop. ([@pocke][])

## 0.47.1 (2017-01-18)

Expand Down
5 changes: 0 additions & 5 deletions config/disabled.yml
Expand Up @@ -114,11 +114,6 @@ Style/StringMethods:
Description: 'Checks if configured preferred methods are used over non-preferred.'
Enabled: false

Style/SymbolArray:
Description: 'Use %i or %I for arrays of symbols.'
StyleGuide: '#percent-i'
Enabled: false

Style/SingleLineBlockParams:
Description: 'Enforces the names of some block params.'
Enabled: false
5 changes: 5 additions & 0 deletions config/enabled.yml
Expand Up @@ -892,6 +892,11 @@ Style/StructInheritance:
StyleGuide: '#no-extend-struct-new'
Enabled: true

Style/SymbolArray:
Description: 'Use %i or %I for arrays of symbols.'
StyleGuide: '#percent-i'
Enabled: true

Style/SymbolLiteral:
Description: 'Use plain symbols instead of string symbols when possible.'
Enabled: true
Expand Down
18 changes: 17 additions & 1 deletion manual/cops_style.md
Expand Up @@ -5335,7 +5335,7 @@ Person = Struct.new(:first_name, :last_name)

Enabled by default | Supports autocorrection
--- | ---
Disabled | Yes
Enabled | Yes

This cop can check for array literals made up of symbols that are not
using the %i() syntax.
Expand All @@ -5344,6 +5344,22 @@ Alternatively, it checks for symbol arrays using the %i() syntax on
projects which do not want to use that syntax, perhaps because they
support a version of Ruby lower than 2.0.

# EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

# EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

### Important attributes

Attribute | Value
Expand Down
19 changes: 15 additions & 4 deletions spec/fixtures/html_formatter/expected.html
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">RuboCop Inspection Report</h1>
<div class="infobox">
<div class="total">
3 files inspected,
18 offenses detected:
19 offenses detected:
</div>
<ul class="offenses-list">

Expand All @@ -381,7 +381,7 @@ <h1 class="title">RuboCop Inspection Report</h1>

<li>
<a href="#offense_app/controllers/books_controller.rb">
app/controllers/books_controller.rb - 10 offenses
app/controllers/books_controller.rb - 11 offenses
</a>
</li>

Expand Down Expand Up @@ -432,7 +432,7 @@ <h1 class="title">RuboCop Inspection Report</h1>

<div class="offense-box" id="offense_app/controllers/books_controller.rb">
<div class="box-title-placeholder"><h3>&nbsp;</h3></div>
<div class="box-title"><h3>app/controllers/books_controller.rb - 10 offenses</h3></div>
<div class="box-title"><h3>app/controllers/books_controller.rb - 11 offenses</h3></div>
<div class="offense-reports">

<div class="report">
Expand All @@ -446,6 +446,17 @@ <h1 class="title">RuboCop Inspection Report</h1>

</div>

<div class="report">
<div class="meta">
<span class="location">Line #2</span>
<span class="severity convention">convention:</span>
<span class="message">Use <code>%i</code> or <code>%I</code> for an array of symbols.</span>
</div>

<pre><code> before_action :set_book, only: <span class="highlight convention">[:show, :edit, :update, :destroy]</span></code></pre>

</div>

<div class="report">
<div class="meta">
<span class="location">Line #12</span>
Expand Down Expand Up @@ -628,7 +639,7 @@ <h1 class="title">RuboCop Inspection Report</h1>
</div>
<footer>
Generated by <a href="https://github.com/bbatsov/rubocop">RuboCop</a>
<span class="version">0.39.0</span>
<span class="version">0.47.1</span>
</footer>
</body>
</html>
39 changes: 0 additions & 39 deletions spec/rubocop/config_loader_spec.rb
Expand Up @@ -597,45 +597,6 @@
end
end

describe 'configuration for SymbolArray', :isolated_environment do
let(:config) do
config_path = described_class.configuration_file_for('.')
described_class.configuration_from_file(config_path)
end

context 'when no config file exists for the target file' do
it 'is disabled' do
expect(
config.cop_enabled?(RuboCop::Cop::Style::SymbolArray)
).to be_falsey
end
end

context 'when a config file which does not mention SymbolArray exists' do
it 'is disabled' do
create_file('.rubocop.yml', [
'Metrics/LineLength:',
' Max: 80'
])
expect(
config.cop_enabled?(RuboCop::Cop::Style::SymbolArray)
).to be_falsey
end
end

context 'when a config file which explicitly enables SymbolArray exists' do
it 'is enabled' do
create_file('.rubocop.yml', [
'Style/SymbolArray:',
' Enabled: true'
])
expect(
config.cop_enabled?(RuboCop::Cop::Style::SymbolArray)
).to be_truthy
end
end
end

describe 'configuration for CharacterLiteral', :isolated_environment do
let(:dir_path) { 'test/blargh' }

Expand Down

0 comments on commit 23dffd8

Please sign in to comment.