rubocop 0.59.2 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +3 -2
- data/config/default.yml +2960 -552
- data/lib/rubocop.rb +1 -0
- data/lib/rubocop/ast/builder.rb +29 -29
- data/lib/rubocop/ast/node.rb +29 -25
- data/lib/rubocop/ast/node/args_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +1 -1
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +26 -0
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +5 -1
- data/lib/rubocop/ast/node/pair_node.rb +8 -1
- data/lib/rubocop/ast/node/str_node.rb +1 -1
- data/lib/rubocop/cached_data.rb +2 -2
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +8 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -1
- data/lib/rubocop/cop/generator.rb +10 -3
- data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +1 -1
- data/lib/rubocop/cop/layout/align_hash.rb +9 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +2 -4
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -7
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +2 -2
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +1 -2
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +25 -25
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/indent_hash.rb +1 -1
- data/lib/rubocop/cop/layout/indent_heredoc.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +84 -43
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -5
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +10 -20
- data/lib/rubocop/cop/lint/ensure_return.rb +3 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +3 -3
- data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +10 -7
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +3 -4
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -2
- data/lib/rubocop/cop/lint/syntax.rb +3 -2
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -3
- data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -7
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -17
- data/lib/rubocop/cop/metrics/line_length.rb +14 -10
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +45 -0
- data/lib/rubocop/cop/mixin/check_assignment.rb +12 -6
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +0 -2
- data/lib/rubocop/cop/mixin/configurable_max.rb +4 -2
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +2 -2
- data/lib/rubocop/cop/mixin/hash_alignment.rb +32 -5
- data/lib/rubocop/cop/mixin/heredoc.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -4
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +2 -0
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +1 -1
- data/lib/rubocop/cop/performance/regexp_match.rb +1 -1
- data/lib/rubocop/cop/performance/sample.rb +3 -2
- data/lib/rubocop/cop/performance/start_with.rb +1 -1
- data/lib/rubocop/cop/performance/string_replacement.rb +1 -1
- data/lib/rubocop/cop/rails/date.rb +8 -8
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
- data/lib/rubocop/cop/rails/exit.rb +8 -9
- data/lib/rubocop/cop/rails/output_safety.rb +3 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -4
- data/lib/rubocop/cop/rails/refute_methods.rb +13 -13
- data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +17 -0
- data/lib/rubocop/cop/registry.rb +11 -2
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/collection_methods.rb +26 -0
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +3 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -13
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +4 -7
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +15 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +2 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +6 -6
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/redundant_freeze.rb +10 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -2
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +4 -3
- data/lib/rubocop/cop/style/unneeded_condition.rb +2 -2
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/team.rb +3 -2
- data/lib/rubocop/cop/util.rb +2 -22
- data/lib/rubocop/cop/variable_force/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable.rb +3 -4
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/formatter/base_formatter.rb +3 -3
- data/lib/rubocop/formatter/disabled_config_formatter.rb +16 -1
- data/lib/rubocop/formatter/formatter_set.rb +14 -14
- data/lib/rubocop/formatter/html_formatter.rb +4 -4
- data/lib/rubocop/formatter/json_formatter.rb +13 -13
- data/lib/rubocop/formatter/simple_text_formatter.rb +4 -4
- data/lib/rubocop/magic_comment.rb +4 -4
- data/lib/rubocop/node_pattern.rb +17 -17
- data/lib/rubocop/options.rb +93 -82
- data/lib/rubocop/result_cache.rb +9 -1
- data/lib/rubocop/rspec/expect_offense.rb +2 -2
- data/lib/rubocop/rspec/shared_contexts.rb +11 -11
- data/lib/rubocop/rspec/shared_examples.rb +4 -4
- data/lib/rubocop/string_interpreter.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +6 -13
- data/config/disabled.yml +0 -161
- data/config/enabled.yml +0 -2092
data/lib/rubocop.rb
CHANGED
@@ -330,6 +330,7 @@ require_relative 'rubocop/cop/lint/void'
|
|
330
330
|
|
331
331
|
require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
|
332
332
|
# relies on cyclomatic_complexity
|
333
|
+
require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
|
333
334
|
require_relative 'rubocop/cop/metrics/abc_size'
|
334
335
|
require_relative 'rubocop/cop/metrics/block_length'
|
335
336
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -15,37 +15,37 @@ module RuboCop
|
|
15
15
|
# root_node = parser.parse(buffer)
|
16
16
|
class Builder < Parser::Builders::Default
|
17
17
|
NODE_MAP = {
|
18
|
-
and:
|
19
|
-
args:
|
20
|
-
array:
|
21
|
-
block:
|
22
|
-
case:
|
23
|
-
def:
|
24
|
-
defined?:
|
25
|
-
defs:
|
26
|
-
ensure:
|
27
|
-
for:
|
28
|
-
hash:
|
29
|
-
if:
|
30
|
-
kwsplat:
|
31
|
-
or:
|
32
|
-
pair:
|
33
|
-
regexp:
|
34
|
-
resbody:
|
35
|
-
csend:
|
36
|
-
send:
|
37
|
-
str:
|
38
|
-
dstr:
|
39
|
-
xstr:
|
40
|
-
super:
|
41
|
-
zsuper:
|
42
|
-
sym:
|
43
|
-
until:
|
18
|
+
and: AndNode,
|
19
|
+
args: ArgsNode,
|
20
|
+
array: ArrayNode,
|
21
|
+
block: BlockNode,
|
22
|
+
case: CaseNode,
|
23
|
+
def: DefNode,
|
24
|
+
defined?: DefinedNode,
|
25
|
+
defs: DefNode,
|
26
|
+
ensure: EnsureNode,
|
27
|
+
for: ForNode,
|
28
|
+
hash: HashNode,
|
29
|
+
if: IfNode,
|
30
|
+
kwsplat: KeywordSplatNode,
|
31
|
+
or: OrNode,
|
32
|
+
pair: PairNode,
|
33
|
+
regexp: RegexpNode,
|
34
|
+
resbody: ResbodyNode,
|
35
|
+
csend: SendNode,
|
36
|
+
send: SendNode,
|
37
|
+
str: StrNode,
|
38
|
+
dstr: StrNode,
|
39
|
+
xstr: StrNode,
|
40
|
+
super: SuperNode,
|
41
|
+
zsuper: SuperNode,
|
42
|
+
sym: SymbolNode,
|
43
|
+
until: UntilNode,
|
44
44
|
until_post: UntilNode,
|
45
|
-
when:
|
46
|
-
while:
|
45
|
+
when: WhenNode,
|
46
|
+
while: WhileNode,
|
47
47
|
while_post: WhileNode,
|
48
|
-
yield:
|
48
|
+
yield: YieldNode
|
49
49
|
}.freeze
|
50
50
|
|
51
51
|
# Generates {Node} from the given information.
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -33,9 +33,17 @@ module RuboCop
|
|
33
33
|
COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
|
34
34
|
erange regexp].freeze
|
35
35
|
BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
|
36
|
-
MUTABLE_LITERALS = %i[str dstr xstr array hash
|
36
|
+
MUTABLE_LITERALS = %i[str dstr xstr array hash
|
37
|
+
regexp irange erange].freeze
|
37
38
|
IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
|
38
39
|
|
40
|
+
EQUALS_ASSIGNMENTS = %i[lvasgn ivasgn cvasgn gvasgn
|
41
|
+
casgn masgn].freeze
|
42
|
+
SHORTHAND_ASSIGNMENTS = %i[op_asgn or_asgn and_asgn].freeze
|
43
|
+
ASSIGNMENTS = (EQUALS_ASSIGNMENTS + SHORTHAND_ASSIGNMENTS).freeze
|
44
|
+
|
45
|
+
BASIC_CONDITIONALS = %i[if while until].freeze
|
46
|
+
CONDITIONALS = [*BASIC_CONDITIONALS, :case].freeze
|
39
47
|
VARIABLES = %i[ivar gvar cvar lvar].freeze
|
40
48
|
REFERENCES = %i[nth_ref back_ref].freeze
|
41
49
|
KEYWORDS = %i[alias and break case class def defs defined?
|
@@ -358,16 +366,6 @@ module RuboCop
|
|
358
366
|
source_length.zero?
|
359
367
|
end
|
360
368
|
|
361
|
-
def_node_matcher :equals_asgn?, <<-PATTERN
|
362
|
-
{lvasgn ivasgn cvasgn gvasgn casgn masgn}
|
363
|
-
PATTERN
|
364
|
-
|
365
|
-
def_node_matcher :shorthand_asgn?, '{op_asgn or_asgn and_asgn}'
|
366
|
-
|
367
|
-
def_node_matcher :assignment?, <<-PATTERN
|
368
|
-
{equals_asgn? shorthand_asgn?}
|
369
|
-
PATTERN
|
370
|
-
|
371
369
|
# Some cops treat the shovel operator as a kind of assignment.
|
372
370
|
def_node_matcher :assignment_or_similar?, <<-PATTERN
|
373
371
|
{assignment? (send _recv :<< ...)}
|
@@ -422,6 +420,26 @@ module RuboCop
|
|
422
420
|
REFERENCES.include?(type)
|
423
421
|
end
|
424
422
|
|
423
|
+
def equals_asgn?
|
424
|
+
EQUALS_ASSIGNMENTS.include?(type)
|
425
|
+
end
|
426
|
+
|
427
|
+
def shorthand_asgn?
|
428
|
+
SHORTHAND_ASSIGNMENTS.include?(type)
|
429
|
+
end
|
430
|
+
|
431
|
+
def assignment?
|
432
|
+
ASSIGNMENTS.include?(type)
|
433
|
+
end
|
434
|
+
|
435
|
+
def basic_conditional?
|
436
|
+
BASIC_CONDITIONALS.include?(type)
|
437
|
+
end
|
438
|
+
|
439
|
+
def conditional?
|
440
|
+
CONDITIONALS.include?(type)
|
441
|
+
end
|
442
|
+
|
425
443
|
def keyword?
|
426
444
|
return true if special_keyword? || send_type? && prefix_not?
|
427
445
|
return false unless KEYWORDS.include?(type)
|
@@ -437,20 +455,6 @@ module RuboCop
|
|
437
455
|
OPERATOR_KEYWORDS.include?(type)
|
438
456
|
end
|
439
457
|
|
440
|
-
def unary_operation?
|
441
|
-
return false unless loc.respond_to?(:selector) && loc.selector
|
442
|
-
|
443
|
-
Cop::Util.operator?(loc.selector.source.to_sym) &&
|
444
|
-
source_range.begin_pos == loc.selector.begin_pos
|
445
|
-
end
|
446
|
-
|
447
|
-
def binary_operation?
|
448
|
-
return false unless loc.respond_to?(:selector) && loc.selector
|
449
|
-
|
450
|
-
Cop::Util.operator?(method_name) &&
|
451
|
-
source_range.begin_pos != loc.selector.begin_pos
|
452
|
-
end
|
453
|
-
|
454
458
|
def parenthesized_call?
|
455
459
|
loc.respond_to?(:begin) && loc.begin && loc.begin.is?('(')
|
456
460
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
rhs = rhs.children.first if rhs.begin_type?
|
32
32
|
|
33
33
|
[lhs, rhs].each_with_object([]) do |side, collection|
|
34
|
-
if
|
34
|
+
if side.operator_keyword?
|
35
35
|
collection.concat(side.conditions)
|
36
36
|
else
|
37
37
|
collection << side
|
@@ -182,6 +182,32 @@ module RuboCop
|
|
182
182
|
block_literal? && loc.expression && loc.expression.source == '->'
|
183
183
|
end
|
184
184
|
|
185
|
+
# Checks whether this is a unary operation.
|
186
|
+
#
|
187
|
+
# @example
|
188
|
+
#
|
189
|
+
# -foo
|
190
|
+
#
|
191
|
+
# @return [Boolean] whether this method is a unary operation
|
192
|
+
def unary_operation?
|
193
|
+
return false unless loc.selector
|
194
|
+
|
195
|
+
operator_method? && loc.expression.begin_pos == loc.selector.begin_pos
|
196
|
+
end
|
197
|
+
|
198
|
+
# Checks whether this is a binary operation.
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
#
|
202
|
+
# foo + bar
|
203
|
+
#
|
204
|
+
# @return [Bookean] whether this method is a binary operation
|
205
|
+
def binary_operation?
|
206
|
+
return false unless loc.selector
|
207
|
+
|
208
|
+
operator_method? && loc.expression.begin_pos != loc.selector.begin_pos
|
209
|
+
end
|
210
|
+
|
185
211
|
private
|
186
212
|
|
187
213
|
def_node_matcher :macro_scope?, <<-PATTERN
|
@@ -12,6 +12,10 @@ module RuboCop
|
|
12
12
|
map reduce reject reject! reverse_each select
|
13
13
|
select! times upto].freeze
|
14
14
|
|
15
|
+
# http://phrogz.net/programmingruby/language.html#table_18.4
|
16
|
+
OPERATOR_METHODS = %i[| ^ & <=> == === =~ > >= < <= << >> + - * /
|
17
|
+
% ** ~ +@ -@ !@ ~@ [] []= ! != !~ `].freeze
|
18
|
+
|
15
19
|
# Checks whether the method name matches the argument.
|
16
20
|
#
|
17
21
|
# @param [Symbol, String] name the method name to check for
|
@@ -24,7 +28,7 @@ module RuboCop
|
|
24
28
|
#
|
25
29
|
# @return [Boolean] whether the method is an operator
|
26
30
|
def operator_method?
|
27
|
-
|
31
|
+
OPERATOR_METHODS.include?(method_name)
|
28
32
|
end
|
29
33
|
|
30
34
|
# Checks whether the method is a comparison method.
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns the delimiter of the `pair` as a string. Returns `=>` for a
|
31
|
-
# colon delimited `pair
|
31
|
+
# colon delimited `pair` and `:` for a hash rocket delimited `pair`.
|
32
32
|
#
|
33
33
|
# @param [Boolean] with_spacing whether to include spacing
|
34
34
|
# @return [String] the delimiter of the `pair`
|
@@ -51,6 +51,13 @@ module RuboCop
|
|
51
51
|
hash_rocket? ? COLON : HASH_ROCKET
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
# Checks whether the value starts on its own line.
|
56
|
+
#
|
57
|
+
# @return [Boolean] whether the value in the `pair` starts its own line
|
58
|
+
def value_on_new_line?
|
59
|
+
key.loc.line != value.loc.line
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module AST
|
5
|
-
# A node extension for `str`, `dstr
|
5
|
+
# A node extension for `str`, `dstr`, and `xstr` nodes. This will be used
|
6
6
|
# in place of a plain node when the builder constructs the AST, making
|
7
7
|
# its methods available to all `str` nodes within RuboCop.
|
8
8
|
class StrNode < Node
|
data/lib/rubocop/cached_data.rb
CHANGED
@@ -29,9 +29,9 @@ module RuboCop
|
|
29
29
|
begin_pos: offense.location.begin_pos,
|
30
30
|
end_pos: offense.location.end_pos
|
31
31
|
},
|
32
|
-
message:
|
32
|
+
message: message(offense),
|
33
33
|
cop_name: offense.cop_name,
|
34
|
-
status:
|
34
|
+
status: :uncorrected
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
AutoCorrect StyleGuide Details].freeze
|
19
19
|
# 2.2 is the oldest officially supported Ruby version.
|
20
20
|
DEFAULT_RUBY_VERSION = 2.2
|
21
|
-
KNOWN_RUBIES = [2.2, 2.3, 2.4, 2.5].freeze
|
21
|
+
KNOWN_RUBIES = [2.2, 2.3, 2.4, 2.5, 2.6].freeze
|
22
22
|
OBSOLETE_RUBIES = { 1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58' }.freeze
|
23
23
|
RUBY_VERSION_FILENAME = '.ruby-version'.freeze
|
24
24
|
DEFAULT_RAILS_VERSION = 5.0
|
@@ -181,6 +181,14 @@ module RuboCop
|
|
181
181
|
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
|
182
182
|
SafeYAML.load(yaml_code, filename,
|
183
183
|
whitelisted_tags: %w[!ruby/regexp])
|
184
|
+
elsif RUBY_VERSION >= '2.6'
|
185
|
+
YAML.safe_load(
|
186
|
+
yaml_code,
|
187
|
+
whitelist_classes: [Regexp, Symbol],
|
188
|
+
whitelist_symbols: [],
|
189
|
+
aliases: false,
|
190
|
+
filename: filename
|
191
|
+
)
|
184
192
|
else
|
185
193
|
YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
|
186
194
|
end
|
@@ -20,7 +20,13 @@ module RuboCop
|
|
20
20
|
# allow turning off autocorrect on a cop by cop basis
|
21
21
|
return true unless cop_config
|
22
22
|
|
23
|
-
cop_config['AutoCorrect']
|
23
|
+
return false if cop_config['AutoCorrect'] == false
|
24
|
+
|
25
|
+
if @options.fetch(:safe_auto_correct, false)
|
26
|
+
return cop_config.fetch('SafeAutoCorrect', true)
|
27
|
+
end
|
28
|
+
|
29
|
+
true
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Bundler
|
6
|
-
# The symbol argument `:gemcutter`, `:rubygems
|
6
|
+
# The symbol argument `:gemcutter`, `:rubygems`, and `:rubyforge`
|
7
7
|
# are deprecated. So please change your source to URL string that
|
8
8
|
# 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
|
9
9
|
#
|
@@ -69,7 +69,8 @@ module RuboCop
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def calculate_range(expr, line_begin_pos, column_delta)
|
72
|
-
starts_with_space =
|
72
|
+
starts_with_space =
|
73
|
+
expr.source_buffer.source[line_begin_pos].start_with?(' ')
|
73
74
|
pos_to_remove = if column_delta > 0 || starts_with_space
|
74
75
|
line_begin_pos
|
75
76
|
else
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# Assigning to an attribute with the same name using `spec.foo =` will be
|
10
10
|
# an unintended usage. On the other hand, duplication of methods such
|
11
|
-
# as `spec.requirements`, `spec.add_runtime_dependency
|
11
|
+
# as `spec.requirements`, `spec.add_runtime_dependency`, and others are
|
12
12
|
# permitted because it is the intended use of appending values.
|
13
13
|
#
|
14
14
|
# @example
|
@@ -122,12 +122,13 @@ module RuboCop
|
|
122
122
|
).inject
|
123
123
|
end
|
124
124
|
|
125
|
-
def inject_config(config_file_path: 'config/
|
125
|
+
def inject_config(config_file_path: 'config/default.yml')
|
126
126
|
config = File.readlines(config_file_path)
|
127
127
|
content = <<-YAML.strip_indent
|
128
128
|
#{badge}:
|
129
129
|
Description: 'TODO: Write a description of the cop.'
|
130
130
|
Enabled: true
|
131
|
+
VersionAdded: #{bump_minor_version}
|
131
132
|
|
132
133
|
YAML
|
133
134
|
target_line = config.find.with_index(1) do |line, index|
|
@@ -138,7 +139,7 @@ module RuboCop
|
|
138
139
|
File.write(config_file_path, config.join)
|
139
140
|
output.puts <<-MESSAGE.strip_indent
|
140
141
|
[modify] A configuration for the cop is added into #{config_file_path}.
|
141
|
-
If you want to disable the cop by default,
|
142
|
+
If you want to disable the cop by default, set `Enabled` option to false.
|
142
143
|
MESSAGE
|
143
144
|
end
|
144
145
|
|
@@ -147,7 +148,7 @@ module RuboCop
|
|
147
148
|
Do 3 steps:
|
148
149
|
1. Add an entry to the "New features" section in CHANGELOG.md,
|
149
150
|
e.g. "Add new `#{badge}` cop. ([@#{github_user}][])"
|
150
|
-
2. Modify the description of #{badge} in config/
|
151
|
+
2. Modify the description of #{badge} in config/default.yml
|
151
152
|
3. Implement your new cop in the generated file!
|
152
153
|
TODO
|
153
154
|
end
|
@@ -209,6 +210,12 @@ module RuboCop
|
|
209
210
|
.gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
|
210
211
|
.downcase
|
211
212
|
end
|
213
|
+
|
214
|
+
def bump_minor_version
|
215
|
+
versions = RuboCop::Version::STRING.split('.')
|
216
|
+
|
217
|
+
"#{versions[0]}.#{versions[1].succ}"
|
218
|
+
end
|
212
219
|
end
|
213
220
|
end
|
214
221
|
end
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# It looks for other directives that require files in the same (cop)
|
8
8
|
# namespace and injects the provided one in alpha
|
9
9
|
class RequireFileInjector
|
10
|
-
REQUIRE_PATH = /require_relative ['"](.+)['"]
|
10
|
+
REQUIRE_PATH = /require_relative ['"](.+)['"]/.freeze
|
11
11
|
|
12
12
|
def initialize(source_path:, root_file_path:, output: $stdout)
|
13
13
|
@source_path = Pathname(source_path)
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
# # good
|
23
23
|
# method_name = send_node.method_name
|
24
24
|
class NodeDestructuring < Cop
|
25
|
-
MSG = 'Use the methods provided with the node extensions
|
25
|
+
MSG = 'Use the methods provided with the node extensions or ' \
|
26
26
|
'destructure the node using `*`.'.freeze
|
27
27
|
|
28
28
|
def_node_matcher :node_children_destructuring?, <<-PATTERN
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# literal are aligned according to configuration. The configuration
|
8
8
|
# options are:
|
9
9
|
#
|
10
|
-
# - key (left align keys)
|
10
|
+
# - key (left align keys, one space before hash rockets and values)
|
11
11
|
# - separator (align hash rockets and colons, right align keys)
|
12
12
|
# - table (left align keys, hash rockets, and values)
|
13
13
|
#
|
@@ -25,6 +25,10 @@ module RuboCop
|
|
25
25
|
# :foo => bar,
|
26
26
|
# :ba => baz
|
27
27
|
# }
|
28
|
+
# {
|
29
|
+
# :foo => bar,
|
30
|
+
# :ba => baz
|
31
|
+
# }
|
28
32
|
#
|
29
33
|
# # good
|
30
34
|
# {
|
@@ -68,6 +72,10 @@ module RuboCop
|
|
68
72
|
# foo: bar,
|
69
73
|
# ba: baz
|
70
74
|
# }
|
75
|
+
# {
|
76
|
+
# foo: bar,
|
77
|
+
# ba: baz
|
78
|
+
# }
|
71
79
|
#
|
72
80
|
# # good
|
73
81
|
# {
|
@@ -33,12 +33,10 @@ module RuboCop
|
|
33
33
|
def on_block(node)
|
34
34
|
return if node.single_line?
|
35
35
|
|
36
|
-
end_loc = node.loc.end
|
37
|
-
|
38
36
|
# If the end is on its own line, there is no offense
|
39
|
-
return if
|
37
|
+
return if begins_its_line?(node.loc.end)
|
40
38
|
|
41
|
-
add_offense(node, location:
|
39
|
+
add_offense(node, location: :end)
|
42
40
|
end
|
43
41
|
|
44
42
|
def autocorrect(node)
|