rubocop 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -10
- data/.travis.yml +2 -1
- data/CHANGELOG.md +55 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/config/default.yml +99 -16
- data/config/enabled.yml +28 -16
- data/lib/rubocop.rb +16 -2
- data/lib/rubocop/cli.rb +10 -91
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/config_loader.rb +18 -10
- data/lib/rubocop/config_store.rb +3 -2
- data/lib/rubocop/cop/check_assignment.rb +43 -0
- data/lib/rubocop/cop/check_methods.rb +18 -0
- data/lib/rubocop/cop/commissioner.rb +15 -3
- data/lib/rubocop/cop/cop.rb +51 -43
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +7 -7
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +56 -19
- data/lib/rubocop/cop/lint/end_in_method.rb +4 -10
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -16
- data/lib/rubocop/cop/lint/void.rb +5 -5
- data/lib/rubocop/cop/rails/default_scope.rb +33 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -4
- data/lib/rubocop/cop/rails/output.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +31 -16
- data/lib/rubocop/cop/style/accessor_method_name.rb +53 -0
- data/lib/rubocop/cop/style/alias.rb +14 -2
- data/lib/rubocop/cop/style/align_hash.rb +15 -16
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/array_syntax.rb +22 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -3
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +13 -12
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +5 -1
- data/lib/rubocop/cop/style/blocks.rb +4 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +48 -22
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +25 -6
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_length.rb +7 -19
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/code_length.rb +35 -0
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +51 -0
- data/lib/rubocop/cop/style/configurable_max.rb +17 -0
- data/lib/rubocop/cop/style/configurable_naming.rb +4 -10
- data/lib/rubocop/cop/style/constant_name.rb +5 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +8 -13
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -43
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +6 -2
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +5 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +28 -13
- data/lib/rubocop/cop/style/empty_literal.rb +3 -3
- data/lib/rubocop/cop/style/encoding.rb +5 -5
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +8 -6
- data/lib/rubocop/cop/style/even_odd.rb +6 -6
- data/lib/rubocop/cop/style/favor_join.rb +1 -1
- data/lib/rubocop/cop/style/favor_modifier.rb +20 -34
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +1 -1
- data/lib/rubocop/cop/style/flip_flop.rb +20 -0
- data/lib/rubocop/cop/style/for.rb +34 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/hash_methods.rb +3 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +8 -11
- data/lib/rubocop/cop/style/if_node.rb +25 -0
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +77 -43
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +4 -12
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +9 -5
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +52 -0
- data/lib/rubocop/cop/style/method_length.rb +9 -22
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +11 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +54 -0
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -10
- data/lib/rubocop/cop/style/redundant_begin.rb +5 -15
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -19
- data/lib/rubocop/cop/style/redundant_self.rb +8 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +4 -3
- data/lib/rubocop/cop/style/rescue_modifier.rb +9 -17
- data/lib/rubocop/cop/style/semicolon.rb +20 -22
- data/lib/rubocop/cop/style/signal_exception.rb +10 -17
- data/lib/rubocop/cop/style/single_line_block_params.rb +62 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +5 -15
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +4 -12
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_braces.rb +105 -94
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/style/space_around_operators.rb +38 -123
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_inside.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +5 -5
- data/lib/rubocop/cop/style/space_inside_parens.rb +0 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_help.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -11
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +3 -10
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +4 -14
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +3 -1
- data/lib/rubocop/cop/style/while_until_do.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +4 -10
- data/lib/rubocop/cop/util.rb +85 -12
- data/lib/rubocop/cop/variable_inspector.rb +4 -2
- data/lib/rubocop/file_inspector.rb +98 -0
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +10 -2
- data/lib/rubocop/rake_task.rb +5 -1
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +12 -0
- data/rubocop.gemspec +1 -1
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/rubocop/cli_spec.rb +120 -27
- data/spec/rubocop/config_loader_spec.rb +25 -11
- data/spec/rubocop/config_spec.rb +25 -9
- data/spec/rubocop/config_store_spec.rb +1 -1
- data/spec/rubocop/cop/cop_spec.rb +22 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +4 -4
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +79 -47
- data/spec/rubocop/cop/lint/syntax_spec.rb +4 -3
- data/spec/rubocop/cop/rails/default_scope_spec.rb +31 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +37 -2
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +10 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +3 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +83 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +227 -71
- data/spec/rubocop/cop/style/class_length_spec.rb +2 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +6 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +1 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +12 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +10 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +22 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +6 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -0
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +15 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +96 -18
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +8 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +185 -20
- data/spec/rubocop/cop/style/line_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +72 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +16 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +34 -3
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +15 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +5 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +16 -16
- data/spec/rubocop/cop/style/{reduce_arguments_spec.rb → single_line_block_params_spec.rb} +12 -4
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +58 -8
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +71 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +18 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +2 -2
- data/spec/rubocop/processed_source_spec.rb +7 -3
- data/spec/rubocop/token_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/isolated_environment.rb +7 -0
- data/spec/support/shared_context.rb +5 -1
- metadata +35 -12
- data/lib/rubocop/cop/style/reduce_arguments.rb +0 -34
- data/lib/rubocop/cop/style/symbol_name.rb +0 -45
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +0 -33
- data/spec/rubocop/cop/style/symbol_name_spec.rb +0 -138
@@ -16,7 +16,7 @@ module Rubocop
|
|
16
16
|
index = index_of_first_token(optarg)
|
17
17
|
arg, equals, value = processed_source.tokens[index, 3]
|
18
18
|
unless space_between?(arg, equals) && space_between?(equals, value)
|
19
|
-
|
19
|
+
add_offence(equals.pos, equals.pos)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -6,150 +6,65 @@ module Rubocop
|
|
6
6
|
# Checks that operators have space around them, except for **
|
7
7
|
# which should not have surrounding space.
|
8
8
|
class SpaceAroundOperators < Cop
|
9
|
-
|
10
|
-
|
11
|
-
MSG_DETECTED = 'Space around operator ** detected.'
|
9
|
+
TYPES = %w(and or class
|
10
|
+
op_asgn and_asgn or_asgn masgn casgn lvasgn ivasgn gvasgn)
|
12
11
|
|
13
|
-
|
14
|
-
BINARY_OPERATORS =
|
15
|
-
[:tEQL, :tAMPER2, :tPIPE, :tCARET, :tPLUS, :tMINUS, :tSTAR2,
|
16
|
-
:tDIVIDE, :tPERCENT, :tEH, :tCOLON, :tANDOP, :tOROP, :tMATCH,
|
17
|
-
:tNMATCH, :tEQ, :tNEQ, :tGT, :tRSHFT, :tGEQ, :tLT,
|
18
|
-
:tLSHFT, :tLEQ, :tASSOC, :tEQQ, :tCMP, :tOP_ASGN]
|
12
|
+
TYPES.each { |t| define_method(:"on_#{t}") { |node| check(node) } }
|
19
13
|
|
20
|
-
def
|
21
|
-
|
22
|
-
@processed_source = processed_source
|
23
|
-
tokens = processed_source.tokens
|
24
|
-
tokens.each_cons(3) do |token_before, token, token_after|
|
25
|
-
next if token_before.type == :kDEF # TODO: remove?
|
26
|
-
next if token_before.type == :tDOT # Called as method.
|
27
|
-
next if positions_not_to_check.include?(token.pos)
|
28
|
-
|
29
|
-
case token.type
|
30
|
-
when :tPOW, :tDSTAR
|
31
|
-
if space_on_any_side?(token_before, token, token_after)
|
32
|
-
convention(token_with_surrounding_space(token), token.pos,
|
33
|
-
MSG_DETECTED)
|
34
|
-
end
|
35
|
-
when *BINARY_OPERATORS
|
36
|
-
check_missing_space(token_before, token, token_after)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns an array of positions marking the tokens that this cop
|
42
|
-
# should not check, either because the token is not an operator
|
43
|
-
# or because another cop does the check.
|
44
|
-
def positions_not_to_check
|
45
|
-
@positions_not_to_check ||= begin
|
46
|
-
positions = []
|
47
|
-
positions.concat(do_not_check_block_arg_pipes)
|
48
|
-
positions.concat(do_not_check_param_default)
|
49
|
-
positions.concat(do_not_check_class_lshift_self)
|
50
|
-
positions.concat(do_not_check_def_things)
|
51
|
-
positions.concat(do_not_check_singleton_operator_defs)
|
52
|
-
positions
|
53
|
-
end
|
14
|
+
def on_pair(node)
|
15
|
+
check(node) if node.loc.operator.is?('=>')
|
54
16
|
end
|
55
17
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
on_node(:block, @processed_source.ast) do |b|
|
61
|
-
on_node(:args, b) do |a|
|
62
|
-
positions << a.loc.begin << a.loc.end if a.loc.begin
|
63
|
-
end
|
18
|
+
def on_if(node)
|
19
|
+
if node.loc.respond_to?(:question)
|
20
|
+
check_operator(node.loc.question)
|
21
|
+
check_operator(node.loc.colon)
|
64
22
|
end
|
65
|
-
positions
|
66
23
|
end
|
67
24
|
|
68
|
-
def
|
69
|
-
|
70
|
-
# ^
|
71
|
-
positions = []
|
72
|
-
tokens = @processed_source.tokens
|
73
|
-
on_node(:optarg, @processed_source.ast) do |optarg|
|
74
|
-
_arg, equals, _value = tokens[index_of_first_token(optarg),
|
75
|
-
3]
|
76
|
-
positions << equals.pos
|
77
|
-
end
|
78
|
-
positions
|
25
|
+
def on_resbody(node)
|
26
|
+
check_operator(node.loc.assoc) if node.loc.assoc
|
79
27
|
end
|
80
28
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
ix = index_of_first_token(sclass)
|
88
|
-
if tokens[ix, 2].map(&:type) == [:kCLASS, :tLSHFT]
|
89
|
-
positions << tokens[ix + 1].pos
|
90
|
-
end
|
29
|
+
def on_send(node)
|
30
|
+
if node.loc.operator
|
31
|
+
check(node)
|
32
|
+
elsif !unary_operation?(node) && !called_with_dot?(node)
|
33
|
+
op = node.loc.selector
|
34
|
+
check_operator(op) if operator?(op)
|
91
35
|
end
|
92
|
-
positions
|
93
36
|
end
|
94
37
|
|
95
|
-
|
96
|
-
# def +(other)
|
97
|
-
# ^
|
98
|
-
positions = []
|
99
|
-
tokens = @processed_source.tokens
|
100
|
-
on_node(:def, @processed_source.ast) do |def_node|
|
101
|
-
# def each &block
|
102
|
-
# ^
|
103
|
-
# def each *args
|
104
|
-
# ^
|
105
|
-
on_node([:blockarg, :restarg], def_node) do |arg_node|
|
106
|
-
positions << tokens[index_of_first_token(arg_node)].pos
|
107
|
-
end
|
108
|
-
positions << tokens[index_of_first_token(def_node) + 1].pos
|
109
|
-
end
|
110
|
-
positions
|
111
|
-
end
|
38
|
+
private
|
112
39
|
|
113
|
-
def
|
114
|
-
|
115
|
-
# ^
|
116
|
-
positions = []
|
117
|
-
tokens = @processed_source.tokens
|
118
|
-
on_node(:defs, @processed_source.ast) do |defs_node|
|
119
|
-
_receiver, name, _args = *defs_node
|
120
|
-
ix = index_of_first_token(defs_node)
|
121
|
-
name_token = tokens[ix..-1].find { |t| t.text == name.to_s }
|
122
|
-
positions << name_token.pos
|
123
|
-
end
|
124
|
-
positions
|
40
|
+
def operator?(range)
|
41
|
+
range.source !~ /^\[|\w/
|
125
42
|
end
|
126
43
|
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
convention(token_with_surrounding_space(token), token.pos,
|
131
|
-
MSG_MISSING.format(text))
|
132
|
-
end
|
44
|
+
def unary_operation?(node)
|
45
|
+
whole, selector = node.loc.expression, node.loc.selector
|
46
|
+
operator?(selector) && whole.begin_pos == selector.begin_pos
|
133
47
|
end
|
134
48
|
|
135
|
-
def
|
136
|
-
|
137
|
-
begin_pos = token.pos.begin_pos
|
138
|
-
begin_pos -= 1 while src[begin_pos - 1] =~ /[ \t]/
|
139
|
-
end_pos = token.pos.end_pos
|
140
|
-
end_pos += 1 while src[end_pos] =~ /[ \t]/
|
141
|
-
Parser::Source::Range.new(@processed_source.buffer, begin_pos,
|
142
|
-
end_pos)
|
49
|
+
def called_with_dot?(node)
|
50
|
+
!!node.loc.dot
|
143
51
|
end
|
144
52
|
|
145
|
-
def
|
146
|
-
|
147
|
-
token_after)
|
53
|
+
def check(node)
|
54
|
+
check_operator(node.loc.operator) if node.loc.operator
|
148
55
|
end
|
149
56
|
|
150
|
-
def
|
151
|
-
|
152
|
-
|
57
|
+
def check_operator(op)
|
58
|
+
with_space = range_with_surrounding_space(op)
|
59
|
+
if op.is?('**')
|
60
|
+
unless with_space.is?('**')
|
61
|
+
add_offence(with_space, op, 'Space around operator ** detected.')
|
62
|
+
end
|
63
|
+
elsif with_space.source !~ /^\s.*\s$/
|
64
|
+
add_offence(with_space, op,
|
65
|
+
'Surrounding space missing for operator' +
|
66
|
+
" '#{op.source}'.")
|
67
|
+
end
|
153
68
|
end
|
154
69
|
|
155
70
|
def autocorrect(range)
|
@@ -12,7 +12,7 @@ module Rubocop
|
|
12
12
|
kw = node.loc.keyword
|
13
13
|
b = kw.begin_pos
|
14
14
|
left_of_kw = Parser::Source::Range.new(kw.source_buffer, b - 1, b)
|
15
|
-
|
15
|
+
add_offence(node, left_of_kw) unless left_of_kw.is?(' ')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# rubocop:disable SymbolName
|
4
|
-
|
5
3
|
module Rubocop
|
6
4
|
module Cop
|
7
5
|
module Style
|
@@ -20,7 +18,7 @@ module Rubocop
|
|
20
18
|
range = Parser::Source::Range.new(processed_source.buffer,
|
21
19
|
t1.pos.end_pos,
|
22
20
|
t2.pos.begin_pos)
|
23
|
-
|
21
|
+
add_offence(range, range, format(MSG, kind))
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# rubocop:disable SymbolName
|
4
|
-
|
5
3
|
module Rubocop
|
6
4
|
module Cop
|
7
5
|
module Style
|
@@ -9,6 +7,8 @@ module Rubocop
|
|
9
7
|
# surrounding space depending on configuration.
|
10
8
|
class SpaceInsideHashLiteralBraces < Cop
|
11
9
|
include SurroundingSpace
|
10
|
+
include ConfigurableEnforcedStyle
|
11
|
+
|
12
12
|
MSG = 'Space inside %s.'
|
13
13
|
|
14
14
|
def investigate(processed_source)
|
@@ -35,13 +35,13 @@ module Rubocop
|
|
35
35
|
expect_space = if is_empty_braces
|
36
36
|
cop_config['EnforcedStyleForEmptyBraces'] == 'space'
|
37
37
|
else
|
38
|
-
|
38
|
+
style == :space
|
39
39
|
end
|
40
40
|
if offence?(t1, t2, expect_space)
|
41
41
|
brace = (t1.text == '{' ? t1 : t2).pos
|
42
42
|
range = expect_space ? brace : space_range(brace)
|
43
|
-
|
44
|
-
|
43
|
+
add_offence(range, range,
|
44
|
+
message(brace, is_empty_braces, expect_space))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -5,12 +5,13 @@ module Rubocop
|
|
5
5
|
module Style
|
6
6
|
# Checks if uses of quotes match the configured preference.
|
7
7
|
class StringLiterals < Cop
|
8
|
+
include ConfigurableEnforcedStyle
|
8
9
|
include StringHelp
|
9
10
|
|
10
11
|
private
|
11
12
|
|
12
13
|
def message(node)
|
13
|
-
if
|
14
|
+
if style == :single_quotes
|
14
15
|
"Prefer single-quoted strings when you don't need string " +
|
15
16
|
'interpolation or special symbols.'
|
16
17
|
else
|
@@ -21,8 +22,8 @@ module Rubocop
|
|
21
22
|
|
22
23
|
def offence?(node)
|
23
24
|
src = node.loc.expression.source
|
24
|
-
return false if src =~ /^(%q
|
25
|
-
src !~ if
|
25
|
+
return false if src =~ /^(%q|\?|<<-)/i
|
26
|
+
src !~ if style == :single_quotes
|
26
27
|
# regex matches IF there is a ' or there is a \\ in the
|
27
28
|
# string that is not preceeded/followed by another \\
|
28
29
|
# (e.g. "\\x34") but not "\\\\"
|
@@ -32,14 +33,6 @@ module Rubocop
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def single_quotes_preferred?
|
36
|
-
case cop_config['EnforcedStyle']
|
37
|
-
when 'single_quotes' then true
|
38
|
-
when 'double_quotes' then false
|
39
|
-
else fail 'Unknown StringLiterals style'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
36
|
def autocorrect(node)
|
44
37
|
@corrections << lambda do |corrector|
|
45
38
|
replacement = node.loc.begin.is?('"') ? "'" : '"'
|
@@ -8,21 +8,14 @@ module Rubocop
|
|
8
8
|
#
|
9
9
|
# This check makes sense only on Ruby 2.0+.
|
10
10
|
class SymbolArray < Cop
|
11
|
+
include ArraySyntax
|
12
|
+
|
11
13
|
MSG = 'Use %i or %I for array of symbols.'
|
12
14
|
|
13
15
|
def on_array(node)
|
14
16
|
# %i and %I were introduced in Ruby 2.0
|
15
17
|
unless RUBY_VERSION < '2.0.0'
|
16
|
-
|
17
|
-
|
18
|
-
array_elems = node.children
|
19
|
-
|
20
|
-
# no need to check empty arrays
|
21
|
-
return unless array_elems && array_elems.size > 1
|
22
|
-
|
23
|
-
symbol_array = array_elems.all? { |e| e.type == :sym }
|
24
|
-
|
25
|
-
convention(node, :expression) if symbol_array
|
18
|
+
add_offence(node, :expression) if array_of?(:sym, node)
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
@@ -12,11 +12,11 @@ module Rubocop
|
|
12
12
|
match = line.match(/^( *)\t/)
|
13
13
|
if match
|
14
14
|
spaces = match.captures[0]
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
add_offence(nil,
|
16
|
+
source_range(processed_source.buffer,
|
17
|
+
processed_source[0...index],
|
18
|
+
spaces.length, 1),
|
19
|
+
MSG)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -14,7 +14,7 @@ module Rubocop
|
|
14
14
|
# discard non-ternary ops
|
15
15
|
return unless loc.respond_to?(:question)
|
16
16
|
|
17
|
-
|
17
|
+
add_offence(node, :expression) if loc.line != loc.colon.line
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -31,7 +31,7 @@ module Rubocop
|
|
31
31
|
|
32
32
|
node.children.each do |child|
|
33
33
|
on_node(:if, child) do |c|
|
34
|
-
|
34
|
+
add_offence(c, :expression) if c.loc.respond_to?(:question)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -6,19 +6,9 @@ module Rubocop
|
|
6
6
|
# This cop looks for trivial reader/writer methods, that could
|
7
7
|
# have been created with the attr_* family of functions automatically.
|
8
8
|
class TrivialAccessors < Cop
|
9
|
-
|
10
|
-
|
11
|
-
def on_def(node)
|
12
|
-
method_name, args, body = *node
|
13
|
-
|
14
|
-
check(node, method_name, args, body)
|
15
|
-
end
|
9
|
+
include CheckMethods
|
16
10
|
|
17
|
-
|
18
|
-
_scope, method_name, args, body = *node
|
19
|
-
|
20
|
-
check(node, method_name, args, body)
|
21
|
-
end
|
11
|
+
MSG = 'Use attr_%s to define trivial %s methods.'
|
22
12
|
|
23
13
|
private
|
24
14
|
|
@@ -29,8 +19,8 @@ module Rubocop
|
|
29
19
|
'writer'
|
30
20
|
end
|
31
21
|
if kind
|
32
|
-
|
33
|
-
|
22
|
+
add_offence(node, :keyword,
|
23
|
+
sprintf(MSG, kind, kind))
|
34
24
|
end
|
35
25
|
end
|
36
26
|
|