Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support inline visibility definition on checking visibility
- Loading branch information
Showing
4 changed files
with
196 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#11171](https://github.com/rubocop/rubocop/pull/11171): Support inline visibility definition on checking visibility. ([@r7kamura][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::VisibilityHelp do | ||
describe '#node_visibility' do | ||
subject do | ||
instance.__send__(:node_visibility, node) | ||
end | ||
|
||
let(:instance) do | ||
klass.new | ||
end | ||
|
||
let(:klass) do | ||
mod = described_class | ||
Class.new do | ||
include mod | ||
end | ||
end | ||
|
||
let(:node) do | ||
processed_source.ast.each_node(:def).first | ||
end | ||
|
||
let(:processed_source) do | ||
parse_source(source) | ||
end | ||
|
||
let(:source) do | ||
raise NotImplementedError | ||
end | ||
|
||
context 'without visibility block' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:public) } | ||
end | ||
|
||
context 'with visibility block public' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
public | ||
def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:public) } | ||
end | ||
|
||
context 'with visibility block private' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
private | ||
def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:private) } | ||
end | ||
|
||
context 'with visibility block private after public' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
public | ||
private | ||
def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:private) } | ||
end | ||
|
||
context 'with inline public' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
public def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:public) } | ||
end | ||
|
||
context 'with inline private' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
private def x; end | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:private) } | ||
end | ||
|
||
context 'with inline private with symbol' do | ||
let(:source) do | ||
<<~RUBY | ||
class A | ||
def x; end | ||
private :x | ||
end | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq(:private) } | ||
end | ||
end | ||
end |