Skip to content
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

Rename enforced style for Layout/IndentationConsistency #7163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -20,7 +20,7 @@

* [#5976](https://github.com/rubocop-hq/rubocop/issues/5976): Remove Rails cops. ([@koic][])
* [#5976](https://github.com/rubocop-hq/rubocop/issues/5976): Remove `rubocop -R/--rails` option. ([@koic][])
* [#7113](https://github.com/rubocop-hq/rubocop/pull/7113): Rename `EnforcedStyle: rails` to `EnabledStyle: outdented_access_modifiers` for `Layout/IndentationConsistency`. ([@koic][])
* [#7113](https://github.com/rubocop-hq/rubocop/pull/7113): Rename `EnforcedStyle: rails` to `EnabledStyle: indented_internal_methods` for `Layout/IndentationConsistency`. ([@koic][])

## 0.71.0 (2019-05-30)

Expand Down
6 changes: 3 additions & 3 deletions config/default.yml
Expand Up @@ -770,7 +770,7 @@ Layout/IndentationConsistency:
StyleGuide: '#spaces-indentation'
Enabled: true
VersionAdded: '0.49'
# The difference between `indented` and `normal` is that the `outdented_access_modifiers`
# The difference between `indented` and `normal` is that the `indented_internal_methods`
# style prescribes that in classes and modules the `protected` and `private`
# modifier keywords shall be indented the same as public methods and that
# protected and private members shall be indented one step more than the
Expand All @@ -779,9 +779,9 @@ Layout/IndentationConsistency:
EnforcedStyle: normal
SupportedStyles:
- normal
- outdented_access_modifiers
- indented_internal_methods
Reference:
# A reference to `EnforcedStyle: outdented_access_modifiers`.
# A reference to `EnforcedStyle: indented_internal_methods`.
- https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions

Layout/IndentationWidth:
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/config.rb
Expand Up @@ -235,7 +235,7 @@ class Config
parameter: 'EnforcedStyle',
enforced_style: 'rails',
alternative: '`EnforcedStyle: rails` has been renamed to ' \
'`EnforcedStyle: outdented_access_modifiers`'
'`EnforcedStyle: indented_internal_methods`'
}
].freeze

Expand Down
14 changes: 7 additions & 7 deletions lib/rubocop/cop/layout/indentation_consistency.rb
Expand Up @@ -5,8 +5,8 @@ module Cop
module Layout
# This cop checks for inconsistent indentation.
#
# The difference between `outdented_access_modifiers` and `normal` is
# that the `outdented_access_modifiers` style prescribes that in
# The difference between `indented_internal_methods` and `normal` is
# that the `indented_internal_methods` style prescribes that in
# classes and modules the `protected` and `private` modifier keywords
# shall be indented the same as public methods and that protected and
# private members shall be indented one step more than the modifiers.
Expand Down Expand Up @@ -66,7 +66,7 @@ module Layout
# end
# end
#
# @example EnforcedStyle: outdented_access_modifiers
# @example EnforcedStyle: indented_internal_methods
# # bad
# class A
# def test
Expand Down Expand Up @@ -167,8 +167,8 @@ def base_column_for_normal_style(node)
end

def check(node)
if style == :outdented_access_modifiers
check_outdented_access_modifiers_style(node)
if style == :indented_internal_methods
check_indented_internal_methods_style(node)
else
check_normal_style(node)
end
Expand All @@ -181,12 +181,12 @@ def check_normal_style(node)
)
end

def check_outdented_access_modifiers_style(node)
def check_indented_internal_methods_style(node)
children_to_check = [[]]
node.children.each do |child|
# Modifier nodes have special indentation and will be checked by
# the AccessModifierIndentation cop. This cop uses them as dividers
# in outdented_access_modifiers mode. Then consistency is checked
# in indented_internal_methods mode. Then consistency is checked
# only within each section delimited by a modifier node.
if bare_access_modifier?(child)
children_to_check << []
Expand Down
12 changes: 6 additions & 6 deletions lib/rubocop/cop/layout/indentation_width.rb
Expand Up @@ -83,7 +83,7 @@ def on_block(node)

check_indentation(end_loc, node.body)

return unless outdented_access_modifiers_style?
return unless indented_internal_methods_style?

check_members(end_loc, [node.body])
end
Expand Down Expand Up @@ -155,8 +155,8 @@ def check_members(base, members)

return unless members.any? && members.first.begin_type?

if indentation_consistency_style == 'outdented_access_modifiers'
check_members_for_outdented_access_modifiers_style(members)
if indentation_consistency_style == 'indented_internal_methods'
check_members_for_indented_internal_methods_style(members)
else
members.first.children.each do |member|
next if member.send_type? && member.access_modifier?
Expand All @@ -176,7 +176,7 @@ def select_check_member(member)
end
end

def check_members_for_outdented_access_modifiers_style(members)
def check_members_for_indented_internal_methods_style(members)
each_member(members) do |member, previous_modifier|
check_indentation(previous_modifier, member,
indentation_consistency_style)
Expand All @@ -195,8 +195,8 @@ def each_member(members)
end
end

def outdented_access_modifiers_style?
indentation_consistency_style == 'outdented_access_modifiers'
def indented_internal_methods_style?
indentation_consistency_style == 'indented_internal_methods'
end

def indentation_consistency_style
Expand Down
8 changes: 4 additions & 4 deletions manual/cops_layout.md
Expand Up @@ -2654,8 +2654,8 @@ Enabled | Yes | Yes | 0.49 | -

This cop checks for inconsistent indentation.

The difference between `outdented_access_modifiers` and `normal` is
that the `outdented_access_modifiers` style prescribes that in
The difference between `indented_internal_methods` and `normal` is
that the `indented_internal_methods` style prescribes that in
classes and modules the `protected` and `private` modifier keywords
shall be indented the same as public methods and that protected and
private members shall be indented one step more than the modifiers.
Expand Down Expand Up @@ -2719,7 +2719,7 @@ class A
end
end
```
#### EnforcedStyle: outdented_access_modifiers
#### EnforcedStyle: indented_internal_methods

```ruby
# bad
Expand Down Expand Up @@ -2779,7 +2779,7 @@ end

Name | Default value | Configurable values
--- | --- | ---
EnforcedStyle | `normal` | `normal`, `outdented_access_modifiers`
EnforcedStyle | `normal` | `normal`, `indented_internal_methods`

### References

Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cli/cli_auto_gen_config_spec.rb
Expand Up @@ -522,7 +522,7 @@ def a; end
'# Offense count: 2',
'# Cop supports --auto-correct.',
'# Configuration parameters: EnforcedStyle.',
'# SupportedStyles: normal, outdented_access_modifiers',
'# SupportedStyles: normal, indented_internal_methods',
'Layout/IndentationConsistency:',
' Exclude:',
" - 'example2.rb'",
Expand Down Expand Up @@ -619,7 +619,7 @@ def a; end
'# Offense count: 1',
'# Cop supports --auto-correct.',
'# Configuration parameters: EnforcedStyle.',
'# SupportedStyles: normal, outdented_access_modifiers',
'# SupportedStyles: normal, indented_internal_methods',
'Layout/IndentationConsistency:',
' Exclude:',
" - 'example2.rb'",
Expand Down Expand Up @@ -709,7 +709,7 @@ def a; end
'# Offense count: 1',
'# Cop supports --auto-correct.',
'# Configuration parameters: EnforcedStyle.',
'# SupportedStyles: normal, outdented_access_modifiers',
'# SupportedStyles: normal, indented_internal_methods',
'Layout/IndentationConsistency:',
' Exclude:',
" - 'example2.rb'",
Expand Down Expand Up @@ -824,7 +824,7 @@ def a; end
'',
'# Cop supports --auto-correct.',
'# Configuration parameters: EnforcedStyle.',
'# SupportedStyles: normal, outdented_access_modifiers',
'# SupportedStyles: normal, indented_internal_methods',
'Layout/IndentationConsistency:',
' Exclude:',
" - 'example2.rb'",
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cli_spec.rb
Expand Up @@ -631,12 +631,12 @@ def and_with_args
end
end

context 'when configured for outdented_access_modifiers style ' \
context 'when configured for indented_internal_methods style ' \
'indentation' do
it 'accepts outdented_access_modifiers style indentation' do
it 'accepts indented_internal_methods style indentation' do
create_file('.rubocop.yml', <<~YAML)
Layout/IndentationConsistency:
EnforcedStyle: outdented_access_modifiers
EnforcedStyle: indented_internal_methods
Style/FrozenStringLiteralComment:
Enabled: false
YAML
Expand Down Expand Up @@ -672,7 +672,7 @@ def meow_at_3am?
it "registers offense for normal indentation in #{parent}" do
create_file('.rubocop.yml', <<~YAML)
Layout/IndentationConsistency:
EnforcedStyle: outdented_access_modifiers
EnforcedStyle: indented_internal_methods
Style/FrozenStringLiteralComment:
Enabled: false
YAML
Expand Down Expand Up @@ -706,8 +706,8 @@ def meow_at_4am?
expect($stdout.string)
.to eq(<<~RESULT)
== example.rb ==
C: 9: 3: Layout/IndentationWidth: Use 2 (not 0) spaces for outdented_access_modifiers indentation.
C: 15: 3: Layout/IndentationWidth: Use 2 (not 0) spaces for outdented_access_modifiers indentation.
C: 9: 3: Layout/IndentationWidth: Use 2 (not 0) spaces for indented_internal_methods indentation.
C: 15: 3: Layout/IndentationWidth: Use 2 (not 0) spaces for indented_internal_methods indentation.

1 file inspected, 2 offenses detected
RESULT
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/layout/indentation_consistency_spec.rb
Expand Up @@ -416,8 +416,8 @@ def self.test
end

context 'with class' do
context 'with outdented_access_modifiers style configured' do
let(:cop_config) { { 'EnforcedStyle' => 'outdented_access_modifiers' } }
context 'with indented_internal_methods style configured' do
let(:cop_config) { { 'EnforcedStyle' => 'indented_internal_methods' } }

it 'accepts different indentation in different visibility sections' do
expect_no_offenses(<<~RUBY)
Expand All @@ -439,7 +439,7 @@ def related_to?(another_cat)
private

# Here we go back an indentation level again. This is a
# violation of the outdented_access_modifiers style,
# violation of the indented_internal_methods style,
# but it's not for this cop to report.
# Layout/IndentationWidth will handle it.
def meow_at_3am?
Expand Down
32 changes: 16 additions & 16 deletions spec/rubocop/cop/layout/indentation_width_spec.rb
Expand Up @@ -16,8 +16,8 @@
let(:def_end_alignment_config) do
{ 'Enabled' => true, 'EnforcedStyleAlignWith' => 'start_of_line' }
end
let(:outdented_access_modifiers_offense_message) do
'Use 2 (not 0) spaces for outdented_access_modifiers indentation.'
let(:indented_internal_methods_offense_message) do
'Use 2 (not 0) spaces for indented_internal_methods indentation.'
end

context 'with Width set to 4' do
Expand Down Expand Up @@ -1131,7 +1131,7 @@ def g
RUBY
end

it 'registers offenses for outdented_access_modifiers indentation' do
it 'registers offenses for indented_internal_methods indentation' do
expect_offense(<<~RUBY)
class Test
def e
Expand All @@ -1153,12 +1153,12 @@ def g
end
end

context 'when consistency style is outdented_access_modifiers' do
context 'when consistency style is indented_internal_methods' do
let(:consistency_config) do
{ 'EnforcedStyle' => 'outdented_access_modifiers' }
{ 'EnforcedStyle' => 'indented_internal_methods' }
end

it 'registers an offense for normal non-outdented access modifiers ' \
it 'registers an offense for normal non-indented internal methods ' \
'indentation' do
inspect_source(<<~RUBY)
class Test
Expand All @@ -1179,11 +1179,11 @@ def g
end
RUBY
expect(cop.messages)
.to eq([outdented_access_modifiers_offense_message] * 2)
.to eq([indented_internal_methods_offense_message] * 2)
expect(cop.offenses.map(&:line)).to eq([9, 14])
end

it 'registers an offense for normal non-outdented access modifiers ' \
it 'registers an offense for normal non-indented internal methods ' \
'indentation when defined in a singleton class' do
inspect_source(<<~RUBY)
class << self
Expand All @@ -1205,7 +1205,7 @@ def g
RUBY

expect(cop.messages)
.to eq([outdented_access_modifiers_offense_message] * 2)
.to eq([indented_internal_methods_offense_message] * 2)
expect(cop.offenses.map(&:line)).to eq([9, 14])
end
end
Expand All @@ -1231,9 +1231,9 @@ module Test
end
end

context 'when consistency style is outdented_access_modifiers' do
context 'when consistency style is indented_internal_methods' do
let(:consistency_config) do
{ 'EnforcedStyle' => 'outdented_access_modifiers' }
{ 'EnforcedStyle' => 'indented_internal_methods' }
end

it 'registers an offense for bad indentation of a module body' do
Expand All @@ -1244,13 +1244,13 @@ def func1
end
private
def func2
^ Use 2 (not -1) spaces for outdented_access_modifiers indentation.
^ Use 2 (not -1) spaces for indented_internal_methods indentation.
end
end
RUBY
end

it 'accepts normal non-outdented access modifiers indentation of ' \
it 'accepts normal non-indented internal methods of' \
'module functions' do
expect_no_offenses(<<~RUBY)
module Test
Expand Down Expand Up @@ -1320,9 +1320,9 @@ def my_func
end

context 'with block' do
context 'when consistency style is outdented_access_modifiers' do
context 'when consistency style is indented_internal_methods' do
let(:consistency_config) do
{ 'EnforcedStyle' => 'outdented_access_modifiers' }
{ 'EnforcedStyle' => 'indented_internal_methods' }
end

it 'registers an offense for bad indentation in a do/end body' do
Expand All @@ -1340,7 +1340,7 @@ def bar
end
RUBY
expect(cop.messages)
.to eq([outdented_access_modifiers_offense_message])
.to eq([indented_internal_methods_offense_message])
end
end

Expand Down