rubocop 0.47.1 → 0.48.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.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -16
  3. data/config/default.yml +203 -115
  4. data/config/disabled.yml +0 -5
  5. data/config/enabled.yml +92 -8
  6. data/lib/rubocop.rb +24 -1
  7. data/lib/rubocop/ast/builder.rb +7 -2
  8. data/lib/rubocop/ast/node.rb +23 -20
  9. data/lib/rubocop/ast/node/and_node.rb +37 -0
  10. data/lib/rubocop/ast/node/array_node.rb +4 -1
  11. data/lib/rubocop/ast/node/case_node.rb +1 -0
  12. data/lib/rubocop/ast/node/ensure_node.rb +25 -0
  13. data/lib/rubocop/ast/node/hash_node.rb +10 -3
  14. data/lib/rubocop/ast/node/if_node.rb +2 -0
  15. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +23 -0
  16. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +35 -0
  17. data/lib/rubocop/ast/node/or_node.rb +37 -0
  18. data/lib/rubocop/ast/node/resbody_node.rb +25 -0
  19. data/lib/rubocop/ast/node/send_node.rb +190 -0
  20. data/lib/rubocop/ast/node/when_node.rb +1 -1
  21. data/lib/rubocop/ast/traversal.rb +15 -15
  22. data/lib/rubocop/comment_config.rb +1 -1
  23. data/lib/rubocop/config.rb +39 -15
  24. data/lib/rubocop/config_loader.rb +34 -13
  25. data/lib/rubocop/cop/bundler/ordered_gems.rb +23 -4
  26. data/lib/rubocop/cop/commissioner.rb +4 -0
  27. data/lib/rubocop/cop/cop.rb +5 -0
  28. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +53 -0
  29. data/lib/rubocop/cop/lint/debugger.rb +8 -1
  30. data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -1
  31. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +2 -4
  32. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
  33. data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -1
  34. data/lib/rubocop/cop/lint/empty_ensure.rb +6 -2
  35. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  36. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +20 -18
  37. data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -3
  38. data/lib/rubocop/cop/lint/literal_in_condition.rb +1 -1
  39. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  40. data/lib/rubocop/cop/lint/multiple_compare.rb +5 -3
  41. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +26 -18
  42. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +7 -8
  43. data/lib/rubocop/cop/lint/require_parentheses.rb +7 -13
  44. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +7 -3
  45. data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -6
  46. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +7 -8
  47. data/lib/rubocop/cop/lint/unneeded_disable.rb +35 -11
  48. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
  49. data/lib/rubocop/cop/lint/unreachable_code.rb +5 -2
  50. data/lib/rubocop/cop/lint/unused_block_argument.rb +6 -6
  51. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -1
  52. data/lib/rubocop/cop/lint/useless_comparison.rb +5 -4
  53. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  54. data/lib/rubocop/cop/message_annotator.rb +7 -3
  55. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  56. data/lib/rubocop/cop/metrics/block_nesting.rb +4 -4
  57. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
  58. data/lib/rubocop/cop/metrics/line_length.rb +2 -9
  59. data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -3
  60. data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
  61. data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
  62. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -2
  63. data/lib/rubocop/cop/mixin/check_assignment.rb +6 -6
  64. data/lib/rubocop/cop/mixin/duplication.rb +1 -1
  65. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  66. data/lib/rubocop/cop/mixin/ignored_pattern.rb +27 -0
  67. data/lib/rubocop/cop/mixin/method_preference.rb +2 -0
  68. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +17 -29
  69. data/lib/rubocop/cop/mixin/on_method_def.rb +3 -3
  70. data/lib/rubocop/cop/mixin/percent_literal.rb +27 -0
  71. data/lib/rubocop/cop/mixin/rescue_node.rb +21 -0
  72. data/lib/rubocop/cop/mixin/safe_mode.rb +1 -1
  73. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  74. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -1
  75. data/lib/rubocop/cop/mixin/target_rails_version.rb +16 -0
  76. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
  77. data/lib/rubocop/cop/offense.rb +3 -3
  78. data/lib/rubocop/cop/performance/casecmp.rb +1 -1
  79. data/lib/rubocop/cop/performance/detect.rb +2 -1
  80. data/lib/rubocop/cop/performance/double_start_end_with.rb +35 -1
  81. data/lib/rubocop/cop/performance/end_with.rb +3 -1
  82. data/lib/rubocop/cop/performance/flat_map.rb +6 -6
  83. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -2
  84. data/lib/rubocop/cop/performance/range_include.rb +3 -1
  85. data/lib/rubocop/cop/performance/redundant_match.rb +6 -5
  86. data/lib/rubocop/cop/performance/regexp_match.rb +10 -3
  87. data/lib/rubocop/cop/performance/reverse_each.rb +2 -1
  88. data/lib/rubocop/cop/performance/size.rb +6 -11
  89. data/lib/rubocop/cop/performance/start_with.rb +3 -1
  90. data/lib/rubocop/cop/performance/string_replacement.rb +13 -18
  91. data/lib/rubocop/cop/performance/times_map.rb +4 -4
  92. data/lib/rubocop/cop/rails/action_filter.rb +42 -42
  93. data/lib/rubocop/cop/rails/active_support_aliases.rb +68 -0
  94. data/lib/rubocop/cop/rails/blank.rb +131 -0
  95. data/lib/rubocop/cop/rails/date.rb +25 -28
  96. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +5 -7
  97. data/lib/rubocop/cop/rails/dynamic_find_by.rb +7 -3
  98. data/lib/rubocop/cop/rails/exit.rb +9 -9
  99. data/lib/rubocop/cop/rails/file_path.rb +5 -14
  100. data/lib/rubocop/cop/rails/find_by.rb +8 -10
  101. data/lib/rubocop/cop/rails/find_each.rb +6 -9
  102. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -0
  103. data/lib/rubocop/cop/rails/http_positional_arguments.rb +15 -7
  104. data/lib/rubocop/cop/rails/output.rb +3 -5
  105. data/lib/rubocop/cop/rails/output_safety.rb +4 -8
  106. data/lib/rubocop/cop/rails/pluralization_grammar.rb +25 -24
  107. data/lib/rubocop/cop/rails/present.rb +137 -0
  108. data/lib/rubocop/cop/rails/read_write_attribute.rb +9 -18
  109. data/lib/rubocop/cop/rails/relative_date_constant.rb +53 -0
  110. data/lib/rubocop/cop/rails/request_referer.rb +7 -4
  111. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -2
  112. data/lib/rubocop/cop/rails/safe_navigation.rb +2 -1
  113. data/lib/rubocop/cop/rails/save_bang.rb +10 -10
  114. data/lib/rubocop/cop/rails/skips_model_validations.rb +23 -6
  115. data/lib/rubocop/cop/rails/time_zone.rb +20 -18
  116. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -2
  117. data/lib/rubocop/cop/rails/validation.rb +8 -11
  118. data/lib/rubocop/cop/registry.rb +3 -3
  119. data/lib/rubocop/cop/security/json_load.rb +1 -1
  120. data/lib/rubocop/cop/security/marshal_load.rb +5 -1
  121. data/lib/rubocop/cop/security/yaml_load.rb +3 -3
  122. data/lib/rubocop/cop/severity.rb +1 -1
  123. data/lib/rubocop/cop/style/alias.rb +5 -5
  124. data/lib/rubocop/cop/style/align_hash.rb +1 -1
  125. data/lib/rubocop/cop/style/align_parameters.rb +5 -5
  126. data/lib/rubocop/cop/style/and_or.rb +16 -31
  127. data/lib/rubocop/cop/style/attr.rb +14 -8
  128. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +8 -11
  129. data/lib/rubocop/cop/style/block_delimiters.rb +11 -13
  130. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -23
  131. data/lib/rubocop/cop/style/case_indentation.rb +2 -0
  132. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  133. data/lib/rubocop/cop/style/class_check.rb +5 -7
  134. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +5 -4
  135. data/lib/rubocop/cop/style/collection_methods.rb +8 -8
  136. data/lib/rubocop/cop/style/colon_method_call.rb +2 -9
  137. data/lib/rubocop/cop/style/conditional_assignment.rb +38 -45
  138. data/lib/rubocop/cop/style/constant_name.rb +1 -1
  139. data/lib/rubocop/cop/style/documentation_method.rb +1 -0
  140. data/lib/rubocop/cop/style/dot_position.rb +3 -7
  141. data/lib/rubocop/cop/style/double_negation.rb +2 -1
  142. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  143. data/lib/rubocop/cop/style/empty_else.rb +2 -2
  144. data/lib/rubocop/cop/style/empty_line_after_magic_comment.rb +63 -0
  145. data/lib/rubocop/cop/style/empty_line_between_defs.rb +74 -4
  146. data/lib/rubocop/cop/style/empty_lines_around_begin_body.rb +42 -0
  147. data/lib/rubocop/cop/style/empty_lines_around_exception_handling_keywords.rb +127 -0
  148. data/lib/rubocop/cop/style/empty_literal.rb +17 -9
  149. data/lib/rubocop/cop/style/end_of_line.rb +25 -3
  150. data/lib/rubocop/cop/style/file_name.rb +1 -1
  151. data/lib/rubocop/cop/style/first_method_argument_line_break.rb +1 -1
  152. data/lib/rubocop/cop/style/first_parameter_indentation.rb +17 -19
  153. data/lib/rubocop/cop/style/for.rb +2 -4
  154. data/lib/rubocop/cop/style/format_string.rb +5 -4
  155. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  156. data/lib/rubocop/cop/style/identical_conditional_branches.rb +27 -1
  157. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  158. data/lib/rubocop/cop/style/indent_assignment.rb +2 -2
  159. data/lib/rubocop/cop/style/indent_hash.rb +2 -1
  160. data/lib/rubocop/cop/style/indent_heredoc.rb +173 -0
  161. data/lib/rubocop/cop/style/indentation_width.rb +61 -29
  162. data/lib/rubocop/cop/style/inverse_methods.rb +130 -0
  163. data/lib/rubocop/cop/style/lambda_call.rb +15 -11
  164. data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -4
  165. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +26 -14
  166. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -16
  167. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
  168. data/lib/rubocop/cop/style/missing_else.rb +4 -3
  169. data/lib/rubocop/cop/style/mixin_grouping.rb +97 -0
  170. data/lib/rubocop/cop/style/multiline_memoization.rb +38 -5
  171. data/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb +2 -3
  172. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +38 -19
  173. data/lib/rubocop/cop/style/mutable_constant.rb +5 -1
  174. data/lib/rubocop/cop/style/negated_if.rb +73 -1
  175. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +21 -19
  176. data/lib/rubocop/cop/style/next.rb +5 -5
  177. data/lib/rubocop/cop/style/non_nil_check.rb +7 -10
  178. data/lib/rubocop/cop/style/not.rb +3 -4
  179. data/lib/rubocop/cop/style/numeric_literals.rb +25 -3
  180. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  181. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
  182. data/lib/rubocop/cop/style/op_method.rb +2 -2
  183. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -3
  184. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +52 -6
  185. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  186. data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -9
  187. data/lib/rubocop/cop/style/raise_args.rb +28 -24
  188. data/lib/rubocop/cop/style/redundant_freeze.rb +5 -7
  189. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -3
  190. data/lib/rubocop/cop/style/redundant_self.rb +17 -35
  191. data/lib/rubocop/cop/style/rescue_modifier.rb +2 -14
  192. data/lib/rubocop/cop/style/self_assignment.rb +3 -3
  193. data/lib/rubocop/cop/style/send.rb +4 -5
  194. data/lib/rubocop/cop/style/space_after_not.rb +7 -8
  195. data/lib/rubocop/cop/style/space_around_keyword.rb +8 -9
  196. data/lib/rubocop/cop/style/space_around_operators.rb +19 -15
  197. data/lib/rubocop/cop/style/space_before_first_arg.rb +17 -14
  198. data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -1
  199. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +3 -3
  200. data/lib/rubocop/cop/style/space_inside_parens.rb +1 -1
  201. data/lib/rubocop/cop/style/special_global_vars.rb +14 -14
  202. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -1
  203. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  204. data/lib/rubocop/cop/style/string_methods.rb +10 -5
  205. data/lib/rubocop/cop/style/struct_inheritance.rb +4 -15
  206. data/lib/rubocop/cop/style/symbol_array.rb +31 -35
  207. data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
  208. data/lib/rubocop/cop/style/ternary_parentheses.rb +41 -13
  209. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +6 -9
  210. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -1
  211. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  212. data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -2
  213. data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
  214. data/lib/rubocop/cop/style/word_array.rb +12 -34
  215. data/lib/rubocop/cop/style/zero_length_predicate.rb +11 -4
  216. data/lib/rubocop/cop/team.rb +4 -1
  217. data/lib/rubocop/cop/util.rb +33 -26
  218. data/lib/rubocop/cop/variable_force.rb +13 -13
  219. data/lib/rubocop/cop/variable_force/assignment.rb +1 -8
  220. data/lib/rubocop/cop/variable_force/branch.rb +318 -0
  221. data/lib/rubocop/cop/variable_force/branchable.rb +21 -0
  222. data/lib/rubocop/cop/variable_force/reference.rb +1 -3
  223. data/lib/rubocop/cop/variable_force/scope.rb +36 -20
  224. data/lib/rubocop/cop/variable_force/variable.rb +9 -8
  225. data/lib/rubocop/formatter/colorizable.rb +10 -10
  226. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  227. data/lib/rubocop/formatter/html_formatter.rb +2 -1
  228. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -2
  229. data/lib/rubocop/magic_comment.rb +20 -6
  230. data/lib/rubocop/options.rb +1 -1
  231. data/lib/rubocop/platform.rb +11 -0
  232. data/lib/rubocop/processed_source.rb +1 -1
  233. data/lib/rubocop/remote_config.rb +18 -6
  234. data/lib/rubocop/result_cache.rb +8 -8
  235. data/lib/rubocop/rspec/cop_helper.rb +2 -0
  236. data/lib/rubocop/rspec/shared_contexts.rb +20 -0
  237. data/lib/rubocop/rspec/shared_examples.rb +1 -1
  238. data/lib/rubocop/runner.rb +2 -2
  239. data/lib/rubocop/target_finder.rb +64 -6
  240. data/lib/rubocop/version.rb +2 -4
  241. metadata +27 -4
  242. data/lib/rubocop/cop/variable_force/locatable.rb +0 -200
@@ -42,6 +42,8 @@ shared_context 'config', :config do
42
42
  end
43
43
 
44
44
  hash = { 'AllCops' => { 'TargetRubyVersion' => ruby_version } }
45
+ hash['Rails'] = { 'Enabled' => true } if enabled_rails
46
+ hash['AllCops']['TargetRailsVersion'] = rails_version if rails_version
45
47
  if respond_to?(:cop_config)
46
48
  cop_name = described_class.cop_name
47
49
  hash[cop_name] = RuboCop::ConfigLoader
@@ -49,6 +51,8 @@ shared_context 'config', :config do
49
51
  .merge(cop_config)
50
52
  end
51
53
 
54
+ hash = other_cops.merge hash if respond_to?(:other_cops)
55
+
52
56
  RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
53
57
  end
54
58
  end
@@ -76,3 +80,19 @@ end
76
80
  shared_context 'ruby 2.4', :ruby24 do
77
81
  let(:ruby_version) { 2.4 }
78
82
  end
83
+
84
+ shared_context 'with Rails', :enabled_rails do
85
+ let(:enabled_rails) { true }
86
+ end
87
+
88
+ shared_context 'with Rails 3', :rails3 do
89
+ let(:rails_version) { 3.0 }
90
+ end
91
+
92
+ shared_context 'with Rails 4', :rails4 do
93
+ let(:rails_version) { 4.0 }
94
+ end
95
+
96
+ shared_context 'with Rails 5', :rails5 do
97
+ let(:rails_version) { 5.0 }
98
+ end
@@ -22,7 +22,7 @@ shared_examples_for 'mimics MRI 2.1' do |grep_mri_warning|
22
22
  offense_by_mri = offenses_by_mri[index]
23
23
  # Exclude column attribute since MRI does not
24
24
  # output column number.
25
- [:severity, :line, :cop_name].each do |a|
25
+ %i(severity line cop_name).each do |a|
26
26
  expect(offense_by_cop.send(a)).to eq(offense_by_mri.send(a))
27
27
  end
28
28
  end
@@ -118,7 +118,7 @@ module RuboCop
118
118
  def add_unneeded_disables(file, offenses, source)
119
119
  if check_for_unneded_disables?(source)
120
120
  config = @config_store.for(file)
121
- if config.cop_enabled?(Cop::Lint::UnneededDisable)
121
+ if config.for_cop(Cop::Lint::UnneededDisable).fetch('Enabled')
122
122
  cop = Cop::Lint::UnneededDisable.new(config, @options)
123
123
  if cop.relevant_file?(file)
124
124
  cop.check(offenses, source.disabled_line_ranges, source.comments)
@@ -261,7 +261,7 @@ module RuboCop
261
261
  @mobilized_cop_classes[config.object_id] ||= begin
262
262
  cop_classes = Cop::Cop.all
263
263
 
264
- [:only, :except].each do |opt|
264
+ %i(only except).each do |opt|
265
265
  OptionsValidator.validate_cop_list(@options[opt])
266
266
  end
267
267
 
@@ -3,6 +3,53 @@
3
3
  require 'set'
4
4
 
5
5
  module RuboCop
6
+ RUBY_EXTENSIONS = %w(.rb
7
+ .builder
8
+ .fcgi
9
+ .gemspec
10
+ .god
11
+ .jbuilder
12
+ .mspec
13
+ .pluginspec
14
+ .podspec
15
+ .rabl
16
+ .rake
17
+ .rbuild
18
+ .rbw
19
+ .rbx
20
+ .ru
21
+ .ruby
22
+ .spec
23
+ .thor
24
+ .watchr).freeze
25
+
26
+ RUBY_INTERPRETERS = %w(ruby
27
+ macruby
28
+ rake
29
+ jruby
30
+ rbx).freeze
31
+
32
+ RUBY_FILENAMES = %w(.irbrc
33
+ .pryrc
34
+ Appraisals
35
+ Berksfile
36
+ Brewfile
37
+ Buildfile
38
+ Dangerfile
39
+ Deliverfile
40
+ Fastfile
41
+ Gemfile
42
+ Guardfile
43
+ Jarfile
44
+ Mavenfile
45
+ Podfile
46
+ Puppetfile
47
+ Rakefile
48
+ Snapfile
49
+ Thorfile
50
+ Vagrantfile
51
+ buildfile).freeze
52
+
6
53
  # This class finds target files to inspect by scanning the directory tree
7
54
  # and picking ruby files.
8
55
  class TargetFinder
@@ -73,10 +120,7 @@ module RuboCop
73
120
 
74
121
  def to_inspect?(file, hidden_files, base_dir_config)
75
122
  return false if base_dir_config.file_to_exclude?(file)
76
- unless hidden_files.include?(file)
77
- return true if File.extname(file) == '.rb'
78
- return true if ruby_executable?(file)
79
- end
123
+ return true if !hidden_files.include?(file) && ruby_file?(file)
80
124
  base_dir_config.file_to_include?(file)
81
125
  end
82
126
 
@@ -116,18 +160,32 @@ module RuboCop
116
160
  dir_tree_excludes.map { |pattern| pattern.sub(%r{/\*\*/\*$}, '') }
117
161
  end
118
162
 
163
+ def ruby_extension?(file)
164
+ RUBY_EXTENSIONS.include?(File.extname(file))
165
+ end
166
+
167
+ def ruby_filename?(file)
168
+ RUBY_FILENAMES.include?(File.basename(file))
169
+ end
170
+
119
171
  def ruby_executable?(file)
120
- return false unless File.extname(file).empty?
172
+ return false unless File.extname(file).empty? && File.exist?(file)
121
173
  first_line = File.open(file, &:readline)
122
- first_line =~ /#!.*ruby/
174
+ !(first_line =~ /#!.*(#{RUBY_INTERPRETERS.join('|')})/).nil?
123
175
  rescue EOFError, ArgumentError => e
124
176
  warn "Unprocessable file #{file}: #{e.class}, #{e.message}" if debug?
125
177
  false
126
178
  end
127
179
 
180
+ def ruby_file?(file)
181
+ ruby_extension?(file) || ruby_filename?(file) || ruby_executable?(file)
182
+ end
183
+
128
184
  def process_explicit_path(path)
129
185
  files = path.include?('*') ? Dir[path] : [path]
130
186
 
187
+ files.select! { |file| ruby_file?(file) }
188
+
131
189
  return files unless force_exclusion?
132
190
 
133
191
  files.reject do |file|
@@ -3,13 +3,11 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.47.1'.freeze
6
+ STRING = '0.48.0'.freeze
7
7
 
8
8
  MSG = '%s (using Parser %s, running on %s %s %s)'.freeze
9
9
 
10
- module_function
11
-
12
- def version(debug = false)
10
+ def self.version(debug = false)
13
11
  if debug
14
12
  format(MSG, STRING, Parser::VERSION,
15
13
  RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.47.1
4
+ version: 0.48.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-01-18 00:00:00.000000000 Z
13
+ date: 2017-03-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rainbow
@@ -136,16 +136,23 @@ files:
136
136
  - lib/rubocop.rb
137
137
  - lib/rubocop/ast/builder.rb
138
138
  - lib/rubocop/ast/node.rb
139
+ - lib/rubocop/ast/node/and_node.rb
139
140
  - lib/rubocop/ast/node/array_node.rb
140
141
  - lib/rubocop/ast/node/case_node.rb
142
+ - lib/rubocop/ast/node/ensure_node.rb
141
143
  - lib/rubocop/ast/node/for_node.rb
142
144
  - lib/rubocop/ast/node/hash_node.rb
143
145
  - lib/rubocop/ast/node/if_node.rb
144
146
  - lib/rubocop/ast/node/keyword_splat_node.rb
147
+ - lib/rubocop/ast/node/mixin/binary_operator_node.rb
145
148
  - lib/rubocop/ast/node/mixin/conditional_node.rb
146
149
  - lib/rubocop/ast/node/mixin/hash_element_node.rb
147
150
  - lib/rubocop/ast/node/mixin/modifier_node.rb
151
+ - lib/rubocop/ast/node/mixin/predicate_operator_node.rb
152
+ - lib/rubocop/ast/node/or_node.rb
148
153
  - lib/rubocop/ast/node/pair_node.rb
154
+ - lib/rubocop/ast/node/resbody_node.rb
155
+ - lib/rubocop/ast/node/send_node.rb
149
156
  - lib/rubocop/ast/node/until_node.rb
150
157
  - lib/rubocop/ast/node/when_node.rb
151
158
  - lib/rubocop/ast/node/while_node.rb
@@ -167,6 +174,7 @@ files:
167
174
  - lib/rubocop/cop/corrector.rb
168
175
  - lib/rubocop/cop/force.rb
169
176
  - lib/rubocop/cop/ignored_node.rb
177
+ - lib/rubocop/cop/lint/ambiguous_block_association.rb
170
178
  - lib/rubocop/cop/lint/ambiguous_operator.rb
171
179
  - lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
172
180
  - lib/rubocop/cop/lint/assignment_in_condition.rb
@@ -258,6 +266,7 @@ files:
258
266
  - lib/rubocop/cop/mixin/first_element_line_break.rb
259
267
  - lib/rubocop/cop/mixin/frozen_string_literal.rb
260
268
  - lib/rubocop/cop/mixin/hash_alignment.rb
269
+ - lib/rubocop/cop/mixin/ignored_pattern.rb
261
270
  - lib/rubocop/cop/mixin/integer_node.rb
262
271
  - lib/rubocop/cop/mixin/match_range.rb
263
272
  - lib/rubocop/cop/mixin/method_complexity.rb
@@ -272,6 +281,7 @@ files:
272
281
  - lib/rubocop/cop/mixin/parser_diagnostic.rb
273
282
  - lib/rubocop/cop/mixin/percent_literal.rb
274
283
  - lib/rubocop/cop/mixin/preceding_following_alignment.rb
284
+ - lib/rubocop/cop/mixin/rescue_node.rb
275
285
  - lib/rubocop/cop/mixin/safe_assignment.rb
276
286
  - lib/rubocop/cop/mixin/safe_mode.rb
277
287
  - lib/rubocop/cop/mixin/space_after_punctuation.rb
@@ -281,6 +291,7 @@ files:
281
291
  - lib/rubocop/cop/mixin/string_help.rb
282
292
  - lib/rubocop/cop/mixin/string_literals_help.rb
283
293
  - lib/rubocop/cop/mixin/surrounding_space.rb
294
+ - lib/rubocop/cop/mixin/target_rails_version.rb
284
295
  - lib/rubocop/cop/mixin/target_ruby_version.rb
285
296
  - lib/rubocop/cop/mixin/too_many_lines.rb
286
297
  - lib/rubocop/cop/mixin/trailing_comma.rb
@@ -310,6 +321,8 @@ files:
310
321
  - lib/rubocop/cop/performance/string_replacement.rb
311
322
  - lib/rubocop/cop/performance/times_map.rb
312
323
  - lib/rubocop/cop/rails/action_filter.rb
324
+ - lib/rubocop/cop/rails/active_support_aliases.rb
325
+ - lib/rubocop/cop/rails/blank.rb
313
326
  - lib/rubocop/cop/rails/date.rb
314
327
  - lib/rubocop/cop/rails/delegate.rb
315
328
  - lib/rubocop/cop/rails/delegate_allow_blank.rb
@@ -325,7 +338,9 @@ files:
325
338
  - lib/rubocop/cop/rails/output.rb
326
339
  - lib/rubocop/cop/rails/output_safety.rb
327
340
  - lib/rubocop/cop/rails/pluralization_grammar.rb
341
+ - lib/rubocop/cop/rails/present.rb
328
342
  - lib/rubocop/cop/rails/read_write_attribute.rb
343
+ - lib/rubocop/cop/rails/relative_date_constant.rb
329
344
  - lib/rubocop/cop/rails/request_referer.rb
330
345
  - lib/rubocop/cop/rails/reversible_migration.rb
331
346
  - lib/rubocop/cop/rails/safe_navigation.rb
@@ -386,11 +401,14 @@ files:
386
401
  - lib/rubocop/cop/style/else_alignment.rb
387
402
  - lib/rubocop/cop/style/empty_case_condition.rb
388
403
  - lib/rubocop/cop/style/empty_else.rb
404
+ - lib/rubocop/cop/style/empty_line_after_magic_comment.rb
389
405
  - lib/rubocop/cop/style/empty_line_between_defs.rb
390
406
  - lib/rubocop/cop/style/empty_lines.rb
391
407
  - lib/rubocop/cop/style/empty_lines_around_access_modifier.rb
408
+ - lib/rubocop/cop/style/empty_lines_around_begin_body.rb
392
409
  - lib/rubocop/cop/style/empty_lines_around_block_body.rb
393
410
  - lib/rubocop/cop/style/empty_lines_around_class_body.rb
411
+ - lib/rubocop/cop/style/empty_lines_around_exception_handling_keywords.rb
394
412
  - lib/rubocop/cop/style/empty_lines_around_method_body.rb
395
413
  - lib/rubocop/cop/style/empty_lines_around_module_body.rb
396
414
  - lib/rubocop/cop/style/empty_literal.rb
@@ -422,11 +440,13 @@ files:
422
440
  - lib/rubocop/cop/style/indent_array.rb
423
441
  - lib/rubocop/cop/style/indent_assignment.rb
424
442
  - lib/rubocop/cop/style/indent_hash.rb
443
+ - lib/rubocop/cop/style/indent_heredoc.rb
425
444
  - lib/rubocop/cop/style/indentation_consistency.rb
426
445
  - lib/rubocop/cop/style/indentation_width.rb
427
446
  - lib/rubocop/cop/style/infinite_loop.rb
428
447
  - lib/rubocop/cop/style/initial_indentation.rb
429
448
  - lib/rubocop/cop/style/inline_comment.rb
449
+ - lib/rubocop/cop/style/inverse_methods.rb
430
450
  - lib/rubocop/cop/style/lambda.rb
431
451
  - lib/rubocop/cop/style/lambda_call.rb
432
452
  - lib/rubocop/cop/style/leading_comment_space.rb
@@ -438,6 +458,7 @@ files:
438
458
  - lib/rubocop/cop/style/method_missing.rb
439
459
  - lib/rubocop/cop/style/method_name.rb
440
460
  - lib/rubocop/cop/style/missing_else.rb
461
+ - lib/rubocop/cop/style/mixin_grouping.rb
441
462
  - lib/rubocop/cop/style/module_function.rb
442
463
  - lib/rubocop/cop/style/multiline_array_brace_layout.rb
443
464
  - lib/rubocop/cop/style/multiline_assignment_layout.rb
@@ -550,7 +571,8 @@ files:
550
571
  - lib/rubocop/cop/util.rb
551
572
  - lib/rubocop/cop/variable_force.rb
552
573
  - lib/rubocop/cop/variable_force/assignment.rb
553
- - lib/rubocop/cop/variable_force/locatable.rb
574
+ - lib/rubocop/cop/variable_force/branch.rb
575
+ - lib/rubocop/cop/variable_force/branchable.rb
554
576
  - lib/rubocop/cop/variable_force/reference.rb
555
577
  - lib/rubocop/cop/variable_force/scope.rb
556
578
  - lib/rubocop/cop/variable_force/variable.rb
@@ -577,6 +599,7 @@ files:
577
599
  - lib/rubocop/node_pattern.rb
578
600
  - lib/rubocop/options.rb
579
601
  - lib/rubocop/path_util.rb
602
+ - lib/rubocop/platform.rb
580
603
  - lib/rubocop/processed_source.rb
581
604
  - lib/rubocop/rake_task.rb
582
605
  - lib/rubocop/remote_config.rb
@@ -613,7 +636,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
613
636
  version: '0'
614
637
  requirements: []
615
638
  rubyforge_project:
616
- rubygems_version: 2.5.2
639
+ rubygems_version: 2.6.11
617
640
  signing_key:
618
641
  specification_version: 4
619
642
  summary: Automatic Ruby code style checking tool.
@@ -1,200 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- class VariableForce
6
- # This module provides a way to locate the conditional branch the node is
7
- # in. This is intended to be used as mix-in.
8
- module Locatable
9
- BRANCH_TYPES = [:if, :case].freeze
10
- CONDITION_INDEX_OF_BRANCH_NODE = 0
11
-
12
- LOGICAL_OPERATOR_TYPES = [:and, :or].freeze
13
- LEFT_SIDE_INDEX_OF_LOGICAL_OPERATOR_NODE = 0
14
-
15
- ENSURE_TYPE = :ensure
16
- ENSURE_INDEX_OF_ENSURE_NODE = 1
17
-
18
- FOR_LOOP_TYPE = :for
19
- FOR_LOOP_CHILD_INDEX = 2
20
-
21
- NON_FOR_LOOP_TYPES = LOOP_TYPES - [FOR_LOOP_TYPE]
22
- NON_FOR_LOOP_TYPES_CHILD_INDEX = 1
23
-
24
- def initialize(*)
25
- @branch_point_node = @branch_body_node = nil
26
-
27
- super()
28
- end
29
-
30
- def node
31
- raise '#node must be declared!'
32
- end
33
-
34
- def scope
35
- raise '#scope must be declared!'
36
- end
37
-
38
- def inside_of_branch?
39
- branch_point_node
40
- end
41
-
42
- def run_exclusively_with?(other)
43
- return false unless branch_point_node.equal?(other.branch_point_node)
44
- return false if branch_body_node.equal?(other.branch_body_node)
45
-
46
- # Main body of rescue is always run:
47
- #
48
- # begin
49
- # # main
50
- # rescue
51
- # # resbody
52
- # end
53
- if branch_point_node.rescue_type? &&
54
- (branch_body_name == 'main' || other.branch_body_name == 'main')
55
- return false
56
- end
57
-
58
- true
59
- end
60
-
61
- def branch_id
62
- return nil unless inside_of_branch?
63
- @branch_id ||= [branch_point_node.object_id, branch_type].join('_')
64
- end
65
-
66
- def branch_type
67
- return nil unless inside_of_branch?
68
- @branch_type ||= [branch_point_node.type, branch_body_name].join('_')
69
- end
70
-
71
- # Inner if, case, rescue, or ensure node.
72
- def branch_point_node
73
- return @branch_point_node if @branch_point_node
74
-
75
- set_branch_point_and_body_nodes!
76
- @branch_point_node
77
- end
78
-
79
- # A child node of #branch_point_node this assignment belongs.
80
- def branch_body_node
81
- return @branch_body_node if @branch_body_node
82
-
83
- set_branch_point_and_body_nodes!
84
- @branch_body_node
85
- end
86
-
87
- # TODO: Replace case statement with function mapping
88
- def branch_body_name
89
- case branch_point_node.type
90
- when :if then if_body_name
91
- when :case then case_body_name
92
- when RESCUE_TYPE then rescue_body_name
93
- when ENSURE_TYPE then ensure_body_name
94
- when *LOGICAL_OPERATOR_TYPES then logical_operator_body_name
95
- when *LOOP_TYPES then loop_body_name
96
- else
97
- raise InvalidBranchBodyError, "Invalid body index #{body_index} " \
98
- "of #{branch_point_node.type}"
99
- end
100
- end
101
-
102
- private
103
-
104
- def if_body_name
105
- case body_index
106
- when 1 then 'true'
107
- when 2 then 'false'
108
- else raise InvalidBranchBodyError
109
- end
110
- end
111
-
112
- def case_body_name
113
- if branch_body_node.when_type?
114
- "when#{body_index - 1}"
115
- else
116
- 'else'
117
- end
118
- end
119
-
120
- def logical_operator_body_name
121
- case body_index
122
- when 1 then 'right'
123
- else raise InvalidBranchBodyError
124
- end
125
- end
126
-
127
- def rescue_body_name
128
- if body_index.zero?
129
- 'main'
130
- elsif branch_body_node.type == :resbody
131
- "rescue#{body_index - 1}"
132
- else
133
- 'else'
134
- end
135
- end
136
-
137
- def ensure_body_name
138
- case body_index
139
- when 0 then 'main'
140
- else raise InvalidBranchBodyError
141
- end
142
- end
143
-
144
- def loop_body_name
145
- loop_indices = [FOR_LOOP_CHILD_INDEX, NON_FOR_LOOP_TYPES_CHILD_INDEX]
146
-
147
- raise InvalidBranchBodyError unless loop_indices.include?(body_index)
148
-
149
- 'main'
150
- end
151
-
152
- def body_index
153
- branch_point_node.children.index { |n| n.equal?(branch_body_node) }
154
- end
155
-
156
- def set_branch_point_and_body_nodes!
157
- self_and_ancestor_nodes = [node] + ancestor_nodes_in_scope
158
-
159
- self_and_ancestor_nodes.each_cons(2) do |child, parent|
160
- next unless branch?(parent, child)
161
- @branch_point_node = parent
162
- @branch_body_node = child
163
- break
164
- end
165
- end
166
-
167
- def ancestor_nodes_in_scope
168
- node.each_ancestor.take_while do |ancestor_node|
169
- !ancestor_node.equal?(scope.node)
170
- end
171
- end
172
-
173
- # rubocop:disable Metrics/MethodLength
174
- def branch?(parent_node, child_node)
175
- child_index = parent_node.children.index(child_node)
176
-
177
- case parent_node.type
178
- when RESCUE_TYPE
179
- true
180
- when ENSURE_TYPE
181
- child_index != ENSURE_INDEX_OF_ENSURE_NODE
182
- when FOR_LOOP_TYPE
183
- child_index == FOR_LOOP_CHILD_INDEX
184
- when *BRANCH_TYPES
185
- child_index != CONDITION_INDEX_OF_BRANCH_NODE
186
- when *LOGICAL_OPERATOR_TYPES
187
- child_index != LEFT_SIDE_INDEX_OF_LOGICAL_OPERATOR_NODE
188
- when *NON_FOR_LOOP_TYPES
189
- child_index == NON_FOR_LOOP_TYPES_CHILD_INDEX
190
- else
191
- false
192
- end
193
- end
194
- # rubocop:enable Metrics/MethodLength
195
-
196
- class InvalidBranchBodyError < StandardError; end
197
- end
198
- end
199
- end
200
- end