rubocop 1.8.0 → 1.11.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 +4 -4
- data/README.md +14 -13
- data/assets/output.html.erb +1 -1
- data/config/default.yml +89 -22
- data/config/obsoletion.yml +4 -0
- data/lib/rubocop.rb +9 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +5 -4
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- data/lib/rubocop/config.rb +5 -2
- data/lib/rubocop/config_loader.rb +7 -14
- data/lib/rubocop/config_store.rb +12 -1
- data/lib/rubocop/cop/base.rb +2 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
- data/lib/rubocop/cop/exclude_limit.rb +26 -0
- data/lib/rubocop/cop/gemspec/date_assignment.rb +57 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
- data/lib/rubocop/cop/generator.rb +3 -5
- data/lib/rubocop/cop/internal_affairs.rb +6 -1
- data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +68 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +90 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +62 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +65 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +8 -2
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +37 -17
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +22 -3
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/line_length.rb +2 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +26 -0
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_brackets.rb +9 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +60 -14
- data/lib/rubocop/cop/lint/deprecated_constants.rb +5 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +14 -4
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
- data/lib/rubocop/cop/lint/duplicate_require.rb +3 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +5 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +43 -6
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +47 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +39 -0
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
- data/lib/rubocop/cop/lint/rand_one.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +5 -3
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +103 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
- data/lib/rubocop/cop/lint/triple_quotes.rb +71 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
- data/lib/rubocop/cop/lint/useless_times.rb +3 -0
- data/lib/rubocop/cop/message_annotator.rb +4 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +6 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -0
- data/lib/rubocop/cop/mixin/code_length.rb +3 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +0 -1
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -1
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +3 -3
- data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +5 -1
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/constant_name.rb +2 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -0
- data/lib/rubocop/cop/naming/method_name.rb +3 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +38 -5
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/severity.rb +3 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.rb +2 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/style/collection_compact.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +28 -0
- data/lib/rubocop/cop/style/date_time.rb +3 -0
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -9
- data/lib/rubocop/cop/style/documentation.rb +5 -0
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +3 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
- data/lib/rubocop/cop/style/each_with_object.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +9 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +140 -49
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +12 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -7
- data/lib/rubocop/cop/style/float_division.rb +7 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -0
- data/lib/rubocop/cop/style/format_string_token.rb +19 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +105 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
- data/lib/rubocop/cop/style/hash_except.rb +1 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
- data/lib/rubocop/cop/style/if_inside_else.rb +14 -7
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +122 -0
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
- data/lib/rubocop/cop/style/min_max.rb +1 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
- data/lib/rubocop/cop/style/module_function.rb +5 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +6 -0
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +30 -13
- data/lib/rubocop/cop/style/numeric_literals.rb +6 -9
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -1
- data/lib/rubocop/cop/style/option_hash.rb +1 -0
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +7 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
- data/lib/rubocop/cop/style/return_nil.rb +6 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
- data/lib/rubocop/cop/style/sample.rb +1 -0
- data/lib/rubocop/cop/style/signal_exception.rb +3 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +5 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +28 -4
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +2 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
- data/lib/rubocop/cop/style/unless_logical_operators.rb +99 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/while_until_modifier.rb +2 -4
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +30 -1
- data/lib/rubocop/name_similarity.rb +1 -1
- data/lib/rubocop/options.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +5 -2
- data/lib/rubocop/runner.rb +1 -0
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +2 -2
- metadata +21 -7
@@ -25,17 +25,18 @@ module RuboCop
|
|
25
25
|
attr_accessor :debug, :ignore_parent_exclusion,
|
26
26
|
:disable_pending_cops, :enable_pending_cops
|
27
27
|
attr_writer :default_configuration, :project_root
|
28
|
+
attr_reader :loaded_features
|
28
29
|
|
29
30
|
alias debug? debug
|
30
31
|
alias ignore_parent_exclusion? ignore_parent_exclusion
|
31
32
|
|
32
33
|
def clear_options
|
33
34
|
@debug = nil
|
34
|
-
@loaded_features =
|
35
|
+
@loaded_features = Set.new
|
35
36
|
FileFinder.root_level = nil
|
36
37
|
end
|
37
38
|
|
38
|
-
def load_file(file)
|
39
|
+
def load_file(file, check: true)
|
39
40
|
path = file_path(file)
|
40
41
|
|
41
42
|
hash = load_yaml_configuration(path)
|
@@ -52,7 +53,7 @@ module RuboCop
|
|
52
53
|
|
53
54
|
hash.delete('inherit_from')
|
54
55
|
|
55
|
-
Config.create(hash, path)
|
56
|
+
Config.create(hash, path, check: check)
|
56
57
|
end
|
57
58
|
|
58
59
|
def load_yaml_configuration(absolute_path)
|
@@ -99,10 +100,10 @@ module RuboCop
|
|
99
100
|
find_user_xdg_config || DEFAULT_FILE
|
100
101
|
end
|
101
102
|
|
102
|
-
def configuration_from_file(config_file)
|
103
|
+
def configuration_from_file(config_file, check: true)
|
103
104
|
return default_configuration if config_file == DEFAULT_FILE
|
104
105
|
|
105
|
-
config = load_file(config_file)
|
106
|
+
config = load_file(config_file, check: check)
|
106
107
|
if ignore_parent_exclusion?
|
107
108
|
print 'Ignoring AllCops/Exclude from parent folders' if debug?
|
108
109
|
else
|
@@ -174,19 +175,11 @@ module RuboCop
|
|
174
175
|
resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
|
175
176
|
end
|
176
177
|
|
177
|
-
def loaded_features
|
178
|
-
@loaded_features.flatten.compact
|
179
|
-
end
|
180
|
-
|
181
178
|
# @api private
|
182
179
|
# Used to add features that were required inside a config or from
|
183
180
|
# the CLI using `--require`.
|
184
181
|
def add_loaded_features(loaded_features)
|
185
|
-
|
186
|
-
instance_variable_get(:@loaded_features) << loaded_features
|
187
|
-
else
|
188
|
-
instance_variable_set(:@loaded_features, [loaded_features])
|
189
|
-
end
|
182
|
+
@loaded_features.merge(Array(loaded_features))
|
190
183
|
end
|
191
184
|
|
192
185
|
private
|
data/lib/rubocop/config_store.rb
CHANGED
@@ -4,6 +4,9 @@ module RuboCop
|
|
4
4
|
# Handles caching of configurations and association of inspected
|
5
5
|
# ruby files to configurations.
|
6
6
|
class ConfigStore
|
7
|
+
attr_reader :validated
|
8
|
+
alias validated? validated
|
9
|
+
|
7
10
|
def initialize
|
8
11
|
# @options_config stores a config that is specified in the command line.
|
9
12
|
# This takes precedence over configs located in any directories
|
@@ -17,6 +20,9 @@ module RuboCop
|
|
17
20
|
# @object_cache maps configuration file paths to
|
18
21
|
# configuration objects so we only need to load them once.
|
19
22
|
@object_cache = {}
|
23
|
+
|
24
|
+
# By default the config is validated before it can be used.
|
25
|
+
@validated = true
|
20
26
|
end
|
21
27
|
|
22
28
|
def options_config=(options_config)
|
@@ -29,6 +35,11 @@ module RuboCop
|
|
29
35
|
@options_config = ConfigLoader.default_configuration
|
30
36
|
end
|
31
37
|
|
38
|
+
def unvalidated
|
39
|
+
@validated = false
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
32
43
|
def for_file(file)
|
33
44
|
for_dir(File.dirname(file))
|
34
45
|
end
|
@@ -55,7 +66,7 @@ module RuboCop
|
|
55
66
|
path = @path_cache[dir]
|
56
67
|
@object_cache[path] ||= begin
|
57
68
|
print "For #{dir}: " if ConfigLoader.debug?
|
58
|
-
ConfigLoader.configuration_from_file(path)
|
69
|
+
ConfigLoader.configuration_from_file(path, check: validated?)
|
59
70
|
end
|
60
71
|
end
|
61
72
|
end
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
class Base # rubocop:disable Metrics/ClassLength
|
35
35
|
extend RuboCop::AST::Sexp
|
36
36
|
extend NodePattern::Macros
|
37
|
+
extend ExcludeLimit
|
37
38
|
include RuboCop::AST::Sexp
|
38
39
|
include Util
|
39
40
|
include IgnoredNode
|
@@ -351,7 +352,7 @@ module RuboCop
|
|
351
352
|
def use_corrector(range, corrector)
|
352
353
|
if autocorrect?
|
353
354
|
attempt_correction(range, corrector)
|
354
|
-
elsif corrector
|
355
|
+
elsif corrector && cop_config.fetch('AutoCorrect', true)
|
355
356
|
:uncorrected
|
356
357
|
else
|
357
358
|
:unsupported
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
# if Dir.exist?(local)
|
31
31
|
# gem 'rubocop', path: local
|
32
32
|
# elsif ENV['RUBOCOP_VERSION'] == 'master'
|
33
|
-
# gem 'rubocop', git: 'https://github.com/rubocop
|
33
|
+
# gem 'rubocop', git: 'https://github.com/rubocop/rubocop.git'
|
34
34
|
# else
|
35
35
|
# gem 'rubocop', '~> 0.90.0'
|
36
36
|
# end
|
@@ -57,6 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
+
# @!method gem_declarations(node)
|
60
61
|
def_node_search :gem_declarations, '(send nil? :gem str ...)'
|
61
62
|
|
62
63
|
def duplicated_gem_nodes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# Allows specified configuration options to have an exclude limit
|
5
|
+
# ie. a maximum value tracked that it can be used by `--auto-gen-config`.
|
6
|
+
module ExcludeLimit
|
7
|
+
# Sets up a configuration option to have an exclude limit tracked.
|
8
|
+
# The parameter name given is transformed into a method name (eg. `Max`
|
9
|
+
# becomes `self.max=` and `MinDigits` becomes `self.min_digits=`).
|
10
|
+
def exclude_limit(parameter_name, method_name: transform(parameter_name))
|
11
|
+
define_method("#{method_name}=") do |value|
|
12
|
+
cfg = config_to_allow_offenses
|
13
|
+
cfg[:exclude_limit] ||= {}
|
14
|
+
current_max = cfg[:exclude_limit][parameter_name]
|
15
|
+
value = [current_max, value].max if current_max
|
16
|
+
cfg[:exclude_limit][parameter_name] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def transform(parameter_name)
|
23
|
+
parameter_name.gsub(/(?<!\A)(?=[A-Z])/, '_').downcase
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemspec
|
6
|
+
# This cop checks that `date =` is not used in gemspec file.
|
7
|
+
# It is set automatically when the gem is packaged.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Gem::Specification.new do |spec|
|
13
|
+
# s.name = 'your_cool_gem_name'
|
14
|
+
# spec.date = Time.now.strftime('%Y-%m-%d')
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# Gem::Specification.new do |spec|
|
19
|
+
# s.name = 'your_cool_gem_name'
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class DateAssignment < Base
|
23
|
+
include RangeHelp
|
24
|
+
extend AutoCorrector
|
25
|
+
|
26
|
+
MSG = 'Do not use `date =` in gemspec, it is set automatically when the gem is packaged.'
|
27
|
+
|
28
|
+
# @!method gem_specification(node)
|
29
|
+
def_node_matcher :gem_specification, <<~PATTERN
|
30
|
+
(block
|
31
|
+
(send
|
32
|
+
(const
|
33
|
+
(const {cbase nil?} :Gem) :Specification) :new)
|
34
|
+
...)
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
def on_block(block_node)
|
38
|
+
return unless gem_specification(block_node)
|
39
|
+
|
40
|
+
block_parameter = block_node.arguments.first.source
|
41
|
+
|
42
|
+
date_assignment = block_node.descendants.detect do |node|
|
43
|
+
node.send_type? && node.receiver&.source == block_parameter && node.method?(:date=)
|
44
|
+
end
|
45
|
+
|
46
|
+
return unless date_assignment
|
47
|
+
|
48
|
+
add_offense(date_assignment) do |corrector|
|
49
|
+
range = range_by_whole_lines(date_assignment.source_range, include_final_newline: true)
|
50
|
+
|
51
|
+
corrector.remove(range)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -40,6 +40,7 @@ module RuboCop
|
|
40
40
|
MSG = '`%<assignment>s` method calls already given on line '\
|
41
41
|
'%<line_of_first_occurrence>d of the gemspec.'
|
42
42
|
|
43
|
+
# @!method gem_specification(node)
|
43
44
|
def_node_search :gem_specification, <<~PATTERN
|
44
45
|
(block
|
45
46
|
(send
|
@@ -49,6 +50,7 @@ module RuboCop
|
|
49
50
|
(arg $_)) ...)
|
50
51
|
PATTERN
|
51
52
|
|
53
|
+
# @!method assignment_method_declarations(node)
|
52
54
|
def_node_search :assignment_method_declarations, <<~PATTERN
|
53
55
|
(send
|
54
56
|
(lvar #match_block_variable_name?) #assignment_method? ...)
|
@@ -55,10 +55,12 @@ module RuboCop
|
|
55
55
|
'.rubocop.yml) should be equal.'
|
56
56
|
MISSING_MSG = '`required_ruby_version` should be specified.'
|
57
57
|
|
58
|
+
# @!method required_ruby_version(node)
|
58
59
|
def_node_search :required_ruby_version, <<~PATTERN
|
59
60
|
(send _ :required_ruby_version= $_)
|
60
61
|
PATTERN
|
61
62
|
|
63
|
+
# @!method defined_ruby_version(node)
|
62
64
|
def_node_matcher :defined_ruby_version, <<~PATTERN
|
63
65
|
{$(str _) $(array (str _) (str _))
|
64
66
|
(send (const (const nil? :Gem) :Requirement) :new $(str _))}
|
@@ -28,8 +28,10 @@ module RuboCop
|
|
28
28
|
class RubyVersionGlobalsUsage < Base
|
29
29
|
MSG = 'Do not use `RUBY_VERSION` in gemspec file.'
|
30
30
|
|
31
|
+
# @!method ruby_version?(node)
|
31
32
|
def_node_matcher :ruby_version?, '(const {cbase nil?} :RUBY_VERSION)'
|
32
33
|
|
34
|
+
# @!method gem_specification?(node)
|
33
35
|
def_node_search :gem_specification?, <<~PATTERN
|
34
36
|
(block
|
35
37
|
(send
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# @api private
|
10
10
|
class Generator
|
11
11
|
# NOTE: RDoc 5.1.0 or lower has the following issue.
|
12
|
-
# https://github.com/rubocop
|
12
|
+
# https://github.com/rubocop/rubocop/issues/7043
|
13
13
|
#
|
14
14
|
# The following `String#gsub` can be replaced with
|
15
15
|
# squiggly heredoc when RuboCop supports Ruby 2.5 or higher
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
# TODO: Implement the cop in here.
|
59
59
|
#
|
60
60
|
# In many cases, you can use a node matcher for matching node pattern.
|
61
|
-
# See https://github.com/rubocop
|
61
|
+
# See https://github.com/rubocop/rubocop-ast/blob/master/lib/rubocop/ast/node_pattern.rb
|
62
62
|
#
|
63
63
|
# For example
|
64
64
|
MSG = 'Use `#good_method` instead of `#bad_method`.'
|
@@ -81,9 +81,7 @@ module RuboCop
|
|
81
81
|
SPEC_TEMPLATE = <<~SPEC
|
82
82
|
# frozen_string_literal: true
|
83
83
|
|
84
|
-
RSpec.describe RuboCop::Cop::%<department>s::%<cop_name>s do
|
85
|
-
subject(:cop) { described_class.new(config) }
|
86
|
-
|
84
|
+
RSpec.describe RuboCop::Cop::%<department>s::%<cop_name>s, :config do
|
87
85
|
let(:config) { RuboCop::Config.new }
|
88
86
|
|
89
87
|
# TODO: Write test code
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'internal_affairs/empty_line_between_expect_offense_and_correction'
|
4
|
+
require_relative 'internal_affairs/example_description'
|
3
5
|
require_relative 'internal_affairs/method_name_equal'
|
4
6
|
require_relative 'internal_affairs/node_destructuring'
|
7
|
+
require_relative 'internal_affairs/node_matcher_directive'
|
5
8
|
require_relative 'internal_affairs/node_type_predicate'
|
6
9
|
require_relative 'internal_affairs/offense_location_keyword'
|
7
|
-
require_relative 'internal_affairs/
|
10
|
+
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
11
|
+
require_relative 'internal_affairs/redundant_let_rubocop_config_new'
|
8
12
|
require_relative 'internal_affairs/redundant_location_argument'
|
13
|
+
require_relative 'internal_affairs/redundant_message_argument'
|
9
14
|
require_relative 'internal_affairs/style_detected_api_use'
|
10
15
|
require_relative 'internal_affairs/useless_message_assertion'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# This cop checks whether `expect_offense` and correction expectation methods
|
7
|
+
# (i.e. `expect_correction` and `expect_no_corrections`) are separated by empty line.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# it 'registers and corrects an offense' do
|
12
|
+
# expect_offense(<<~RUBY)
|
13
|
+
# bad_method
|
14
|
+
# ^^^^^^^^^^ Use `good_method`.
|
15
|
+
# RUBY
|
16
|
+
# expect_correction(<<~RUBY)
|
17
|
+
# good_method
|
18
|
+
# RUBY
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# it 'registers and corrects an offense' do
|
23
|
+
# expect_offense(<<~RUBY)
|
24
|
+
# bad_method
|
25
|
+
# ^^^^^^^^^^ Use `good_method`.
|
26
|
+
# RUBY
|
27
|
+
#
|
28
|
+
# expect_correction(<<~RUBY)
|
29
|
+
# good_method
|
30
|
+
# RUBY
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
class EmptyLineBetweenExpectOffenseAndCorrection < Base
|
34
|
+
extend AutoCorrector
|
35
|
+
|
36
|
+
MSG = 'Add empty line between `expect_offense` and `%<expect_correction>s`.'
|
37
|
+
RESTRICT_ON_SEND = %i[expect_offense].freeze
|
38
|
+
CORRECTION_EXPECTATION_METHODS = %i[expect_correction expect_no_corrections].freeze
|
39
|
+
|
40
|
+
def on_send(node)
|
41
|
+
return unless (next_sibling = node.right_sibling) && next_sibling.send_type?
|
42
|
+
|
43
|
+
method_name = next_sibling.method_name
|
44
|
+
return unless CORRECTION_EXPECTATION_METHODS.include?(method_name)
|
45
|
+
|
46
|
+
range = offense_range(node)
|
47
|
+
return unless range.last_line + 1 == next_sibling.loc.line
|
48
|
+
|
49
|
+
add_offense(range, message: format(MSG, expect_correction: method_name)) do |corrector|
|
50
|
+
corrector.insert_after(range, "\n")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def offense_range(node)
|
57
|
+
first_argument = node.first_argument
|
58
|
+
|
59
|
+
if first_argument.respond_to?(:heredoc?) && first_argument.heredoc?
|
60
|
+
first_argument.loc.heredoc_end
|
61
|
+
else
|
62
|
+
node
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks that RSpec examples that use `expects_offense`
|
7
|
+
# or `expects_no_offenses` do not have conflicting
|
8
|
+
# descriptions.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# it 'does not register an offense' do
|
13
|
+
# expect_offense('...')
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# it 'registers an offense' do
|
17
|
+
# expect_no_offenses('...')
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# it 'registers an offense' do
|
22
|
+
# expect_offense('...')
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# it 'does not register an offense' do
|
26
|
+
# expect_no_offenses('...')
|
27
|
+
# end
|
28
|
+
class ExampleDescription < Base
|
29
|
+
class << self
|
30
|
+
attr_accessor :descriptions
|
31
|
+
end
|
32
|
+
|
33
|
+
MSG = 'Description does not match use of `%<method_name>s`.'
|
34
|
+
|
35
|
+
RESTRICT_ON_SEND = %i[
|
36
|
+
expect_offense
|
37
|
+
expect_no_offenses
|
38
|
+
expect_correction
|
39
|
+
expect_no_corrections
|
40
|
+
].to_set.freeze
|
41
|
+
|
42
|
+
EXPECT_NO_OFFENSES_INCORRECT_DESCRIPTIONS = [
|
43
|
+
/^(adds|registers|reports|finds) (an? )?offense/,
|
44
|
+
/^flags\b/
|
45
|
+
].freeze
|
46
|
+
|
47
|
+
EXPECT_OFFENSE_INCORRECT_DESCRIPTIONS = [
|
48
|
+
/^(does not|doesn't) (register|find|flag|report)/,
|
49
|
+
/^(does not|doesn't) add (a|an|any )?offense/
|
50
|
+
].freeze
|
51
|
+
|
52
|
+
EXPECT_NO_CORRECTIONS_INCORRECT_DESCRIPTIONS = [
|
53
|
+
/^(auto[- ]?)?correct/
|
54
|
+
].freeze
|
55
|
+
|
56
|
+
EXPECT_CORRECTION_INCORRECT_DESCRIPTIONS = [
|
57
|
+
/\b(does not|doesn't) (auto[- ]?)?correct/
|
58
|
+
].freeze
|
59
|
+
|
60
|
+
# @!method offense_example?(node)
|
61
|
+
def_node_matcher :offense_example?, <<~PATTERN
|
62
|
+
(block
|
63
|
+
(send _ {:it :specify} $_description)
|
64
|
+
_args
|
65
|
+
`(send nil? %RESTRICT_ON_SEND ...)
|
66
|
+
)
|
67
|
+
PATTERN
|
68
|
+
|
69
|
+
def on_send(node)
|
70
|
+
parent = node.each_ancestor(:block).first
|
71
|
+
return unless parent && (description = offense_example?(parent))
|
72
|
+
|
73
|
+
method_name = node.method_name
|
74
|
+
message = format(MSG, method_name: method_name)
|
75
|
+
|
76
|
+
regexp_group = self.class.const_get("#{method_name}_incorrect_descriptions".upcase)
|
77
|
+
check_description(description, regexp_group, message)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def check_description(description, regexps, message)
|
83
|
+
return unless regexps.any? { |regexp| regexp.match?(description.value) }
|
84
|
+
|
85
|
+
add_offense(description, message: message)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|