Class: RuboCop::Cop::Layout::SpaceAroundKeyword
- Inherits:
-
Cop
- Object
- Cop
- RuboCop::Cop::Layout::SpaceAroundKeyword
show all
- Defined in:
- lib/rubocop/cop/layout/space_around_keyword.rb
Overview
Checks the spacing around the keywords.
Constant Summary
collapse
- MSG_BEFORE =
'Space before keyword `%<range>s` is missing.'
- MSG_AFTER =
'Space after keyword `%<range>s` is missing.'
- DO =
'do'
- SAFE_NAVIGATION =
'&.'
- NAMESPACE_OPERATOR =
'::'
- ACCEPT_LEFT_PAREN =
%w[break defined? next not rescue return super yield].freeze
- ACCEPT_LEFT_SQUARE_BRACKET =
%w[super yield].freeze
- ACCEPT_NAMESPACE_OPERATOR =
'super'
Constants included
from Util
Util::LITERAL_REGEX
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offenses, #processed_source
Instance Method Summary
collapse
Methods inherited from Cop
#add_offense, all, autocorrect_incompatible_with, badge, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, #cop_name, cop_name, #correct, department, #disable_uncorrectable, #duplicate_location?, #excluded_file?, #external_dependency_checksum, #find_location, #highlights, inherited, #initialize, #join_force?, lint?, match?, #message, #messages, #parse, qualified_cop_name, #reason_to_not_correct, #relevant_file?, #target_rails_version, #target_ruby_version
Methods included from AST::Sexp
#s
#def_node_matcher, #def_node_search, #node_search, #node_search_all, #node_search_body, #node_search_first
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #correctable?, #disable_offense, #disable_uncorrectable?, #safe_autocorrect?, #support_autocorrect?
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
begins_its_line?, comment_line?, double_quotes_required?, escape_string, first_part_of_call_chain, interpret_string_escapes, line_range, needs_escaping?, on_node, parentheses?, same_line?, to_string_literal, to_supported_styles, tokens, trim_string_interporation_escape_character
Methods included from PathUtil
absolute?, chdir, hidden_dir?, hidden_file_in_not_hidden_dir?, match_path?, pwd, relative_path, reset_pwd, smart_path
Instance Method Details
#autocorrect(range) ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 132
def autocorrect(range)
if space_before_missing?(range)
->(corrector) { corrector.insert_before(range, ' ') }
else
->(corrector) { corrector.insert_after(range, ' ') }
end
end
|
#on_and(node) ⇒ Object
40
41
42
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 40
def on_and(node)
check(node, [:operator].freeze) if node.keyword?
end
|
#on_block(node) ⇒ Object
44
45
46
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 44
def on_block(node)
check(node, %i[begin end].freeze)
end
|
#on_break(node) ⇒ Object
48
49
50
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 48
def on_break(node)
check(node, [:keyword].freeze)
end
|
#on_case(node) ⇒ Object
52
53
54
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 52
def on_case(node)
check(node, %i[keyword else].freeze)
end
|
#on_defined?(node) ⇒ Boolean
128
129
130
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 128
def on_defined?(node)
check(node, [:keyword].freeze)
end
|
#on_ensure(node) ⇒ Object
56
57
58
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 56
def on_ensure(node)
check(node, [:keyword].freeze)
end
|
#on_for(node) ⇒ Object
60
61
62
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 60
def on_for(node)
check(node, %i[begin end].freeze)
end
|
#on_if(node) ⇒ Object
64
65
66
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 64
def on_if(node)
check(node, %i[keyword else begin end].freeze, 'then')
end
|
#on_kwbegin(node) ⇒ Object
68
69
70
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 68
def on_kwbegin(node)
check(node, %i[begin end].freeze, nil)
end
|
#on_next(node) ⇒ Object
72
73
74
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 72
def on_next(node)
check(node, [:keyword].freeze)
end
|
#on_or(node) ⇒ Object
76
77
78
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 76
def on_or(node)
check(node, [:operator].freeze) if node.keyword?
end
|
#on_postexe(node) ⇒ Object
80
81
82
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 80
def on_postexe(node)
check(node, [:keyword].freeze)
end
|
#on_preexe(node) ⇒ Object
84
85
86
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 84
def on_preexe(node)
check(node, [:keyword].freeze)
end
|
#on_resbody(node) ⇒ Object
88
89
90
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 88
def on_resbody(node)
check(node, [:keyword].freeze)
end
|
#on_rescue(node) ⇒ Object
92
93
94
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 92
def on_rescue(node)
check(node, [:else].freeze)
end
|
#on_return(node) ⇒ Object
96
97
98
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 96
def on_return(node)
check(node, [:keyword].freeze)
end
|
#on_send(node) ⇒ Object
100
101
102
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 100
def on_send(node)
check(node, [:selector].freeze) if node.prefix_not?
end
|
#on_super(node) ⇒ Object
104
105
106
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 104
def on_super(node)
check(node, [:keyword].freeze)
end
|
#on_until(node) ⇒ Object
112
113
114
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 112
def on_until(node)
check(node, %i[begin end keyword].freeze)
end
|
#on_when(node) ⇒ Object
116
117
118
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 116
def on_when(node)
check(node, [:keyword].freeze)
end
|
#on_while(node) ⇒ Object
120
121
122
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 120
def on_while(node)
check(node, %i[begin end keyword].freeze)
end
|
#on_yield(node) ⇒ Object
124
125
126
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 124
def on_yield(node)
check(node, [:keyword].freeze)
end
|
#on_zsuper(node) ⇒ Object
108
109
110
|
# File 'lib/rubocop/cop/layout/space_around_keyword.rb', line 108
def on_zsuper(node)
check(node, [:keyword].freeze)
end
|