rubocop 0.70.0 → 0.72.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -10
- data/config/default.yml +50 -491
- data/lib/rubocop.rb +5 -53
- data/lib/rubocop/ast/builder.rb +2 -0
- data/lib/rubocop/ast/node.rb +1 -1
- data/lib/rubocop/ast/node/float_node.rb +12 -0
- data/lib/rubocop/ast/node/int_node.rb +12 -0
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +21 -0
- data/lib/rubocop/ast/node/resbody_node.rb +1 -6
- data/lib/rubocop/cached_data.rb +1 -1
- data/lib/rubocop/config.rb +35 -6
- data/lib/rubocop/config_loader.rb +2 -2
- data/lib/rubocop/config_loader_resolver.rb +0 -6
- data/lib/rubocop/cop/cop.rb +0 -4
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +55 -0
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +3 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -0
- data/lib/rubocop/cop/layout/indent_first_argument.rb +6 -2
- data/lib/rubocop/cop/layout/indent_first_parameter.rb +7 -3
- data/lib/rubocop/cop/layout/indent_heredoc.rb +0 -1
- data/lib/rubocop/cop/layout/indentation_consistency.rb +13 -12
- data/lib/rubocop/cop/layout/indentation_width.rb +8 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +2 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment.rb +4 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +20 -22
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -1
- data/lib/rubocop/cop/style/float_division.rb +94 -0
- data/lib/rubocop/cop/style/format_string.rb +7 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +42 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +12 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
- data/lib/rubocop/cop/style/word_array.rb +2 -2
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/node_pattern.rb +84 -5
- data/lib/rubocop/options.rb +0 -2
- data/lib/rubocop/processed_source.rb +5 -1
- data/lib/rubocop/rspec/cop_helper.rb +0 -1
- data/lib/rubocop/rspec/shared_contexts.rb +0 -17
- data/lib/rubocop/rspec/support.rb +0 -1
- data/lib/rubocop/runner.rb +6 -7
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop/yaml_duplication_checker.rb +8 -2
- metadata +7 -69
- data/lib/rubocop/cop/mixin/target_rails_version.rb +0 -16
- data/lib/rubocop/cop/rails/action_filter.rb +0 -117
- data/lib/rubocop/cop/rails/active_record_aliases.rb +0 -48
- data/lib/rubocop/cop/rails/active_record_override.rb +0 -82
- data/lib/rubocop/cop/rails/active_support_aliases.rb +0 -69
- data/lib/rubocop/cop/rails/application_job.rb +0 -40
- data/lib/rubocop/cop/rails/application_record.rb +0 -40
- data/lib/rubocop/cop/rails/assert_not.rb +0 -44
- data/lib/rubocop/cop/rails/belongs_to.rb +0 -102
- data/lib/rubocop/cop/rails/blank.rb +0 -164
- data/lib/rubocop/cop/rails/bulk_change_table.rb +0 -289
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +0 -91
- data/lib/rubocop/cop/rails/date.rb +0 -161
- data/lib/rubocop/cop/rails/delegate.rb +0 -132
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +0 -37
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +0 -91
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +0 -45
- data/lib/rubocop/cop/rails/environment_comparison.rb +0 -68
- data/lib/rubocop/cop/rails/exit.rb +0 -67
- data/lib/rubocop/cop/rails/file_path.rb +0 -108
- data/lib/rubocop/cop/rails/find_by.rb +0 -55
- data/lib/rubocop/cop/rails/find_each.rb +0 -51
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +0 -25
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +0 -106
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +0 -117
- data/lib/rubocop/cop/rails/http_status.rb +0 -179
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +0 -94
- data/lib/rubocop/cop/rails/inverse_of.rb +0 -246
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +0 -175
- data/lib/rubocop/cop/rails/link_to_blank.rb +0 -98
- data/lib/rubocop/cop/rails/not_null_column.rb +0 -67
- data/lib/rubocop/cop/rails/output.rb +0 -49
- data/lib/rubocop/cop/rails/output_safety.rb +0 -99
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +0 -107
- data/lib/rubocop/cop/rails/presence.rb +0 -124
- data/lib/rubocop/cop/rails/present.rb +0 -153
- data/lib/rubocop/cop/rails/read_write_attribute.rb +0 -74
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +0 -111
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +0 -136
- data/lib/rubocop/cop/rails/reflection_class_name.rb +0 -37
- data/lib/rubocop/cop/rails/refute_methods.rb +0 -76
- data/lib/rubocop/cop/rails/relative_date_constant.rb +0 -93
- data/lib/rubocop/cop/rails/request_referer.rb +0 -56
- data/lib/rubocop/cop/rails/reversible_migration.rb +0 -286
- data/lib/rubocop/cop/rails/safe_navigation.rb +0 -87
- data/lib/rubocop/cop/rails/save_bang.rb +0 -316
- data/lib/rubocop/cop/rails/scope_args.rb +0 -29
- data/lib/rubocop/cop/rails/skips_model_validations.rb +0 -87
- data/lib/rubocop/cop/rails/time_zone.rb +0 -238
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +0 -105
- data/lib/rubocop/cop/rails/unknown_env.rb +0 -63
- data/lib/rubocop/cop/rails/validation.rb +0 -109
- data/lib/rubocop/rspec/shared_examples.rb +0 -59
data/lib/rubocop.rb
CHANGED
@@ -27,6 +27,7 @@ require_relative 'rubocop/ast/node/mixin/conditional_node'
|
|
27
27
|
require_relative 'rubocop/ast/node/mixin/hash_element_node'
|
28
28
|
require_relative 'rubocop/ast/node/mixin/method_dispatch_node'
|
29
29
|
require_relative 'rubocop/ast/node/mixin/modifier_node'
|
30
|
+
require_relative 'rubocop/ast/node/mixin/numeric_node'
|
30
31
|
require_relative 'rubocop/ast/node/mixin/parameterized_node'
|
31
32
|
require_relative 'rubocop/ast/node/mixin/predicate_operator_node'
|
32
33
|
require_relative 'rubocop/ast/node/mixin/basic_literal_node'
|
@@ -42,8 +43,10 @@ require_relative 'rubocop/ast/node/def_node'
|
|
42
43
|
require_relative 'rubocop/ast/node/defined_node'
|
43
44
|
require_relative 'rubocop/ast/node/ensure_node'
|
44
45
|
require_relative 'rubocop/ast/node/for_node'
|
46
|
+
require_relative 'rubocop/ast/node/float_node'
|
45
47
|
require_relative 'rubocop/ast/node/hash_node'
|
46
48
|
require_relative 'rubocop/ast/node/if_node'
|
49
|
+
require_relative 'rubocop/ast/node/int_node'
|
47
50
|
require_relative 'rubocop/ast/node/keyword_splat_node'
|
48
51
|
require_relative 'rubocop/ast/node/module_node'
|
49
52
|
require_relative 'rubocop/ast/node/or_node'
|
@@ -148,7 +151,6 @@ require_relative 'rubocop/cop/mixin/statement_modifier'
|
|
148
151
|
require_relative 'rubocop/cop/mixin/string_help'
|
149
152
|
require_relative 'rubocop/cop/mixin/string_literals_help'
|
150
153
|
require_relative 'rubocop/cop/mixin/target_ruby_version'
|
151
|
-
require_relative 'rubocop/cop/mixin/target_rails_version'
|
152
154
|
require_relative 'rubocop/cop/mixin/too_many_lines'
|
153
155
|
require_relative 'rubocop/cop/mixin/trailing_body'
|
154
156
|
require_relative 'rubocop/cop/mixin/trailing_comma'
|
@@ -179,6 +181,7 @@ require_relative 'rubocop/cop/bundler/ordered_gems'
|
|
179
181
|
require_relative 'rubocop/cop/gemspec/duplicated_assignment'
|
180
182
|
require_relative 'rubocop/cop/gemspec/ordered_dependencies'
|
181
183
|
require_relative 'rubocop/cop/gemspec/required_ruby_version'
|
184
|
+
require_relative 'rubocop/cop/gemspec/ruby_version_globals_usage'
|
182
185
|
|
183
186
|
require_relative 'rubocop/cop/layout/access_modifier_indentation'
|
184
187
|
require_relative 'rubocop/cop/layout/align_arguments'
|
@@ -425,6 +428,7 @@ require_relative 'rubocop/cop/style/end_block'
|
|
425
428
|
require_relative 'rubocop/cop/style/eval_with_location'
|
426
429
|
require_relative 'rubocop/cop/style/even_odd'
|
427
430
|
require_relative 'rubocop/cop/style/expand_path_arguments'
|
431
|
+
require_relative 'rubocop/cop/style/float_division'
|
428
432
|
require_relative 'rubocop/cop/style/for'
|
429
433
|
require_relative 'rubocop/cop/style/format_string'
|
430
434
|
require_relative 'rubocop/cop/style/format_string_token'
|
@@ -547,58 +551,6 @@ require_relative 'rubocop/cop/style/word_array'
|
|
547
551
|
require_relative 'rubocop/cop/style/yoda_condition'
|
548
552
|
require_relative 'rubocop/cop/style/zero_length_predicate'
|
549
553
|
|
550
|
-
require_relative 'rubocop/cop/rails/action_filter'
|
551
|
-
require_relative 'rubocop/cop/rails/active_record_aliases'
|
552
|
-
require_relative 'rubocop/cop/rails/active_record_override'
|
553
|
-
require_relative 'rubocop/cop/rails/active_support_aliases'
|
554
|
-
require_relative 'rubocop/cop/rails/application_job'
|
555
|
-
require_relative 'rubocop/cop/rails/application_record'
|
556
|
-
require_relative 'rubocop/cop/rails/assert_not'
|
557
|
-
require_relative 'rubocop/cop/rails/belongs_to'
|
558
|
-
require_relative 'rubocop/cop/rails/blank'
|
559
|
-
require_relative 'rubocop/cop/rails/bulk_change_table'
|
560
|
-
require_relative 'rubocop/cop/rails/create_table_with_timestamps'
|
561
|
-
require_relative 'rubocop/cop/rails/date'
|
562
|
-
require_relative 'rubocop/cop/rails/delegate'
|
563
|
-
require_relative 'rubocop/cop/rails/delegate_allow_blank'
|
564
|
-
require_relative 'rubocop/cop/rails/dynamic_find_by'
|
565
|
-
require_relative 'rubocop/cop/rails/enum_uniqueness'
|
566
|
-
require_relative 'rubocop/cop/rails/environment_comparison'
|
567
|
-
require_relative 'rubocop/cop/rails/exit'
|
568
|
-
require_relative 'rubocop/cop/rails/file_path'
|
569
|
-
require_relative 'rubocop/cop/rails/find_by'
|
570
|
-
require_relative 'rubocop/cop/rails/find_each'
|
571
|
-
require_relative 'rubocop/cop/rails/has_and_belongs_to_many'
|
572
|
-
require_relative 'rubocop/cop/rails/has_many_or_has_one_dependent'
|
573
|
-
require_relative 'rubocop/cop/rails/http_positional_arguments'
|
574
|
-
require_relative 'rubocop/cop/rails/http_status'
|
575
|
-
require_relative 'rubocop/cop/rails/ignored_skip_action_filter_option'
|
576
|
-
require_relative 'rubocop/cop/rails/inverse_of'
|
577
|
-
require_relative 'rubocop/cop/rails/lexically_scoped_action_filter'
|
578
|
-
require_relative 'rubocop/cop/rails/link_to_blank'
|
579
|
-
require_relative 'rubocop/cop/rails/not_null_column'
|
580
|
-
require_relative 'rubocop/cop/rails/output'
|
581
|
-
require_relative 'rubocop/cop/rails/output_safety'
|
582
|
-
require_relative 'rubocop/cop/rails/pluralization_grammar'
|
583
|
-
require_relative 'rubocop/cop/rails/presence'
|
584
|
-
require_relative 'rubocop/cop/rails/present'
|
585
|
-
require_relative 'rubocop/cop/rails/read_write_attribute'
|
586
|
-
require_relative 'rubocop/cop/rails/redundant_allow_nil'
|
587
|
-
require_relative 'rubocop/cop/rails/redundant_receiver_in_with_options'
|
588
|
-
require_relative 'rubocop/cop/rails/reflection_class_name'
|
589
|
-
require_relative 'rubocop/cop/rails/refute_methods'
|
590
|
-
require_relative 'rubocop/cop/rails/relative_date_constant'
|
591
|
-
require_relative 'rubocop/cop/rails/request_referer'
|
592
|
-
require_relative 'rubocop/cop/rails/reversible_migration'
|
593
|
-
require_relative 'rubocop/cop/rails/safe_navigation'
|
594
|
-
require_relative 'rubocop/cop/rails/save_bang'
|
595
|
-
require_relative 'rubocop/cop/rails/scope_args'
|
596
|
-
require_relative 'rubocop/cop/rails/skips_model_validations'
|
597
|
-
require_relative 'rubocop/cop/rails/time_zone'
|
598
|
-
require_relative 'rubocop/cop/rails/uniq_before_pluck'
|
599
|
-
require_relative 'rubocop/cop/rails/unknown_env'
|
600
|
-
require_relative 'rubocop/cop/rails/validation'
|
601
|
-
|
602
554
|
require_relative 'rubocop/cop/security/eval'
|
603
555
|
require_relative 'rubocop/cop/security/json_load'
|
604
556
|
require_relative 'rubocop/cop/security/marshal_load'
|
data/lib/rubocop/ast/builder.rb
CHANGED
data/lib/rubocop/ast/node.rb
CHANGED
@@ -405,7 +405,7 @@ module RuboCop
|
|
405
405
|
receiver.send(recursive_kind) &&
|
406
406
|
arguments.all?(&recursive_kind)
|
407
407
|
when :begin, :pair, *OPERATOR_KEYWORDS, *COMPOSITE_LITERALS
|
408
|
-
children.all?(&recursive_kind)
|
408
|
+
children.compact.all?(&recursive_kind)
|
409
409
|
else
|
410
410
|
send(kind_filter)
|
411
411
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `float` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available to
|
7
|
+
# all `float` nodes within RuboCop.
|
8
|
+
class FloatNode < Node
|
9
|
+
include NumericNode
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `int` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available to
|
7
|
+
# all `int` nodes within RuboCop.
|
8
|
+
class IntNode < Node
|
9
|
+
include NumericNode
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# Common functionality for primitive numeric nodes: `int`, `float`, ...
|
6
|
+
module NumericNode
|
7
|
+
SIGN_REGEX = /\A[+-]/.freeze
|
8
|
+
|
9
|
+
# Checks whether this is literal has a sign.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# +42
|
14
|
+
#
|
15
|
+
# @return [Boolean] whether this literal has a sign.
|
16
|
+
def sign?
|
17
|
+
source.match(SIGN_REGEX)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -17,12 +17,7 @@ module RuboCop
|
|
17
17
|
#
|
18
18
|
# @return [Node, nil] The exception variable of the `resbody`.
|
19
19
|
def exception_variable
|
20
|
-
|
21
|
-
return variable if variable
|
22
|
-
|
23
|
-
# When resbody is an implicit rescue (i.e. `rescue e` style),
|
24
|
-
# the exception variable is descendants[1].
|
25
|
-
descendants[1]
|
20
|
+
node_parts[1]
|
26
21
|
end
|
27
22
|
end
|
28
23
|
end
|
data/lib/rubocop/cached_data.rb
CHANGED
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
def message(offense)
|
39
39
|
# JSON.dump will fail if the offense message contains text which is not
|
40
40
|
# valid UTF-8
|
41
|
-
offense.message.scrub
|
41
|
+
offense.message.dup.force_encoding(::Encoding::UTF_8).scrub
|
42
42
|
end
|
43
43
|
|
44
44
|
# Restore an offense object loaded from a JSON file.
|
data/lib/rubocop/config.rb
CHANGED
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
|
22
22
|
# 2.3 is the oldest officially supported Ruby version.
|
23
23
|
DEFAULT_RUBY_VERSION = 2.3
|
24
|
-
KNOWN_RUBIES = [2.3, 2.4, 2.5, 2.6].freeze
|
24
|
+
KNOWN_RUBIES = [2.3, 2.4, 2.5, 2.6, 2.7].freeze
|
25
25
|
OBSOLETE_RUBIES = {
|
26
26
|
1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58', 2.2 => '0.69'
|
27
27
|
}.freeze
|
@@ -229,6 +229,16 @@ module RuboCop
|
|
229
229
|
}
|
230
230
|
].freeze
|
231
231
|
|
232
|
+
OBSOLETE_ENFORCED_STYLES = [
|
233
|
+
{
|
234
|
+
cop: 'Layout/IndentationConsistency',
|
235
|
+
parameter: 'EnforcedStyle',
|
236
|
+
enforced_style: 'rails',
|
237
|
+
alternative: '`EnforcedStyle: rails` has been renamed to ' \
|
238
|
+
'`EnforcedStyle: indented_internal_methods`'
|
239
|
+
}
|
240
|
+
].freeze
|
241
|
+
|
232
242
|
attr_reader :loaded_path
|
233
243
|
|
234
244
|
def initialize(hash = {}, loaded_path = nil)
|
@@ -565,7 +575,8 @@ module RuboCop
|
|
565
575
|
def reject_obsolete_cops_and_parameters
|
566
576
|
messages = [
|
567
577
|
obsolete_cops,
|
568
|
-
obsolete_parameters
|
578
|
+
obsolete_parameters,
|
579
|
+
obsolete_enforced_style
|
569
580
|
].flatten.compact
|
570
581
|
return if messages.empty?
|
571
582
|
|
@@ -596,17 +607,35 @@ module RuboCop
|
|
596
607
|
end
|
597
608
|
end
|
598
609
|
|
610
|
+
def obsolete_enforced_style
|
611
|
+
OBSOLETE_ENFORCED_STYLES.map do |params|
|
612
|
+
obsolete_enforced_style_message(params[:cop], params[:parameter],
|
613
|
+
params[:enforced_style],
|
614
|
+
params[:alternative])
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
def obsolete_enforced_style_message(cop, param, enforced_style, alternative)
|
619
|
+
style = self[cop]&.detect { |key, _| key.start_with?(param) }
|
620
|
+
|
621
|
+
return unless style && style[1] == enforced_style
|
622
|
+
|
623
|
+
"obsolete `#{param}: #{enforced_style}` (for #{cop}) " \
|
624
|
+
"found in #{smart_loaded_path}" \
|
625
|
+
"\n#{alternative}"
|
626
|
+
end
|
627
|
+
|
599
628
|
def check_target_ruby
|
600
629
|
return if KNOWN_RUBIES.include?(target_ruby_version)
|
601
630
|
|
602
631
|
msg = if OBSOLETE_RUBIES.include?(target_ruby_version)
|
603
|
-
"
|
604
|
-
"#{target_ruby_source}. #{target_ruby_version}-compatible " \
|
632
|
+
"RuboCop found unsupported Ruby version #{target_ruby_version} " \
|
633
|
+
"in #{target_ruby_source}. #{target_ruby_version}-compatible " \
|
605
634
|
'analysis was dropped after version ' \
|
606
635
|
"#{OBSOLETE_RUBIES[target_ruby_version]}."
|
607
636
|
else
|
608
|
-
|
609
|
-
"#{target_ruby_source}."
|
637
|
+
'RuboCop found unknown Ruby version ' \
|
638
|
+
"#{target_ruby_version.inspect} in #{target_ruby_source}."
|
610
639
|
end
|
611
640
|
|
612
641
|
msg += "\nSupported versions: #{KNOWN_RUBIES.join(', ')}"
|
@@ -173,8 +173,8 @@ module RuboCop
|
|
173
173
|
|
174
174
|
def existing_configuration(config_file)
|
175
175
|
IO.read(config_file, encoding: Encoding::UTF_8)
|
176
|
-
.sub(
|
177
|
-
.sub(
|
176
|
+
.sub(/^inherit_from: *[^\n]+/, '')
|
177
|
+
.sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
|
178
178
|
end
|
179
179
|
|
180
180
|
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
@@ -164,12 +164,6 @@ module RuboCop
|
|
164
164
|
def handle_disabled_by_default(config, new_default_configuration)
|
165
165
|
department_config = config.to_hash.reject { |cop| cop.include?('/') }
|
166
166
|
department_config.each do |dept, dept_params|
|
167
|
-
# Rails is always disabled by default and the department's Enabled flag
|
168
|
-
# works like the --rails command line option, which is that when
|
169
|
-
# AllCops:DisabledByDefault is true, each Rails cop must still be
|
170
|
-
# explicitly mentioned in user configuration in order to be enabled.
|
171
|
-
next if dept == 'Rails'
|
172
|
-
|
173
167
|
next unless dept_params['Enabled']
|
174
168
|
|
175
169
|
new_default_configuration.each do |cop, params|
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemspec
|
6
|
+
# Checks that `RUBY_VERSION` constant is not used in gemspec.
|
7
|
+
# Using `RUBY_VERSION` is dangerous because value of the
|
8
|
+
# constant is determined by `rake release`.
|
9
|
+
# It's possible to have dependency based on ruby version used
|
10
|
+
# to execute `rake release` and not user's ruby version.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# Gem::Specification.new do |spec|
|
16
|
+
# if RUBY_VERSION >= '2.5'
|
17
|
+
# spec.add_runtime_dependency 'gem_a'
|
18
|
+
# else
|
19
|
+
# spec.add_runtime_dependency 'gem_b'
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# Gem::Specification.new do |spec|
|
25
|
+
# spec.add_runtime_dependency 'gem_a'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
class RubyVersionGlobalsUsage < Cop
|
29
|
+
MSG = 'Do not use `RUBY_VERSION` in gemspec file.'
|
30
|
+
|
31
|
+
def_node_matcher :ruby_version?, '(const nil? :RUBY_VERSION)'
|
32
|
+
|
33
|
+
def_node_search :gem_specification?, <<-PATTERN
|
34
|
+
(block
|
35
|
+
(send
|
36
|
+
(const
|
37
|
+
(const {cbase nil?} :Gem) :Specification) :new)
|
38
|
+
...)
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_const(node)
|
42
|
+
return unless gem_spec_with_ruby_version?(node)
|
43
|
+
|
44
|
+
add_offense(node)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def gem_spec_with_ruby_version?(node)
|
50
|
+
gem_specification?(processed_source.ast) && ruby_version?(node)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -129,7 +129,7 @@ module RuboCop
|
|
129
129
|
# end
|
130
130
|
# end
|
131
131
|
#
|
132
|
-
# @see https://
|
132
|
+
# @see https://rubystyle.guide#consistent-classes
|
133
133
|
class ClassStructure < Cop
|
134
134
|
HUMANIZED_NODE_TYPE = {
|
135
135
|
casgn: :constants,
|
@@ -4,8 +4,12 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# rubocop:disable Metrics/LineLength
|
6
6
|
module Layout
|
7
|
-
# This cop checks the indentation of the first argument in a method call
|
8
|
-
#
|
7
|
+
# This cop checks the indentation of the first argument in a method call.
|
8
|
+
# Arguments after the first one are checked by Layout/AlignArguments,
|
9
|
+
# not by this cop.
|
10
|
+
#
|
11
|
+
# For indenting the first parameter of method *definitions*, check out
|
12
|
+
# Layout/IndentFirstParameter.
|
9
13
|
#
|
10
14
|
# @example
|
11
15
|
#
|
@@ -3,9 +3,13 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# This cop checks the indentation of the first parameter in a method
|
7
|
-
# Parameters after the first one are checked by
|
8
|
-
# not by this cop.
|
6
|
+
# This cop checks the indentation of the first parameter in a method
|
7
|
+
# definition. Parameters after the first one are checked by
|
8
|
+
# Layout/AlignParameters, not by this cop.
|
9
|
+
#
|
10
|
+
# For indenting the first argument of method *calls*, check out
|
11
|
+
# Layout/IndentFirstArgument, which supports options related to
|
12
|
+
# nesting that are irrelevant for method *definitions*.
|
9
13
|
#
|
10
14
|
# @example
|
11
15
|
#
|
@@ -5,12 +5,13 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks for inconsistent indentation.
|
7
7
|
#
|
8
|
-
# The difference between `
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
8
|
+
# The difference between `indented_internal_methods` and `normal` is
|
9
|
+
# that the `indented_internal_methods` style prescribes that in
|
10
|
+
# classes and modules the `protected` and `private` modifier keywords
|
11
|
+
# shall be indented the same as public methods and that protected and
|
12
|
+
# private members shall be indented one step more than the modifiers.
|
13
|
+
# Other than that, both styles mean that entities on the same logical
|
14
|
+
# depth shall have the same indentation.
|
14
15
|
#
|
15
16
|
# @example EnforcedStyle: normal (default)
|
16
17
|
# # bad
|
@@ -65,7 +66,7 @@ module RuboCop
|
|
65
66
|
# end
|
66
67
|
# end
|
67
68
|
#
|
68
|
-
# @example EnforcedStyle:
|
69
|
+
# @example EnforcedStyle: indented_internal_methods
|
69
70
|
# # bad
|
70
71
|
# class A
|
71
72
|
# def test
|
@@ -166,8 +167,8 @@ module RuboCop
|
|
166
167
|
end
|
167
168
|
|
168
169
|
def check(node)
|
169
|
-
if style == :
|
170
|
-
|
170
|
+
if style == :indented_internal_methods
|
171
|
+
check_indented_internal_methods_style(node)
|
171
172
|
else
|
172
173
|
check_normal_style(node)
|
173
174
|
end
|
@@ -180,13 +181,13 @@ module RuboCop
|
|
180
181
|
)
|
181
182
|
end
|
182
183
|
|
183
|
-
def
|
184
|
+
def check_indented_internal_methods_style(node)
|
184
185
|
children_to_check = [[]]
|
185
186
|
node.children.each do |child|
|
186
187
|
# Modifier nodes have special indentation and will be checked by
|
187
188
|
# the AccessModifierIndentation cop. This cop uses them as dividers
|
188
|
-
# in
|
189
|
-
# section delimited by a modifier node.
|
189
|
+
# in indented_internal_methods mode. Then consistency is checked
|
190
|
+
# only within each section delimited by a modifier node.
|
190
191
|
if bare_access_modifier?(child)
|
191
192
|
children_to_check << []
|
192
193
|
else
|