rubocop 0.52.1 → 0.53.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/config/default.yml +118 -46
- data/config/disabled.yml +8 -8
- data/config/enabled.yml +84 -28
- data/lib/rubocop.rb +28 -8
- data/lib/rubocop/ast/builder.rb +35 -37
- data/lib/rubocop/ast/node.rb +16 -1
- data/lib/rubocop/ast/node/and_node.rb +0 -8
- data/lib/rubocop/ast/node/block_node.rb +1 -9
- data/lib/rubocop/ast/node/case_node.rb +0 -8
- data/lib/rubocop/ast/node/ensure_node.rb +0 -8
- data/lib/rubocop/ast/node/for_node.rb +0 -8
- data/lib/rubocop/ast/node/or_node.rb +0 -8
- data/lib/rubocop/ast/node/pair_node.rb +0 -8
- data/lib/rubocop/ast/node/resbody_node.rb +0 -8
- data/lib/rubocop/ast/node/send_node.rb +0 -8
- data/lib/rubocop/ast/node/symbol_node.rb +0 -8
- data/lib/rubocop/ast/node/until_node.rb +0 -8
- data/lib/rubocop/ast/node/when_node.rb +0 -8
- data/lib/rubocop/ast/node/while_node.rb +0 -8
- data/lib/rubocop/cli.rb +17 -7
- data/lib/rubocop/comment_config.rb +24 -3
- data/lib/rubocop/config.rb +75 -6
- data/lib/rubocop/config_loader.rb +18 -28
- data/lib/rubocop/config_loader_resolver.rb +61 -9
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +4 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +2 -2
- data/lib/rubocop/cop/cop.rb +4 -0
- data/lib/rubocop/cop/corrector.rb +11 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +59 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +13 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +3 -5
- data/lib/rubocop/cop/generator.rb +29 -8
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -0
- data/lib/rubocop/cop/layout/align_hash.rb +106 -37
- data/lib/rubocop/cop/{lint → layout}/block_alignment.rb +8 -5
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -17
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +6 -7
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/{lint → layout}/condition_position.rb +3 -3
- data/lib/rubocop/cop/{lint → layout}/def_end_alignment.rb +2 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +140 -0
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines.rb +3 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -5
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +20 -10
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +20 -0
- data/lib/rubocop/cop/{lint → layout}/end_alignment.rb +37 -6
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +30 -37
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/indent_heredoc.rb +38 -2
- data/lib/rubocop/cop/layout/indentation_consistency.rb +105 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +4 -3
- data/lib/rubocop/cop/layout/initial_indentation.rb +15 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +4 -2
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +62 -29
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +74 -33
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +16 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_method_name.rb +2 -0
- data/lib/rubocop/cop/layout/space_after_not.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +15 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +15 -13
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +13 -1
- data/lib/rubocop/cop/layout/space_before_comment.rb +6 -4
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +30 -45
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +48 -18
- data/lib/rubocop/cop/layout/space_inside_parens.rb +8 -7
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +57 -11
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +1 -0
- data/lib/rubocop/cop/layout/tab.rb +42 -16
- data/lib/rubocop/cop/layout/trailing_blank_lines.rb +46 -13
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +12 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +5 -3
- data/lib/rubocop/cop/lint/big_decimal_new.rb +44 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -2
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -2
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +5 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +20 -9
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +4 -3
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +16 -10
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +5 -4
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +4 -3
- data/lib/rubocop/cop/lint/literal_as_condition.rb +2 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +2 -0
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +7 -5
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +59 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +86 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -0
- data/lib/rubocop/cop/lint/percent_string_array.rb +0 -2
- data/lib/rubocop/cop/lint/rand_one.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +2 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +6 -3
- data/lib/rubocop/cop/lint/return_in_void_context.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -21
- data/lib/rubocop/cop/lint/script_permission.rb +30 -10
- data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -3
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -2
- data/lib/rubocop/cop/lint/unified_integer.rb +2 -2
- data/lib/rubocop/cop/lint/{unneeded_disable.rb → unneeded_cop_disable_directive.rb} +13 -7
- data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +97 -0
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +3 -3
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +11 -10
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +7 -5
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +49 -10
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +5 -2
- data/lib/rubocop/cop/mixin/alignment.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +4 -0
- data/lib/rubocop/cop/mixin/documentation_comment.rb +11 -3
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +12 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +20 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -0
- data/lib/rubocop/cop/mixin/hash_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +6 -0
- data/lib/rubocop/cop/mixin/nil_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +57 -9
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -5
- data/lib/rubocop/cop/mixin/range_help.rb +102 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -7
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +11 -9
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -10
- data/lib/rubocop/cop/mixin/surrounding_space.rb +38 -8
- data/lib/rubocop/cop/mixin/trailing_body.rb +26 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +15 -3
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +104 -0
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +3 -1
- data/lib/rubocop/cop/naming/file_name.rb +5 -10
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +76 -0
- data/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +48 -0
- data/lib/rubocop/cop/naming/uncommunicative_method_param_name.rb +57 -0
- data/lib/rubocop/cop/offense.rb +3 -2
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -0
- data/lib/rubocop/cop/performance/casecmp.rb +17 -8
- data/lib/rubocop/cop/performance/compare_with_block.rb +2 -0
- data/lib/rubocop/cop/performance/count.rb +1 -0
- data/lib/rubocop/cop/performance/fixed_size.rb +41 -0
- data/lib/rubocop/cop/performance/flat_map.rb +2 -0
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +2 -0
- data/lib/rubocop/cop/performance/regexp_match.rb +4 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +2 -0
- data/lib/rubocop/cop/performance/string_replacement.rb +2 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +46 -0
- data/lib/rubocop/cop/rails/blank.rb +3 -3
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +6 -0
- data/lib/rubocop/cop/rails/delegate.rb +6 -6
- data/lib/rubocop/cop/rails/file_path.rb +7 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -0
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +17 -5
- data/lib/rubocop/cop/rails/inverse_of.rb +21 -2
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +45 -9
- data/lib/rubocop/cop/rails/presence.rb +8 -2
- data/lib/rubocop/cop/rails/present.rb +5 -5
- data/lib/rubocop/cop/rails/read_write_attribute.rb +4 -3
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
- data/lib/rubocop/cop/rails/relative_date_constant.rb +4 -3
- data/lib/rubocop/cop/rails/request_referer.rb +3 -2
- data/lib/rubocop/cop/rails/reversible_migration.rb +9 -8
- data/lib/rubocop/cop/rails/safe_navigation.rb +3 -2
- data/lib/rubocop/cop/rails/save_bang.rb +11 -12
- data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
- data/lib/rubocop/cop/rails/time_zone.rb +38 -16
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +26 -16
- data/lib/rubocop/cop/rails/validation.rb +30 -2
- data/lib/rubocop/cop/security/open.rb +48 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +3 -1
- data/lib/rubocop/cop/style/attr.rb +2 -0
- data/lib/rubocop/cop/style/block_comments.rb +3 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -0
- data/lib/rubocop/cop/style/class_vars.rb +23 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -4
- data/lib/rubocop/cop/style/commented_keyword.rb +3 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +3 -1
- data/lib/rubocop/cop/style/each_with_object.rb +15 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -0
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -0
- data/lib/rubocop/cop/style/empty_else.rb +9 -5
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -0
- data/lib/rubocop/cop/style/empty_line_after_guard_clause.rb +80 -0
- data/lib/rubocop/cop/style/empty_literal.rb +1 -0
- data/lib/rubocop/cop/style/encoding.rb +2 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +194 -0
- data/lib/rubocop/cop/style/for.rb +33 -0
- data/lib/rubocop/cop/style/format_string.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +4 -5
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +2 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/missing_else.rb +72 -7
- data/lib/rubocop/cop/style/mixin_usage.rb +3 -5
- data/lib/rubocop/cop/style/module_function.rb +10 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -0
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -0
- data/lib/rubocop/cop/style/nested_modifier.rb +2 -0
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -0
- data/lib/rubocop/cop/style/next.rb +1 -0
- data/lib/rubocop/cop/style/not.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +8 -3
- data/lib/rubocop/cop/style/redundant_return.rb +37 -3
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +74 -32
- data/lib/rubocop/cop/style/semicolon.rb +3 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +14 -23
- data/lib/rubocop/cop/style/stderr_puts.rb +2 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +12 -0
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +29 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -0
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +43 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +7 -54
- data/lib/rubocop/cop/style/trailing_body_on_module.rb +43 -0
- data/lib/rubocop/cop/style/{trailing_comma_in_literal.rb → trailing_comma_in_array_literal.rb} +2 -20
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +56 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +17 -20
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -0
- data/lib/rubocop/cop/style/unless_else.rb +2 -0
- data/lib/rubocop/cop/style/word_array.rb +0 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/team.rb +5 -5
- data/lib/rubocop/cop/util.rb +23 -188
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/file_finder.rb +45 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -14
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +12 -5
- data/lib/rubocop/formatter/json_formatter.rb +1 -1
- data/lib/rubocop/node_pattern.rb +8 -5
- data/lib/rubocop/options.rb +40 -33
- data/lib/rubocop/path_util.rb +5 -8
- data/lib/rubocop/processed_source.rb +53 -0
- data/lib/rubocop/remote_config.rb +1 -1
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +0 -4
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -4
- data/lib/rubocop/rspec/shared_contexts.rb +3 -1
- data/lib/rubocop/rspec/shared_examples.rb +23 -25
- data/lib/rubocop/rspec/support.rb +5 -0
- data/lib/rubocop/runner.rb +3 -2
- data/lib/rubocop/string_util.rb +10 -9
- data/lib/rubocop/target_finder.rb +4 -1
- data/lib/rubocop/token.rb +26 -16
- data/lib/rubocop/version.rb +6 -4
- metadata +31 -17
- data/lib/rubocop/cop/performance/hash_each_methods.rb +0 -129
@@ -126,7 +126,7 @@ module RuboCop
|
|
126
126
|
#
|
127
127
|
# @see http://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html
|
128
128
|
class ReversibleMigration < Cop
|
129
|
-
MSG = '
|
129
|
+
MSG = '%<action>s is not reversible.'.freeze
|
130
130
|
IRREVERSIBLE_CHANGE_TABLE_CALLS = %i[
|
131
131
|
change change_default remove
|
132
132
|
].freeze
|
@@ -177,7 +177,7 @@ module RuboCop
|
|
177
177
|
|
178
178
|
def check_irreversible_schema_statement_node(node)
|
179
179
|
irreversible_schema_statement_call(node) do |method_name|
|
180
|
-
add_offense(node, message: format(MSG, method_name))
|
180
|
+
add_offense(node, message: format(MSG, action: method_name))
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -186,7 +186,7 @@ module RuboCop
|
|
186
186
|
unless node.parent.block_type?
|
187
187
|
add_offense(
|
188
188
|
node,
|
189
|
-
message: format(MSG, 'drop_table(without block)')
|
189
|
+
message: format(MSG, action: 'drop_table(without block)')
|
190
190
|
)
|
191
191
|
end
|
192
192
|
end
|
@@ -198,7 +198,7 @@ module RuboCop
|
|
198
198
|
add_offense(
|
199
199
|
node,
|
200
200
|
message: format(
|
201
|
-
MSG, 'change_column_default(without :from and :to)'
|
201
|
+
MSG, action: 'change_column_default(without :from and :to)'
|
202
202
|
)
|
203
203
|
)
|
204
204
|
end
|
@@ -210,7 +210,7 @@ module RuboCop
|
|
210
210
|
if args.to_a.size < 3
|
211
211
|
add_offense(
|
212
212
|
node,
|
213
|
-
message: format(MSG, 'remove_column(without type)')
|
213
|
+
message: format(MSG, action: 'remove_column(without type)')
|
214
214
|
)
|
215
215
|
end
|
216
216
|
end
|
@@ -221,7 +221,8 @@ module RuboCop
|
|
221
221
|
if arg.hash_type?
|
222
222
|
add_offense(
|
223
223
|
node,
|
224
|
-
message: format(MSG,
|
224
|
+
message: format(MSG,
|
225
|
+
action: 'remove_foreign_key(without table)')
|
225
226
|
)
|
226
227
|
end
|
227
228
|
end
|
@@ -232,7 +233,7 @@ module RuboCop
|
|
232
233
|
if target_rails_version < 4.0
|
233
234
|
add_offense(
|
234
235
|
node,
|
235
|
-
message: format(MSG, 'change_table')
|
236
|
+
message: format(MSG, action: 'change_table')
|
236
237
|
)
|
237
238
|
elsif block.send_type?
|
238
239
|
check_change_table_offense(arg, block)
|
@@ -250,7 +251,7 @@ module RuboCop
|
|
250
251
|
!IRREVERSIBLE_CHANGE_TABLE_CALLS.include?(method_name)
|
251
252
|
add_offense(
|
252
253
|
node,
|
253
|
-
message: format(MSG, "change_table(with #{method_name})")
|
254
|
+
message: format(MSG, action: "change_table(with #{method_name})")
|
254
255
|
)
|
255
256
|
end
|
256
257
|
|
@@ -41,8 +41,9 @@ module RuboCop
|
|
41
41
|
# foo&.bar { |e| e.baz }
|
42
42
|
class SafeNavigation < Cop
|
43
43
|
extend TargetRubyVersion
|
44
|
+
include RangeHelp
|
44
45
|
|
45
|
-
MSG = 'Use safe navigation (`&.`) instead of
|
46
|
+
MSG = 'Use safe navigation (`&.`) instead of `%<try>s`.'.freeze
|
46
47
|
|
47
48
|
def_node_matcher :try_call, <<-PATTERN
|
48
49
|
(send !nil? ${:try :try!} $_ ...)
|
@@ -55,7 +56,7 @@ module RuboCop
|
|
55
56
|
return if try_method == :try && !cop_config['ConvertTry']
|
56
57
|
return unless dispatch.sym_type? && dispatch.value =~ /\w+[=!?]?/
|
57
58
|
|
58
|
-
add_offense(node, message: format(MSG, try_method))
|
59
|
+
add_offense(node, message: format(MSG, try: try_method))
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
@@ -36,13 +36,13 @@ module RuboCop
|
|
36
36
|
# # ...
|
37
37
|
# end
|
38
38
|
class SaveBang < Cop
|
39
|
-
MSG = 'Use
|
40
|
-
.freeze
|
39
|
+
MSG = 'Use `%<prefer>s` instead of `%<current>s` if the return ' \
|
40
|
+
'value is not checked.'.freeze
|
41
41
|
CREATE_MSG = (MSG +
|
42
|
-
' Or check `persisted?` on model returned from
|
43
|
-
|
44
|
-
CREATE_CONDITIONAL_MSG = '
|
45
|
-
.freeze
|
42
|
+
' Or check `persisted?` on model returned from ' \
|
43
|
+
'`%<current>s`.').freeze
|
44
|
+
CREATE_CONDITIONAL_MSG = '`%<method>s` returns a model which is ' \
|
45
|
+
'always truthy.'.freeze
|
46
46
|
|
47
47
|
CREATE_PERSIST_METHODS = %i[create
|
48
48
|
first_or_create find_or_create_by].freeze
|
@@ -72,9 +72,8 @@ module RuboCop
|
|
72
72
|
|
73
73
|
add_offense(node, location: :selector,
|
74
74
|
message: format(CREATE_MSG,
|
75
|
-
"#{node.method_name}!",
|
76
|
-
node.method_name.to_s
|
77
|
-
node.method_name.to_s))
|
75
|
+
prefer: "#{node.method_name}!",
|
76
|
+
current: node.method_name.to_s))
|
78
77
|
end
|
79
78
|
|
80
79
|
def on_send(node)
|
@@ -86,8 +85,8 @@ module RuboCop
|
|
86
85
|
|
87
86
|
add_offense(node, location: :selector,
|
88
87
|
message: format(MSG,
|
89
|
-
"#{node.method_name}!",
|
90
|
-
node.method_name.to_s))
|
88
|
+
prefer: "#{node.method_name}!",
|
89
|
+
current: node.method_name.to_s))
|
91
90
|
end
|
92
91
|
|
93
92
|
def autocorrect(node)
|
@@ -123,7 +122,7 @@ module RuboCop
|
|
123
122
|
unless MODIFY_PERSIST_METHODS.include?(node.method_name)
|
124
123
|
add_offense(node, location: :selector,
|
125
124
|
message: format(CREATE_CONDITIONAL_MSG,
|
126
|
-
node.method_name.to_s))
|
125
|
+
method: node.method_name.to_s))
|
127
126
|
end
|
128
127
|
|
129
128
|
true
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
# user.update_attributes(website: 'example.com')
|
25
25
|
# FileUtils.touch('file')
|
26
26
|
class SkipsModelValidations < Cop
|
27
|
-
MSG = 'Avoid using
|
27
|
+
MSG = 'Avoid using `%<method>s` because it skips validations.'.freeze
|
28
28
|
|
29
29
|
METHODS_WITH_ARGUMENTS = %w[decrement!
|
30
30
|
decrement_counter
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
private
|
59
59
|
|
60
60
|
def message(node)
|
61
|
-
format(MSG, node.method_name)
|
61
|
+
format(MSG, method: node.method_name)
|
62
62
|
end
|
63
63
|
|
64
64
|
def blacklist
|
@@ -14,37 +14,55 @@ module RuboCop
|
|
14
14
|
# When EnforcedStyle is 'flexible' then it's also allowed
|
15
15
|
# to use Time.in_time_zone.
|
16
16
|
#
|
17
|
-
# @example
|
18
|
-
# #
|
17
|
+
# @example EnforcedStyle: strict
|
18
|
+
# # `strict` means that `Time` should be used with `zone`.
|
19
|
+
#
|
20
|
+
# # bad
|
21
|
+
# Time.now
|
22
|
+
# Time.parse('2015-03-02 19:05:37')
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# Time.current
|
26
|
+
# Time.at(timestamp).in_time_zone
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# Time.zone.now
|
30
|
+
# Time.zone.parse('2015-03-02 19:05:37')
|
31
|
+
#
|
32
|
+
# @example EnforcedStyle: flexible (default)
|
33
|
+
# # `flexible` allows usage of `in_time_zone` instead of `zone`.
|
34
|
+
#
|
35
|
+
# # bad
|
19
36
|
# Time.now
|
20
37
|
# Time.parse('2015-03-02 19:05:37')
|
21
38
|
#
|
22
|
-
# #
|
39
|
+
# # good
|
23
40
|
# Time.zone.now
|
24
41
|
# Time.zone.parse('2015-03-02 19:05:37')
|
25
42
|
#
|
26
|
-
# #
|
43
|
+
# # good
|
27
44
|
# Time.current
|
28
|
-
# DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
|
29
45
|
# Time.at(timestamp).in_time_zone
|
30
46
|
class TimeZone < Cop
|
31
47
|
include ConfigurableEnforcedStyle
|
32
48
|
|
33
|
-
MSG = 'Do not use
|
49
|
+
MSG = 'Do not use `%<current>s` without zone. Use `%<prefer>s` ' \
|
50
|
+
'instead.'.freeze
|
34
51
|
|
35
|
-
MSG_ACCEPTABLE = 'Do not use
|
36
|
-
'Use one of
|
52
|
+
MSG_ACCEPTABLE = 'Do not use `%<current>s` without zone. ' \
|
53
|
+
'Use one of %<prefer>s instead.'.freeze
|
37
54
|
|
38
55
|
MSG_LOCALTIME = 'Do not use `Time.localtime` without ' \
|
39
56
|
'offset or zone.'.freeze
|
40
57
|
|
41
|
-
MSG_CURRENT = 'Do not use
|
58
|
+
MSG_CURRENT = 'Do not use `%<current>s`. Use `Time.zone.now` ' \
|
59
|
+
'instead.'.freeze
|
42
60
|
|
43
61
|
TIMECLASS = %i[Time DateTime].freeze
|
44
62
|
|
45
63
|
GOOD_METHODS = %i[zone zone_default find_zone find_zone!].freeze
|
46
64
|
|
47
|
-
DANGEROUS_METHODS = %i[now local new
|
65
|
+
DANGEROUS_METHODS = %i[now local new
|
48
66
|
parse at current].freeze
|
49
67
|
|
50
68
|
ACCEPTED_METHODS = %i[in_time_zone utc getlocal
|
@@ -77,21 +95,25 @@ module RuboCop
|
|
77
95
|
add_offense(node, location: :selector, message: message)
|
78
96
|
end
|
79
97
|
|
98
|
+
# rubocop:disable Metrics/MethodLength
|
80
99
|
def build_message(klass, method_name, node)
|
81
100
|
if acceptable?
|
82
|
-
format(
|
83
|
-
|
84
|
-
|
101
|
+
format(
|
102
|
+
MSG_ACCEPTABLE,
|
103
|
+
current: "#{klass}.#{method_name}",
|
104
|
+
prefer: acceptable_methods(klass, method_name, node).join(', ')
|
105
|
+
)
|
85
106
|
elsif method_name == 'current'
|
86
107
|
format(MSG_CURRENT,
|
87
|
-
"#{klass}.#{method_name}")
|
108
|
+
current: "#{klass}.#{method_name}")
|
88
109
|
else
|
89
110
|
safe_method_name = safe_method(method_name, node)
|
90
111
|
format(MSG,
|
91
|
-
"#{klass}.#{method_name}",
|
92
|
-
"Time.zone.#{safe_method_name}")
|
112
|
+
current: "#{klass}.#{method_name}",
|
113
|
+
prefer: "Time.zone.#{safe_method_name}")
|
93
114
|
end
|
94
115
|
end
|
116
|
+
# rubocop:enable Metrics/MethodLength
|
95
117
|
|
96
118
|
def extract_method_chain(node)
|
97
119
|
chain = []
|
@@ -8,13 +8,6 @@ module RuboCop
|
|
8
8
|
# The use of uniq before pluck is preferred because it executes within
|
9
9
|
# the database.
|
10
10
|
#
|
11
|
-
# @example
|
12
|
-
# # bad
|
13
|
-
# Model.pluck(:id).uniq
|
14
|
-
#
|
15
|
-
# # good
|
16
|
-
# Model.uniq.pluck(:id)
|
17
|
-
#
|
18
11
|
# This cop has two different enforcement modes. When the EnforcedStyle
|
19
12
|
# is conservative (the default) then only calls to pluck on a constant
|
20
13
|
# (i.e. a model class) before uniq are added as offenses.
|
@@ -24,29 +17,45 @@ module RuboCop
|
|
24
17
|
# cannot distinguish between calls to pluck on an ActiveRecord::Relation
|
25
18
|
# vs a call to pluck on an ActiveRecord::Associations::CollectionProxy.
|
26
19
|
#
|
27
|
-
#
|
20
|
+
# Autocorrect is disabled by default for this cop since it may generate
|
21
|
+
# false positives.
|
22
|
+
#
|
23
|
+
# @example EnforcedStyle: conservative (default)
|
24
|
+
# # bad
|
25
|
+
# Model.pluck(:id).uniq
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# Model.uniq.pluck(:id)
|
29
|
+
#
|
30
|
+
# @example EnforcedStyle: aggressive
|
31
|
+
# # bad
|
28
32
|
# # this will return a Relation that pluck is called on
|
29
33
|
# Model.where(cond: true).pluck(:id).uniq
|
30
34
|
#
|
35
|
+
# # bad
|
31
36
|
# # an association on an instance will return a CollectionProxy
|
32
37
|
# instance.assoc.pluck(:id).uniq
|
33
38
|
#
|
34
|
-
#
|
35
|
-
#
|
39
|
+
# # bad
|
40
|
+
# Model.pluck(:id).uniq
|
41
|
+
#
|
42
|
+
# # good
|
43
|
+
# Model.uniq.pluck(:id)
|
36
44
|
#
|
37
45
|
class UniqBeforePluck < RuboCop::Cop::Cop
|
38
46
|
include ConfigurableEnforcedStyle
|
47
|
+
include RangeHelp
|
39
48
|
|
40
|
-
MSG = 'Use
|
49
|
+
MSG = 'Use `%<method>s` before `pluck`.'.freeze
|
41
50
|
NEWLINE = "\n".freeze
|
42
|
-
PATTERN = '[!^block (send (send
|
43
|
-
.freeze
|
51
|
+
PATTERN = '[!^block (send (send %<type>s :pluck ...) ' \
|
52
|
+
'${:uniq :distinct} ...)]'.freeze
|
44
53
|
|
45
54
|
def_node_matcher :conservative_node_match,
|
46
|
-
format(PATTERN, 'const')
|
55
|
+
format(PATTERN, type: 'const')
|
47
56
|
|
48
57
|
def_node_matcher :aggressive_node_match,
|
49
|
-
format(PATTERN, '_')
|
58
|
+
format(PATTERN, type: '_')
|
50
59
|
|
51
60
|
def on_send(node)
|
52
61
|
method = if style == :conservative
|
@@ -57,7 +66,8 @@ module RuboCop
|
|
57
66
|
|
58
67
|
return unless method
|
59
68
|
|
60
|
-
add_offense(node, location: :selector,
|
69
|
+
add_offense(node, location: :selector,
|
70
|
+
message: format(MSG, method: method))
|
61
71
|
end
|
62
72
|
|
63
73
|
def autocorrect(node)
|
@@ -4,8 +4,35 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
6
|
# This cop checks for the use of old-style attribute validation macros.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# validates_acceptance_of :foo
|
11
|
+
# validates_confirmation_of :foo
|
12
|
+
# validates_exclusion_of :foo
|
13
|
+
# validates_format_of :foo
|
14
|
+
# validates_inclusion_of :foo
|
15
|
+
# validates_length_of :foo
|
16
|
+
# validates_numericality_of :foo
|
17
|
+
# validates_presence_of :foo
|
18
|
+
# validates_size_of :foo
|
19
|
+
# validates_uniqueness_of :foo
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# validates :foo, acceptance: true
|
23
|
+
# validates :foo, confirmation: true
|
24
|
+
# validates :foo, exclusion: true
|
25
|
+
# validates :foo, format: true
|
26
|
+
# validates :foo, inclusion: true
|
27
|
+
# validates :foo, length: true
|
28
|
+
# validates :foo, numericality: true
|
29
|
+
# validates :foo, presence: true
|
30
|
+
# validates :foo, size: true
|
31
|
+
# validates :foo, uniqueness: true
|
32
|
+
#
|
7
33
|
class Validation < Cop
|
8
|
-
MSG = 'Prefer the new style validations
|
34
|
+
MSG = 'Prefer the new style validations `%<prefer>s` over ' \
|
35
|
+
'`%<current>s`.'.freeze
|
9
36
|
|
10
37
|
TYPES = %w[
|
11
38
|
acceptance
|
@@ -39,7 +66,8 @@ module RuboCop
|
|
39
66
|
private
|
40
67
|
|
41
68
|
def message(node)
|
42
|
-
format(MSG, preferred_method(node.method_name),
|
69
|
+
format(MSG, prefer: preferred_method(node.method_name),
|
70
|
+
current: node.method_name)
|
43
71
|
end
|
44
72
|
|
45
73
|
def preferred_method(method)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Security
|
6
|
+
# This cop checks for the use of `Kernel#open`.
|
7
|
+
# `Kernel#open` enables not only file access but also process invocation
|
8
|
+
# by prefixing a pipe symbol (e.g., `open("| ls")`). So, it may lead to
|
9
|
+
# a serious security risk by using variable input to the argument of
|
10
|
+
# `Kernel#open`. It would be better to use `File.open` or `IO.popen`
|
11
|
+
# explicitly.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# open(something)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# File.open(something)
|
19
|
+
# IO.popen(something)
|
20
|
+
class Open < Cop
|
21
|
+
MSG = 'The use of `Kernel#open` is a serious security risk.'.freeze
|
22
|
+
|
23
|
+
def_node_matcher :open?, <<-PATTERN
|
24
|
+
(send nil? :open $!str ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def safe?(node)
|
28
|
+
if node.str_type?
|
29
|
+
!node.str_content.empty? && !node.str_content.start_with?('|')
|
30
|
+
elsif node.dstr_type?
|
31
|
+
safe?(node.child_nodes.first)
|
32
|
+
elsif node.send_type? && node.method_name == :+
|
33
|
+
safe?(node.child_nodes.first)
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
open?(node) do |code|
|
41
|
+
return if safe?(code)
|
42
|
+
add_offense(node, location: :selector)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -16,10 +16,12 @@ module RuboCop
|
|
16
16
|
# # good
|
17
17
|
# # Translates from English to Japanese
|
18
18
|
class AsciiComments < Cop
|
19
|
+
include RangeHelp
|
20
|
+
|
19
21
|
MSG = 'Use only ascii symbols in comments.'.freeze
|
20
22
|
|
21
23
|
def investigate(processed_source)
|
22
|
-
processed_source.
|
24
|
+
processed_source.each_comment do |comment|
|
23
25
|
next if comment.text.ascii_only?
|
24
26
|
next if only_allowed_non_ascii_chars?(comment.text)
|
25
27
|
add_offense(comment, location: first_offense_range(comment))
|