rubocop 0.58.2 → 0.59.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 +1 -1
- data/config/default.yml +22 -7
- data/config/disabled.yml +33 -4
- data/config/enabled.yml +4 -11
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +11 -33
- data/lib/rubocop/ast/node/block_node.rb +8 -1
- data/lib/rubocop/ast/node/defined_node.rb +13 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +21 -0
- data/lib/rubocop/ast/node/send_node.rb +3 -12
- data/lib/rubocop/ast/traversal.rb +10 -0
- data/lib/rubocop/cli.rb +4 -1
- data/lib/rubocop/config.rb +21 -5
- data/lib/rubocop/config_loader.rb +2 -0
- data/lib/rubocop/config_loader_resolver.rb +3 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +64 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -0
- data/lib/rubocop/cop/commissioner.rb +2 -0
- data/lib/rubocop/cop/cop.rb +3 -0
- data/lib/rubocop/cop/corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -0
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +2 -0
- data/lib/rubocop/cop/force.rb +1 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/generator.rb +1 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +4 -0
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +5 -4
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +35 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +5 -2
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -0
- data/lib/rubocop/cop/layout/indent_array.rb +1 -0
- data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -0
- data/lib/rubocop/cop/layout/indentation_width.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +34 -11
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -0
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +3 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +16 -8
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -0
- data/lib/rubocop/cop/layout/tab.rb +1 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +9 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +2 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +3 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -0
- data/lib/rubocop/cop/lint/script_permission.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -0
- data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -0
- data/lib/rubocop/cop/lint/unneeded_cop_disable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +3 -0
- data/lib/rubocop/cop/lint/void.rb +1 -0
- data/lib/rubocop/cop/message_annotator.rb +1 -0
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -0
- data/lib/rubocop/cop/metrics/line_length.rb +6 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
- data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +12 -6
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/ignored_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +25 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +5 -3
- data/lib/rubocop/cop/mixin/percent_literal.rb +2 -0
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -1
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -0
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -0
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/file_name.rb +4 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +1 -0
- data/lib/rubocop/cop/naming/uncommunicative_method_param_name.rb +1 -0
- data/lib/rubocop/cop/naming/variable_name.rb +1 -0
- data/lib/rubocop/cop/performance/case_when_splat.rb +11 -7
- data/lib/rubocop/cop/performance/casecmp.rb +33 -42
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +77 -0
- data/lib/rubocop/cop/performance/compare_with_block.rb +3 -0
- data/lib/rubocop/cop/performance/regexp_match.rb +1 -0
- data/lib/rubocop/cop/performance/sample.rb +2 -0
- data/lib/rubocop/cop/performance/size.rb +8 -2
- data/lib/rubocop/cop/performance/string_replacement.rb +1 -0
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -0
- data/lib/rubocop/cop/rails/bulk_change_table.rb +9 -2
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -0
- data/lib/rubocop/cop/rails/delegate.rb +7 -2
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -0
- data/lib/rubocop/cop/rails/find_each.rb +7 -2
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
- data/lib/rubocop/cop/rails/http_status.rb +2 -0
- data/lib/rubocop/cop/rails/inverse_of.rb +4 -0
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +1 -0
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -0
- data/lib/rubocop/cop/rails/save_bang.rb +189 -38
- data/lib/rubocop/cop/rails/time_zone.rb +1 -0
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +6 -3
- data/lib/rubocop/cop/severity.rb +1 -0
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +3 -0
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/copyright.rb +7 -2
- data/lib/rubocop/cop/style/date_time.rb +40 -7
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -0
- data/lib/rubocop/cop/style/empty_else.rb +2 -0
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
- data/lib/rubocop/cop/style/for.rb +56 -10
- data/lib/rubocop/cop/style/format_string_token.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -0
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -5
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +3 -5
- data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/missing_else.rb +1 -0
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +65 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +45 -5
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +13 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -0
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +4 -0
- data/lib/rubocop/cop/style/semicolon.rb +4 -0
- data/lib/rubocop/cop/style/signal_exception.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -8
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -0
- data/lib/rubocop/cop/style/unneeded_condition.rb +13 -2
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -0
- data/lib/rubocop/cop/style/word_array.rb +13 -1
- data/lib/rubocop/cop/team.rb +1 -0
- data/lib/rubocop/cop/variable_force.rb +5 -0
- data/lib/rubocop/cop/variable_force/assignment.rb +4 -0
- data/lib/rubocop/cop/variable_force/branch.rb +4 -0
- data/lib/rubocop/cop/variable_force/branchable.rb +2 -0
- data/lib/rubocop/cop/variable_force/scope.rb +6 -0
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -0
- data/lib/rubocop/file_finder.rb +2 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -4
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -0
- data/lib/rubocop/options.rb +16 -0
- data/lib/rubocop/path_util.rb +16 -1
- data/lib/rubocop/processed_source.rb +4 -0
- data/lib/rubocop/remote_config.rb +6 -1
- data/lib/rubocop/result_cache.rb +1 -0
- data/lib/rubocop/rspec/cop_helper.rb +3 -5
- data/lib/rubocop/rspec/shared_examples.rb +1 -9
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/target_finder.rb +2 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3604f5385c9cdb9a48c56e4b02e873b1f03adc3c
|
4
|
+
data.tar.gz: '039e08df8dc0c3fa47b0a035e650dbdc52068527'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c6b9b6cce39cf4f4977f691a58b43362249e537e798ecb52d639147b8a92df7b32b6aa8553258b66f7093638c0afc11427390ea71cb90c872dbc8510d14359f
|
7
|
+
data.tar.gz: 2f529fb7c60a2ffc733582edec86c1f66059a41e23a0835adf4d3f05593e6e49d0b061d91d06e4e968e7d5c544505e6781a71bfbe20234262eaa080091d86ffe
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
54
54
|
might want to use a conservative version locking in your `Gemfile`:
|
55
55
|
|
56
56
|
```rb
|
57
|
-
gem 'rubocop', '~> 0.
|
57
|
+
gem 'rubocop', '~> 0.59.0', require: false
|
58
58
|
```
|
59
59
|
|
60
60
|
## Quickstart
|
data/config/default.yml
CHANGED
@@ -96,7 +96,7 @@ AllCops:
|
|
96
96
|
# cops in user configuration will be enabled even if they don't set the
|
97
97
|
# Enabled parameter.
|
98
98
|
# When `EnabledByDefault` is `true`, all cops, even those in disabled.yml,
|
99
|
-
# are enabled by default.
|
99
|
+
# are enabled by default. Cops can still be disabled in user configuration.
|
100
100
|
# Note that it is invalid to set both EnabledByDefault and DisabledByDefault
|
101
101
|
# to true in the same configuration.
|
102
102
|
EnabledByDefault: false
|
@@ -132,11 +132,11 @@ AllCops:
|
|
132
132
|
# use the oldest officially supported Ruby version (currently Ruby 2.2).
|
133
133
|
TargetRubyVersion: ~
|
134
134
|
# What version of Rails is the inspected code using? If a value is specified
|
135
|
-
# for TargetRailsVersion then it is used.
|
135
|
+
# for TargetRailsVersion then it is used. Acceptable values are specificed
|
136
136
|
# as a float (i.e. 5.1); the patch version of Rails should not be included.
|
137
137
|
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
|
138
138
|
# gems.locked file to find the version of Rails that has been bound to the
|
139
|
-
# application.
|
139
|
+
# application. If neither of those files exist, RuboCop will use Rails 5.0
|
140
140
|
# as the default.
|
141
141
|
TargetRailsVersion: ~
|
142
142
|
|
@@ -669,8 +669,8 @@ Layout/TrailingWhitespace:
|
|
669
669
|
#################### Naming ##########################
|
670
670
|
|
671
671
|
Naming/FileName:
|
672
|
-
#
|
673
|
-
# excludes here.
|
672
|
+
# Camel case file names listed in `AllCops:Include` and all file names listed
|
673
|
+
# in `AllCops:Exclude` are excluded by default. Add extra excludes here.
|
674
674
|
Exclude: []
|
675
675
|
# When `true`, requires that each source file should define a class or module
|
676
676
|
# with a name which matches the file name (converted to ... case).
|
@@ -798,6 +798,7 @@ Naming/UncommunicativeMethodParamName:
|
|
798
798
|
- in
|
799
799
|
- at
|
800
800
|
- ip
|
801
|
+
- db
|
801
802
|
# Blacklisted names that will register an offense
|
802
803
|
ForbiddenNames: []
|
803
804
|
|
@@ -1015,7 +1016,7 @@ Style/ConditionalAssignment:
|
|
1015
1016
|
# You can override the default Notice in your .rubocop.yml file.
|
1016
1017
|
#
|
1017
1018
|
# In order to use autocorrect, you must supply a value for the
|
1018
|
-
# `AutocorrectNotice` key that matches the regexp Notice.
|
1019
|
+
# `AutocorrectNotice` key that matches the regexp Notice. A blank
|
1019
1020
|
# `AutocorrectNotice` will cause an error during autocorrect.
|
1020
1021
|
#
|
1021
1022
|
# Autocorrect will add a copyright notice in a comment at the top
|
@@ -1246,6 +1247,12 @@ Style/Next:
|
|
1246
1247
|
- skip_modifier_ifs
|
1247
1248
|
- always
|
1248
1249
|
|
1250
|
+
Style/NilComparison:
|
1251
|
+
EnforcedStyle: predicate
|
1252
|
+
SupportedStyles:
|
1253
|
+
- predicate
|
1254
|
+
- comparison
|
1255
|
+
|
1249
1256
|
Style/NonNilCheck:
|
1250
1257
|
# With `IncludeSemanticChanges` set to `true`, this cop reports offenses for
|
1251
1258
|
# `!x.nil?` and autocorrects that and `x != nil` to solely `x`, which is
|
@@ -1270,6 +1277,7 @@ Style/NumericPredicate:
|
|
1270
1277
|
SupportedStyles:
|
1271
1278
|
- predicate
|
1272
1279
|
- comparison
|
1280
|
+
IgnoredMethods: []
|
1273
1281
|
# Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
|
1274
1282
|
# false positives.
|
1275
1283
|
Exclude:
|
@@ -1528,7 +1536,7 @@ Style/WordArray:
|
|
1528
1536
|
# bracket style: ['word1', 'word2']
|
1529
1537
|
- brackets
|
1530
1538
|
# The `MinSize` option causes the `WordArray` rule to be ignored for arrays
|
1531
|
-
# smaller than a certain size.
|
1539
|
+
# smaller than a certain size. The rule is only applied to arrays
|
1532
1540
|
# whose element count is greater than or equal to `MinSize`.
|
1533
1541
|
MinSize: 2
|
1534
1542
|
# The regular expression `WordRegex` decides what is considered a word.
|
@@ -1802,6 +1810,9 @@ Rails/RefuteMethods:
|
|
1802
1810
|
Include:
|
1803
1811
|
- '**/test/**/*'
|
1804
1812
|
|
1813
|
+
Rails/RelativeDateConstant:
|
1814
|
+
AutoCorrect: false
|
1815
|
+
|
1805
1816
|
Rails/RequestReferer:
|
1806
1817
|
EnforcedStyle: referer
|
1807
1818
|
SupportedStyles:
|
@@ -1819,6 +1830,10 @@ Rails/SafeNavigation:
|
|
1819
1830
|
# implement the intended method. `try` will not raise an exception for this.
|
1820
1831
|
ConvertTry: false
|
1821
1832
|
|
1833
|
+
Rails/SaveBang:
|
1834
|
+
AllowImplicitReturn: true
|
1835
|
+
AllowedReceivers: []
|
1836
|
+
|
1822
1837
|
Rails/ScopeArgs:
|
1823
1838
|
Include:
|
1824
1839
|
- app/models/**/*.rb
|
data/config/disabled.yml
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
# These are all the cops that are disabled in the default configuration.
|
2
2
|
|
3
|
+
Bundler/GemComment:
|
4
|
+
Description: 'Add a comment describing each gem.'
|
5
|
+
Enabled: false
|
6
|
+
Include:
|
7
|
+
- '**/*.gemfile'
|
8
|
+
- '**/Gemfile'
|
9
|
+
- '**/gems.rb'
|
10
|
+
Whitelist: []
|
11
|
+
|
3
12
|
Layout/ClassStructure:
|
4
13
|
Description: 'Enforces a configured order of definitions within a class body.'
|
5
14
|
StyleGuide: 'https://github.com/rubocop-hq/ruby-style-guide#consistent-classes'
|
6
15
|
Enabled: false
|
7
16
|
|
8
|
-
Layout/EmptyLineAfterGuardClause:
|
9
|
-
Description: 'Add empty line after guard clause.'
|
10
|
-
Enabled: false
|
11
|
-
|
12
17
|
Layout/FirstArrayElementLineBreak:
|
13
18
|
Description: >-
|
14
19
|
Checks for a line break before the first element in a
|
@@ -42,6 +47,20 @@ Lint/NumberConversion:
|
|
42
47
|
Description: 'Checks unsafe usage of number conversion methods.'
|
43
48
|
Enabled: false
|
44
49
|
|
50
|
+
Performance/CaseWhenSplat:
|
51
|
+
Description: >-
|
52
|
+
Reordering `when` conditions with a splat to the end
|
53
|
+
of the `when` branches can improve performance.
|
54
|
+
Enabled: false
|
55
|
+
AutoCorrect: false
|
56
|
+
|
57
|
+
Performance/ChainArrayAllocation:
|
58
|
+
Description: >-
|
59
|
+
Instead of chaining array methods that allocate new arrays, mutate an
|
60
|
+
existing array.
|
61
|
+
Reference: 'https://twitter.com/schneems/status/1034123879978029057'
|
62
|
+
Enabled: false
|
63
|
+
|
45
64
|
# By default, the rails cops are not run. Override in project or home
|
46
65
|
# directory .rubocop.yml files, or by giving the -R/--rails option.
|
47
66
|
Rails:
|
@@ -65,6 +84,12 @@ Style/Copyright:
|
|
65
84
|
Description: 'Include a copyright notice in each file before any code.'
|
66
85
|
Enabled: false
|
67
86
|
|
87
|
+
Style/DateTime:
|
88
|
+
Description: 'Use Time over DateTime.'
|
89
|
+
StyleGuide: '#date--time'
|
90
|
+
Enabled: false
|
91
|
+
AllowCoercion: false
|
92
|
+
|
68
93
|
Style/DocumentationMethod:
|
69
94
|
Description: 'Public methods.'
|
70
95
|
Enabled: false
|
@@ -105,6 +130,10 @@ Style/MissingElse:
|
|
105
130
|
Style/EmptyElse is configured to style "both"
|
106
131
|
Enabled: false
|
107
132
|
|
133
|
+
Style/MultilineMethodSignature:
|
134
|
+
Description: 'Avoid multi-line method signatures.'
|
135
|
+
Enabled: false
|
136
|
+
|
108
137
|
Style/OptionHash:
|
109
138
|
Description: "Don't use option hashes when you can use keyword arguments."
|
110
139
|
Enabled: false
|
data/config/enabled.yml
CHANGED
@@ -127,6 +127,10 @@ Layout/EmptyComment:
|
|
127
127
|
Description: 'Checks empty comment.'
|
128
128
|
Enabled: true
|
129
129
|
|
130
|
+
Layout/EmptyLineAfterGuardClause:
|
131
|
+
Description: 'Add empty line after guard clause.'
|
132
|
+
Enabled: true
|
133
|
+
|
130
134
|
Layout/EmptyLineAfterMagicComment:
|
131
135
|
Description: 'Add an empty line after magic comments to separate them from code.'
|
132
136
|
StyleGuide: '#separate-magic-comments-from-code'
|
@@ -921,12 +925,6 @@ Performance/Caller:
|
|
921
925
|
Use `caller(n..n)` instead of `caller`.
|
922
926
|
Enabled: true
|
923
927
|
|
924
|
-
Performance/CaseWhenSplat:
|
925
|
-
Description: >-
|
926
|
-
Place `when` conditions that use splat at the end
|
927
|
-
of the list of `when` branches.
|
928
|
-
Enabled: true
|
929
|
-
|
930
928
|
Performance/Casecmp:
|
931
929
|
Description: >-
|
932
930
|
Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`..
|
@@ -1459,11 +1457,6 @@ Style/ConditionalAssignment:
|
|
1459
1457
|
of assigning that variable inside of each branch.
|
1460
1458
|
Enabled: true
|
1461
1459
|
|
1462
|
-
Style/DateTime:
|
1463
|
-
Description: 'Use Date or Time over DateTime.'
|
1464
|
-
StyleGuide: '#date--time'
|
1465
|
-
Enabled: true
|
1466
|
-
|
1467
1460
|
Style/DefWithParentheses:
|
1468
1461
|
Description: 'Use def with parentheses when there are arguments.'
|
1469
1462
|
StyleGuide: '#method-parens'
|
data/lib/rubocop.rb
CHANGED
@@ -40,6 +40,7 @@ require_relative 'rubocop/ast/node/array_node'
|
|
40
40
|
require_relative 'rubocop/ast/node/block_node'
|
41
41
|
require_relative 'rubocop/ast/node/case_node'
|
42
42
|
require_relative 'rubocop/ast/node/def_node'
|
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'
|
45
46
|
require_relative 'rubocop/ast/node/hash_node'
|
@@ -111,6 +112,7 @@ require_relative 'rubocop/cop/mixin/first_element_line_break'
|
|
111
112
|
require_relative 'rubocop/cop/mixin/frozen_string_literal'
|
112
113
|
require_relative 'rubocop/cop/mixin/hash_alignment'
|
113
114
|
require_relative 'rubocop/cop/mixin/ignored_pattern'
|
115
|
+
require_relative 'rubocop/cop/mixin/ignored_methods'
|
114
116
|
require_relative 'rubocop/cop/mixin/integer_node'
|
115
117
|
require_relative 'rubocop/cop/mixin/match_range'
|
116
118
|
require_relative 'rubocop/cop/mixin/method_complexity'
|
@@ -158,6 +160,7 @@ require_relative 'rubocop/cop/correctors/string_literal_corrector'
|
|
158
160
|
require_relative 'rubocop/cop/correctors/unused_arg_corrector'
|
159
161
|
|
160
162
|
require_relative 'rubocop/cop/bundler/duplicated_gem'
|
163
|
+
require_relative 'rubocop/cop/bundler/gem_comment'
|
161
164
|
require_relative 'rubocop/cop/bundler/insecure_protocol_source'
|
162
165
|
require_relative 'rubocop/cop/bundler/ordered_gems'
|
163
166
|
|
@@ -378,6 +381,7 @@ require_relative 'rubocop/cop/performance/times_map'
|
|
378
381
|
require_relative 'rubocop/cop/performance/unfreeze_string'
|
379
382
|
require_relative 'rubocop/cop/performance/unneeded_sort'
|
380
383
|
require_relative 'rubocop/cop/performance/uri_default_parser'
|
384
|
+
require_relative 'rubocop/cop/performance/chain_array_allocation'
|
381
385
|
|
382
386
|
require_relative 'rubocop/cop/style/access_modifier_declarations'
|
383
387
|
require_relative 'rubocop/cop/style/alias'
|
@@ -459,6 +463,7 @@ require_relative 'rubocop/cop/style/module_function'
|
|
459
463
|
require_relative 'rubocop/cop/style/multiline_block_chain'
|
460
464
|
require_relative 'rubocop/cop/style/multiline_if_then'
|
461
465
|
require_relative 'rubocop/cop/style/multiline_if_modifier'
|
466
|
+
require_relative 'rubocop/cop/style/multiline_method_signature'
|
462
467
|
require_relative 'rubocop/cop/style/multiline_memoization'
|
463
468
|
require_relative 'rubocop/cop/style/multiline_ternary_operator'
|
464
469
|
require_relative 'rubocop/cop/style/multiple_comparison'
|
data/lib/rubocop/ast/builder.rb
CHANGED
data/lib/rubocop/ast/node.rb
CHANGED
@@ -24,7 +24,6 @@ module RuboCop
|
|
24
24
|
|
25
25
|
# <=> isn't included here, because it doesn't return a boolean.
|
26
26
|
COMPARISON_OPERATORS = %i[== === != <= >= > <].freeze
|
27
|
-
ARITHMETIC_OPERATORS = %i[+ - * / % **].freeze
|
28
27
|
|
29
28
|
TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
|
30
29
|
hash regexp true irange erange complex
|
@@ -182,6 +181,7 @@ module RuboCop
|
|
182
181
|
|
183
182
|
children.each do |child|
|
184
183
|
next unless child.is_a?(Node)
|
184
|
+
|
185
185
|
yield child if types.empty? || types.include?(child.type)
|
186
186
|
end
|
187
187
|
|
@@ -280,6 +280,7 @@ module RuboCop
|
|
280
280
|
|
281
281
|
def line_count
|
282
282
|
return 0 unless source_range
|
283
|
+
|
283
284
|
source_range.last_line - source_range.first_line + 1
|
284
285
|
end
|
285
286
|
|
@@ -297,16 +298,13 @@ module RuboCop
|
|
297
298
|
{(send $_ ...) (block (send $_ ...) ...)}
|
298
299
|
PATTERN
|
299
300
|
|
300
|
-
def_node_matcher :method_name, <<-PATTERN
|
301
|
-
{(send _ $_ ...) (block (send _ $_ ...) ...)}
|
302
|
-
PATTERN
|
303
|
-
|
304
301
|
# Note: for masgn, #asgn_rhs will be an array node
|
305
302
|
def_node_matcher :asgn_rhs, '[assignment? (... $_)]'
|
306
303
|
def_node_matcher :str_content, '(str $_)'
|
307
304
|
|
308
305
|
def const_name
|
309
306
|
return unless const_type?
|
307
|
+
|
310
308
|
namespace, name = *self
|
311
309
|
if namespace && !namespace.cbase_type?
|
312
310
|
"#{namespace.const_name}::#{name}"
|
@@ -360,15 +358,6 @@ module RuboCop
|
|
360
358
|
source_length.zero?
|
361
359
|
end
|
362
360
|
|
363
|
-
def asgn_method_call?
|
364
|
-
!COMPARISON_OPERATORS.include?(method_name) &&
|
365
|
-
method_name.to_s.end_with?('='.freeze)
|
366
|
-
end
|
367
|
-
|
368
|
-
def arithmetic_operation?
|
369
|
-
ARITHMETIC_OPERATORS.include?(method_name)
|
370
|
-
end
|
371
|
-
|
372
361
|
def_node_matcher :equals_asgn?, <<-PATTERN
|
373
362
|
{lvasgn ivasgn cvasgn gvasgn casgn masgn}
|
374
363
|
PATTERN
|
@@ -376,7 +365,7 @@ module RuboCop
|
|
376
365
|
def_node_matcher :shorthand_asgn?, '{op_asgn or_asgn and_asgn}'
|
377
366
|
|
378
367
|
def_node_matcher :assignment?, <<-PATTERN
|
379
|
-
{equals_asgn? shorthand_asgn?
|
368
|
+
{equals_asgn? shorthand_asgn?}
|
380
369
|
PATTERN
|
381
370
|
|
382
371
|
# Some cops treat the shovel operator as a kind of assignment.
|
@@ -414,10 +403,9 @@ module RuboCop
|
|
414
403
|
define_method(recursive_kind) do
|
415
404
|
case type
|
416
405
|
when :send
|
417
|
-
receiver, method_name, *args = *self
|
418
406
|
[*COMPARISON_OPERATORS, :!, :<=>].include?(method_name) &&
|
419
407
|
receiver.send(recursive_kind) &&
|
420
|
-
|
408
|
+
arguments.all?(&recursive_kind)
|
421
409
|
when :begin, :pair, *OPERATOR_KEYWORDS, *COMPOSITE_LITERALS
|
422
410
|
children.all?(&recursive_kind)
|
423
411
|
else
|
@@ -435,7 +423,7 @@ module RuboCop
|
|
435
423
|
end
|
436
424
|
|
437
425
|
def keyword?
|
438
|
-
return true if special_keyword? ||
|
426
|
+
return true if special_keyword? || send_type? && prefix_not?
|
439
427
|
return false unless KEYWORDS.include?(type)
|
440
428
|
|
441
429
|
!OPERATOR_KEYWORDS.include?(type) || loc.operator.is?(type.to_s)
|
@@ -449,24 +437,16 @@ module RuboCop
|
|
449
437
|
OPERATOR_KEYWORDS.include?(type)
|
450
438
|
end
|
451
439
|
|
452
|
-
def keyword_not?
|
453
|
-
_receiver, method_name, *args = *self
|
454
|
-
args.empty? && method_name == :! && loc.selector.is?('not'.freeze)
|
455
|
-
end
|
456
|
-
|
457
|
-
def keyword_bang?
|
458
|
-
_receiver, method_name, *args = *self
|
459
|
-
args.empty? && method_name == :! && loc.selector.is?('!'.freeze)
|
460
|
-
end
|
461
|
-
|
462
440
|
def unary_operation?
|
463
441
|
return false unless loc.respond_to?(:selector) && loc.selector
|
442
|
+
|
464
443
|
Cop::Util.operator?(loc.selector.source.to_sym) &&
|
465
444
|
source_range.begin_pos == loc.selector.begin_pos
|
466
445
|
end
|
467
446
|
|
468
447
|
def binary_operation?
|
469
448
|
return false unless loc.respond_to?(:selector) && loc.selector
|
449
|
+
|
470
450
|
Cop::Util.operator?(method_name) &&
|
471
451
|
source_range.begin_pos != loc.selector.begin_pos
|
472
452
|
end
|
@@ -476,14 +456,11 @@ module RuboCop
|
|
476
456
|
end
|
477
457
|
|
478
458
|
def chained?
|
479
|
-
|
480
|
-
|
481
|
-
receiver, _method_name, *_args = *parent
|
482
|
-
equal?(receiver)
|
459
|
+
parent && parent.send_type? && eql?(parent.receiver)
|
483
460
|
end
|
484
461
|
|
485
462
|
def argument?
|
486
|
-
parent && parent.send_type?
|
463
|
+
parent && parent.send_type? && parent.arguments.include?(self)
|
487
464
|
end
|
488
465
|
|
489
466
|
def numeric_type?
|
@@ -641,6 +618,7 @@ module RuboCop
|
|
641
618
|
# `class_eval` with no receiver applies to whatever module or class
|
642
619
|
# we are currently in
|
643
620
|
return unless (receiver = ancestor.receiver)
|
621
|
+
|
644
622
|
yield unless receiver.const_type?
|
645
623
|
receiver.const_name
|
646
624
|
elsif !new_class_or_module_block?(ancestor)
|
@@ -32,6 +32,13 @@ module RuboCop
|
|
32
32
|
node_parts[2]
|
33
33
|
end
|
34
34
|
|
35
|
+
# The name of the dispatched method as a symbol.
|
36
|
+
#
|
37
|
+
# @return [Symbol] the name of the dispatched method
|
38
|
+
def method_name
|
39
|
+
send_node.method_name
|
40
|
+
end
|
41
|
+
|
35
42
|
# Checks whether this block takes any arguments.
|
36
43
|
#
|
37
44
|
# @return [Boolean] whether this `block` node takes any arguments
|
@@ -101,7 +108,7 @@ module RuboCop
|
|
101
108
|
#
|
102
109
|
# @return [Boolean] whether the `block` node body is a void context
|
103
110
|
def void_context?
|
104
|
-
VOID_CONTEXT_METHODS.include?(
|
111
|
+
VOID_CONTEXT_METHODS.include?(method_name)
|
105
112
|
end
|
106
113
|
end
|
107
114
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `defined?` nodes. This will be used in place of a
|
6
|
+
# plain node when the builder constructs the AST, making its methods
|
7
|
+
# available to all `send` nodes within RuboCop.
|
8
|
+
class DefinedNode < Node
|
9
|
+
include ParameterizedNode
|
10
|
+
include MethodDispatchNode
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -8,6 +8,8 @@ module RuboCop
|
|
8
8
|
extend NodePattern::Macros
|
9
9
|
include MethodIdentifierPredicates
|
10
10
|
|
11
|
+
ARITHMETIC_OPERATORS = %i[+ - * / % **].freeze
|
12
|
+
|
11
13
|
# The receiving node of the method dispatch.
|
12
14
|
#
|
13
15
|
# @return [Node, nil] the receiver of the dispatched method or `nil`
|
@@ -29,6 +31,14 @@ module RuboCop
|
|
29
31
|
node_parts[2..-1]
|
30
32
|
end
|
31
33
|
|
34
|
+
# The `block` node associated with this method dispatch, if any.
|
35
|
+
#
|
36
|
+
# @return [BlockNode, nil] the `block` node associated with this method
|
37
|
+
# call or `nil`
|
38
|
+
def block_node
|
39
|
+
parent if block_literal?
|
40
|
+
end
|
41
|
+
|
32
42
|
# Checks whether the dispatched method is a macro method. A macro method
|
33
43
|
# is defined as a method that sits in a class, module, or block body and
|
34
44
|
# has an implicit receiver.
|
@@ -80,6 +90,7 @@ module RuboCop
|
|
80
90
|
def setter_method?
|
81
91
|
loc.respond_to?(:operator) && loc.operator
|
82
92
|
end
|
93
|
+
alias assignment? setter_method?
|
83
94
|
|
84
95
|
# Checks whether the dispatched method uses a dot to connect the
|
85
96
|
# receiver and the method name.
|
@@ -132,12 +143,12 @@ module RuboCop
|
|
132
143
|
parent && parent.block_type? && eql?(parent.send_node)
|
133
144
|
end
|
134
145
|
|
135
|
-
#
|
146
|
+
# Checks whether this node is an arithmetic operation
|
136
147
|
#
|
137
|
-
# @return [
|
138
|
-
#
|
139
|
-
def
|
140
|
-
|
148
|
+
# @return [Boolean] whether the dispatched method is an arithmetic
|
149
|
+
# operation
|
150
|
+
def arithmetic_operation?
|
151
|
+
ARITHMETIC_OPERATORS.include?(method_name)
|
141
152
|
end
|
142
153
|
|
143
154
|
# Checks if this node is part of a chain of `def` modifiers.
|