rubocop 0.29.1 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (341) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -1
  3. data/README.md +11 -2
  4. data/config/default.yml +194 -6
  5. data/config/disabled.yml +25 -1
  6. data/config/enabled.yml +74 -12
  7. data/lib/rubocop.rb +19 -2
  8. data/lib/rubocop/config.rb +23 -3
  9. data/lib/rubocop/config_loader.rb +9 -1
  10. data/lib/rubocop/cop/autocorrect_logic.rb +26 -0
  11. data/lib/rubocop/cop/cop.rb +33 -17
  12. data/lib/rubocop/cop/lint/assignment_in_condition.rb +16 -4
  13. data/lib/rubocop/cop/lint/block_alignment.rb +5 -14
  14. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  15. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +61 -0
  16. data/lib/rubocop/cop/lint/void.rb +11 -3
  17. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +17 -0
  18. data/lib/rubocop/cop/performance/detect.rb +72 -0
  19. data/lib/rubocop/cop/performance/flat_map.rb +64 -0
  20. data/lib/rubocop/cop/performance/reverse_each.rb +43 -0
  21. data/lib/rubocop/cop/performance/sample.rb +58 -0
  22. data/lib/rubocop/cop/performance/size.rb +64 -0
  23. data/lib/rubocop/cop/rails/date.rb +121 -0
  24. data/lib/rubocop/cop/rails/find_by.rb +52 -0
  25. data/lib/rubocop/cop/rails/find_each.rb +41 -0
  26. data/lib/rubocop/cop/rails/time_zone.rb +93 -0
  27. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +45 -0
  28. data/lib/rubocop/cop/style/block_delimiters.rb +186 -0
  29. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +76 -0
  30. data/lib/rubocop/cop/style/command_literal.rb +120 -0
  31. data/lib/rubocop/cop/style/copyright.rb +87 -0
  32. data/lib/rubocop/cop/style/documentation.rb +32 -0
  33. data/lib/rubocop/cop/style/empty_else.rb +85 -16
  34. data/lib/rubocop/cop/style/encoding.rb +14 -2
  35. data/lib/rubocop/cop/style/end_of_line.rb +5 -0
  36. data/lib/rubocop/cop/style/hash_syntax.rb +86 -23
  37. data/lib/rubocop/cop/style/if_unless_modifier.rb +15 -0
  38. data/lib/rubocop/cop/style/indentation_consistency.rb +13 -6
  39. data/lib/rubocop/cop/style/indentation_width.rb +34 -10
  40. data/lib/rubocop/cop/style/lambda.rb +32 -17
  41. data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -0
  42. data/lib/rubocop/cop/style/missing_else.rb +72 -0
  43. data/lib/rubocop/cop/style/regexp_literal.rb +89 -58
  44. data/lib/rubocop/cop/style/space_around_operators.rb +13 -2
  45. data/lib/rubocop/cop/style/space_before_block_braces.rb +3 -3
  46. data/lib/rubocop/cop/style/space_inside_block_braces.rb +9 -5
  47. data/lib/rubocop/cop/style/symbol_literal.rb +36 -0
  48. data/lib/rubocop/cop/style/trailing_blank_lines.rb +7 -0
  49. data/lib/rubocop/cop/style/trailing_comma.rb +21 -7
  50. data/lib/rubocop/cop/style/trivial_accessors.rb +17 -3
  51. data/lib/rubocop/cop/style/unneeded_capital_w.rb +4 -6
  52. data/lib/rubocop/cop/style/while_until_modifier.rb +10 -0
  53. data/lib/rubocop/cop/util.rb +24 -19
  54. data/lib/rubocop/cop/variable_force.rb +14 -0
  55. data/lib/rubocop/cop/variable_force/reference.rb +10 -4
  56. data/lib/rubocop/formatter/html_formatter.rb +10 -4
  57. data/lib/rubocop/formatter/text_util.rb +5 -7
  58. data/lib/rubocop/options.rb +47 -45
  59. data/lib/rubocop/path_util.rb +12 -8
  60. data/lib/rubocop/processed_source.rb +12 -1
  61. data/lib/rubocop/rake_task.rb +2 -2
  62. data/lib/rubocop/version.rb +1 -1
  63. data/relnotes/v0.30.0.md +145 -0
  64. data/rubocop.gemspec +15 -3
  65. metadata +22 -545
  66. data/.gitignore +0 -54
  67. data/.rspec +0 -1
  68. data/.rubocop.yml +0 -11
  69. data/.rubocop_todo.yml +0 -28
  70. data/.travis.yml +0 -22
  71. data/Gemfile +0 -15
  72. data/Rakefile +0 -41
  73. data/lib/rubocop/cop/style/blocks.rb +0 -80
  74. data/lib/rubocop/cop/style/unneeded_percent_x.rb +0 -25
  75. data/logo/rubocop-final-logo.eps +0 -0
  76. data/spec/.rubocop.yml +0 -5
  77. data/spec/fixtures/html_formatter/expected.html +0 -495
  78. data/spec/fixtures/html_formatter/project/app/controllers/application_controller.rb +0 -5
  79. data/spec/fixtures/html_formatter/project/app/controllers/books_controller.rb +0 -74
  80. data/spec/fixtures/html_formatter/project/app/models/book.rb +0 -5
  81. data/spec/isolated_environment_spec.rb +0 -24
  82. data/spec/project_spec.rb +0 -119
  83. data/spec/rubocop/cli_spec.rb +0 -2740
  84. data/spec/rubocop/comment_config_spec.rb +0 -105
  85. data/spec/rubocop/config_loader_spec.rb +0 -377
  86. data/spec/rubocop/config_spec.rb +0 -235
  87. data/spec/rubocop/config_store_spec.rb +0 -53
  88. data/spec/rubocop/cop/commissioner_spec.rb +0 -85
  89. data/spec/rubocop/cop/cop_spec.rb +0 -135
  90. data/spec/rubocop/cop/corrector_spec.rb +0 -59
  91. data/spec/rubocop/cop/force_spec.rb +0 -29
  92. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +0 -113
  93. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +0 -35
  94. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +0 -130
  95. data/spec/rubocop/cop/lint/block_alignment_spec.rb +0 -533
  96. data/spec/rubocop/cop/lint/condition_position_spec.rb +0 -51
  97. data/spec/rubocop/cop/lint/debugger_spec.rb +0 -73
  98. data/spec/rubocop/cop/lint/def_end_alignment_spec.rb +0 -108
  99. data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +0 -38
  100. data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +0 -189
  101. data/spec/rubocop/cop/lint/else_layout_spec.rb +0 -65
  102. data/spec/rubocop/cop/lint/empty_ensure_spec.rb +0 -27
  103. data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +0 -18
  104. data/spec/rubocop/cop/lint/end_alignment_spec.rb +0 -91
  105. data/spec/rubocop/cop/lint/end_in_method_spec.rb +0 -29
  106. data/spec/rubocop/cop/lint/ensure_return_spec.rb +0 -39
  107. data/spec/rubocop/cop/lint/eval_spec.rb +0 -33
  108. data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +0 -30
  109. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +0 -33
  110. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +0 -172
  111. data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +0 -31
  112. data/spec/rubocop/cop/lint/loop_spec.rb +0 -27
  113. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +0 -57
  114. data/spec/rubocop/cop/lint/require_parentheses_spec.rb +0 -82
  115. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +0 -123
  116. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +0 -237
  117. data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +0 -66
  118. data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +0 -51
  119. data/spec/rubocop/cop/lint/syntax_spec.rb +0 -34
  120. data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +0 -179
  121. data/spec/rubocop/cop/lint/unreachable_code_spec.rb +0 -63
  122. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +0 -231
  123. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +0 -278
  124. data/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +0 -192
  125. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +0 -1778
  126. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +0 -30
  127. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +0 -48
  128. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +0 -211
  129. data/spec/rubocop/cop/lint/void_spec.rb +0 -64
  130. data/spec/rubocop/cop/metrics/abc_size_spec.rb +0 -109
  131. data/spec/rubocop/cop/metrics/block_nesting_spec.rb +0 -156
  132. data/spec/rubocop/cop/metrics/class_length_spec.rb +0 -131
  133. data/spec/rubocop/cop/metrics/cyclomatic_complexity_spec.rb +0 -204
  134. data/spec/rubocop/cop/metrics/line_length_spec.rb +0 -136
  135. data/spec/rubocop/cop/metrics/method_length_spec.rb +0 -147
  136. data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +0 -44
  137. data/spec/rubocop/cop/metrics/perceived_complexity_spec.rb +0 -222
  138. data/spec/rubocop/cop/offense_spec.rb +0 -133
  139. data/spec/rubocop/cop/rails/action_filter_spec.rb +0 -64
  140. data/spec/rubocop/cop/rails/default_scope_spec.rb +0 -37
  141. data/spec/rubocop/cop/rails/delegate_spec.rb +0 -177
  142. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +0 -13
  143. data/spec/rubocop/cop/rails/output_spec.rb +0 -37
  144. data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +0 -130
  145. data/spec/rubocop/cop/rails/scope_args_spec.rb +0 -25
  146. data/spec/rubocop/cop/rails/validation_spec.rb +0 -28
  147. data/spec/rubocop/cop/severity_spec.rb +0 -113
  148. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +0 -421
  149. data/spec/rubocop/cop/style/accessor_method_name_spec.rb +0 -81
  150. data/spec/rubocop/cop/style/alias_spec.rb +0 -59
  151. data/spec/rubocop/cop/style/align_array_spec.rb +0 -123
  152. data/spec/rubocop/cop/style/align_hash_spec.rb +0 -411
  153. data/spec/rubocop/cop/style/align_parameters_spec.rb +0 -431
  154. data/spec/rubocop/cop/style/and_or_spec.rb +0 -235
  155. data/spec/rubocop/cop/style/array_join_spec.rb +0 -29
  156. data/spec/rubocop/cop/style/ascii_comments_spec.rb +0 -21
  157. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +0 -36
  158. data/spec/rubocop/cop/style/attr_spec.rb +0 -29
  159. data/spec/rubocop/cop/style/bare_percent_literals_spec.rb +0 -132
  160. data/spec/rubocop/cop/style/begin_block_spec.rb +0 -13
  161. data/spec/rubocop/cop/style/block_comments_spec.rb +0 -45
  162. data/spec/rubocop/cop/style/block_end_newline_spec.rb +0 -61
  163. data/spec/rubocop/cop/style/blocks_spec.rb +0 -121
  164. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +0 -288
  165. data/spec/rubocop/cop/style/case_equality_spec.rb +0 -13
  166. data/spec/rubocop/cop/style/case_indentation_spec.rb +0 -293
  167. data/spec/rubocop/cop/style/character_literal_spec.rb +0 -37
  168. data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +0 -40
  169. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +0 -133
  170. data/spec/rubocop/cop/style/class_check_spec.rb +0 -41
  171. data/spec/rubocop/cop/style/class_methods_spec.rb +0 -80
  172. data/spec/rubocop/cop/style/class_vars_spec.rb +0 -19
  173. data/spec/rubocop/cop/style/collection_methods_spec.rb +0 -48
  174. data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -65
  175. data/spec/rubocop/cop/style/comment_annotation_spec.rb +0 -86
  176. data/spec/rubocop/cop/style/comment_indentation_spec.rb +0 -179
  177. data/spec/rubocop/cop/style/constant_name_spec.rb +0 -65
  178. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +0 -43
  179. data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +0 -45
  180. data/spec/rubocop/cop/style/documentation_spec.rb +0 -146
  181. data/spec/rubocop/cop/style/dot_position_spec.rb +0 -132
  182. data/spec/rubocop/cop/style/double_negation_spec.rb +0 -22
  183. data/spec/rubocop/cop/style/each_with_object_spec.rb +0 -73
  184. data/spec/rubocop/cop/style/else_alignment_spec.rb +0 -506
  185. data/spec/rubocop/cop/style/empty_else_spec.rb +0 -100
  186. data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +0 -135
  187. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +0 -178
  188. data/spec/rubocop/cop/style/empty_lines_around_block_body_spec.rb +0 -103
  189. data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +0 -135
  190. data/spec/rubocop/cop/style/empty_lines_around_method_body_spec.rb +0 -90
  191. data/spec/rubocop/cop/style/empty_lines_around_module_body_spec.rb +0 -79
  192. data/spec/rubocop/cop/style/empty_lines_spec.rb +0 -51
  193. data/spec/rubocop/cop/style/empty_literal_spec.rb +0 -117
  194. data/spec/rubocop/cop/style/encoding_spec.rb +0 -139
  195. data/spec/rubocop/cop/style/end_block_spec.rb +0 -13
  196. data/spec/rubocop/cop/style/end_of_line_spec.rb +0 -65
  197. data/spec/rubocop/cop/style/even_odd_spec.rb +0 -164
  198. data/spec/rubocop/cop/style/extra_spacing_spec.rb +0 -68
  199. data/spec/rubocop/cop/style/file_name_spec.rb +0 -84
  200. data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +0 -304
  201. data/spec/rubocop/cop/style/flip_flop_spec.rb +0 -23
  202. data/spec/rubocop/cop/style/for_spec.rb +0 -105
  203. data/spec/rubocop/cop/style/format_string_spec.rb +0 -184
  204. data/spec/rubocop/cop/style/global_vars_spec.rb +0 -34
  205. data/spec/rubocop/cop/style/guard_clause_spec.rb +0 -172
  206. data/spec/rubocop/cop/style/hash_syntax_spec.rb +0 -137
  207. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +0 -146
  208. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +0 -24
  209. data/spec/rubocop/cop/style/indent_array_spec.rb +0 -173
  210. data/spec/rubocop/cop/style/indent_hash_spec.rb +0 -367
  211. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +0 -509
  212. data/spec/rubocop/cop/style/indentation_width_spec.rb +0 -885
  213. data/spec/rubocop/cop/style/infinite_loop_spec.rb +0 -48
  214. data/spec/rubocop/cop/style/inline_comment_spec.rb +0 -13
  215. data/spec/rubocop/cop/style/lambda_call_spec.rb +0 -65
  216. data/spec/rubocop/cop/style/lambda_spec.rb +0 -76
  217. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +0 -64
  218. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +0 -184
  219. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +0 -59
  220. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +0 -60
  221. data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +0 -108
  222. data/spec/rubocop/cop/style/method_name_spec.rb +0 -125
  223. data/spec/rubocop/cop/style/module_function_spec.rb +0 -24
  224. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +0 -78
  225. data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +0 -199
  226. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +0 -134
  227. data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +0 -464
  228. data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +0 -18
  229. data/spec/rubocop/cop/style/negated_if_spec.rb +0 -102
  230. data/spec/rubocop/cop/style/negated_while_spec.rb +0 -64
  231. data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +0 -21
  232. data/spec/rubocop/cop/style/next_spec.rb +0 -301
  233. data/spec/rubocop/cop/style/nil_comparison_spec.rb +0 -29
  234. data/spec/rubocop/cop/style/non_nil_check_spec.rb +0 -132
  235. data/spec/rubocop/cop/style/not_spec.rb +0 -28
  236. data/spec/rubocop/cop/style/numeric_literals_spec.rb +0 -80
  237. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +0 -13
  238. data/spec/rubocop/cop/style/op_method_spec.rb +0 -85
  239. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +0 -161
  240. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +0 -316
  241. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +0 -122
  242. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +0 -22
  243. data/spec/rubocop/cop/style/predicate_name_spec.rb +0 -57
  244. data/spec/rubocop/cop/style/proc_spec.rb +0 -27
  245. data/spec/rubocop/cop/style/raise_args_spec.rb +0 -87
  246. data/spec/rubocop/cop/style/redundant_begin_spec.rb +0 -121
  247. data/spec/rubocop/cop/style/redundant_exception_spec.rb +0 -59
  248. data/spec/rubocop/cop/style/redundant_return_spec.rb +0 -171
  249. data/spec/rubocop/cop/style/redundant_self_spec.rb +0 -186
  250. data/spec/rubocop/cop/style/regexp_literal_spec.rb +0 -188
  251. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +0 -116
  252. data/spec/rubocop/cop/style/self_assignment_spec.rb +0 -49
  253. data/spec/rubocop/cop/style/semicolon_spec.rb +0 -114
  254. data/spec/rubocop/cop/style/signal_exception_spec.rb +0 -289
  255. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +0 -82
  256. data/spec/rubocop/cop/style/single_line_methods_spec.rb +0 -94
  257. data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +0 -63
  258. data/spec/rubocop/cop/style/space_after_colon_spec.rb +0 -55
  259. data/spec/rubocop/cop/style/space_after_comma_spec.rb +0 -30
  260. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +0 -84
  261. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +0 -70
  262. data/spec/rubocop/cop/style/space_after_not_spec.rb +0 -22
  263. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +0 -23
  264. data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +0 -155
  265. data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +0 -95
  266. data/spec/rubocop/cop/style/space_around_operators_spec.rb +0 -330
  267. data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +0 -73
  268. data/spec/rubocop/cop/style/space_before_comma_spec.rb +0 -42
  269. data/spec/rubocop/cop/style/space_before_comment_spec.rb +0 -34
  270. data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +0 -70
  271. data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +0 -28
  272. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +0 -317
  273. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +0 -83
  274. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +0 -147
  275. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +0 -44
  276. data/spec/rubocop/cop/style/space_inside_range_literal_spec.rb +0 -64
  277. data/spec/rubocop/cop/style/special_global_vars_spec.rb +0 -62
  278. data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +0 -99
  279. data/spec/rubocop/cop/style/string_literals_spec.rb +0 -228
  280. data/spec/rubocop/cop/style/struct_inheritance_spec.rb +0 -44
  281. data/spec/rubocop/cop/style/symbol_array_spec.rb +0 -37
  282. data/spec/rubocop/cop/style/symbol_proc_spec.rb +0 -100
  283. data/spec/rubocop/cop/style/tab_spec.rb +0 -47
  284. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +0 -83
  285. data/spec/rubocop/cop/style/trailing_comma_spec.rb +0 -390
  286. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +0 -31
  287. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +0 -558
  288. data/spec/rubocop/cop/style/unless_else_spec.rb +0 -23
  289. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +0 -90
  290. data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +0 -127
  291. data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +0 -34
  292. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +0 -76
  293. data/spec/rubocop/cop/style/variable_name_spec.rb +0 -107
  294. data/spec/rubocop/cop/style/when_then_spec.rb +0 -42
  295. data/spec/rubocop/cop/style/while_until_do_spec.rb +0 -55
  296. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +0 -93
  297. data/spec/rubocop/cop/style/word_array_spec.rb +0 -117
  298. data/spec/rubocop/cop/team_spec.rb +0 -190
  299. data/spec/rubocop/cop/util_spec.rb +0 -102
  300. data/spec/rubocop/cop/variable_force/assignment_spec.rb +0 -200
  301. data/spec/rubocop/cop/variable_force/locatable_spec.rb +0 -699
  302. data/spec/rubocop/cop/variable_force/reference_spec.rb +0 -19
  303. data/spec/rubocop/cop/variable_force/scope_spec.rb +0 -319
  304. data/spec/rubocop/cop/variable_force/variable_spec.rb +0 -59
  305. data/spec/rubocop/cop/variable_force/variable_table_spec.rb +0 -276
  306. data/spec/rubocop/cop/variable_force_spec.rb +0 -26
  307. data/spec/rubocop/formatter/base_formatter_spec.rb +0 -191
  308. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +0 -114
  309. data/spec/rubocop/formatter/colorizable_spec.rb +0 -107
  310. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +0 -50
  311. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +0 -67
  312. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +0 -63
  313. data/spec/rubocop/formatter/file_list_formatter_spec.rb +0 -33
  314. data/spec/rubocop/formatter/formatter_set_spec.rb +0 -141
  315. data/spec/rubocop/formatter/fuubar_style_formatter_spec.rb +0 -129
  316. data/spec/rubocop/formatter/html_formatter_spec.rb +0 -48
  317. data/spec/rubocop/formatter/json_formatter_spec.rb +0 -152
  318. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +0 -75
  319. data/spec/rubocop/formatter/progress_formatter_spec.rb +0 -182
  320. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +0 -135
  321. data/spec/rubocop/formatter/text_util_spec.rb +0 -55
  322. data/spec/rubocop/options_spec.rb +0 -181
  323. data/spec/rubocop/path_util_spec.rb +0 -77
  324. data/spec/rubocop/processed_source_spec.rb +0 -184
  325. data/spec/rubocop/rake_task_spec.rb +0 -122
  326. data/spec/rubocop/runner_spec.rb +0 -99
  327. data/spec/rubocop/string_util_spec.rb +0 -46
  328. data/spec/rubocop/target_finder_spec.rb +0 -245
  329. data/spec/rubocop/token_spec.rb +0 -29
  330. data/spec/spec_helper.rb +0 -39
  331. data/spec/support/cop_helper.rb +0 -75
  332. data/spec/support/cops/class_must_be_a_module_cop.rb +0 -19
  333. data/spec/support/cops/module_must_be_a_class_cop.rb +0 -19
  334. data/spec/support/coverage.rb +0 -15
  335. data/spec/support/custom_matchers.rb +0 -58
  336. data/spec/support/file_helper.rb +0 -23
  337. data/spec/support/jruby_workaround.rb +0 -15
  338. data/spec/support/mri_syntax_checker.rb +0 -73
  339. data/spec/support/shared_contexts.rb +0 -53
  340. data/spec/support/shared_examples.rb +0 -55
  341. data/spec/support/statement_modifier_helper.rb +0 -41
@@ -78,7 +78,7 @@ Style/BlockEndNewline:
78
78
  Description: 'Put end statement of multiline block on its own line.'
79
79
  Enabled: true
80
80
 
81
- Style/Blocks:
81
+ Style/BlockDelimiters:
82
82
  Description: >-
83
83
  Avoid using {...} for multi-line blocks (multiline chaining is
84
84
  always ugly).
@@ -128,11 +128,20 @@ Style/ClassVars:
128
128
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars'
129
129
  Enabled: true
130
130
 
131
+ Style/ClosingParenthesisIndentation:
132
+ Description: 'Checks the indentation of hanging closing parentheses.'
133
+ Enabled: true
134
+
131
135
  Style/ColonMethodCall:
132
136
  Description: 'Do not use :: for method call.'
133
137
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons'
134
138
  Enabled: true
135
139
 
140
+ Style/CommandLiteral:
141
+ Description: 'Use `` or %x around command literals.'
142
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x'
143
+ Enabled: true
144
+
136
145
  Style/CommentAnnotation:
137
146
  Description: >-
138
147
  Checks formatting of special comments
@@ -494,11 +503,7 @@ Style/RedundantSelf:
494
503
  Enabled: true
495
504
 
496
505
  Style/RegexpLiteral:
497
- Description: >-
498
- Use %r for regular expressions matching more than
499
- `MaxSlashes` '/' characters.
500
- Use %r only for regular expressions matching more than
501
- `MaxSlashes` '/' character.
506
+ Description: 'Use / or %r around regular expressions.'
502
507
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r'
503
508
  Enabled: true
504
509
 
@@ -611,7 +616,7 @@ Style/SpaceAroundEqualsInParameterDefault:
611
616
  Enabled: true
612
617
 
613
618
  Style/SpaceAroundOperators:
614
- Description: 'Use spaces around operators.'
619
+ Description: 'Use a single space around operators.'
615
620
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators'
616
621
  Enabled: true
617
622
 
@@ -660,6 +665,10 @@ Style/StructInheritance:
660
665
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new'
661
666
  Enabled: true
662
667
 
668
+ Style/SymbolLiteral:
669
+ Description: 'Use plain symbols instead of string symbols when possible.'
670
+ Enabled: true
671
+
663
672
  Style/SymbolProc:
664
673
  Description: 'Use symbols as procs instead of blocks when possible.'
665
674
  Enabled: true
@@ -705,11 +714,6 @@ Style/UnneededPercentQ:
705
714
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-q'
706
715
  Enabled: true
707
716
 
708
- Style/UnneededPercentX:
709
- Description: 'Checks for %x when `` would do.'
710
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-x'
711
- Enabled: true
712
-
713
717
  Style/VariableInterpolation:
714
718
  Description: >-
715
719
  Don't interpolate global, instance and class variables
@@ -891,6 +895,10 @@ Lint/Loop:
891
895
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#loop-with-break'
892
896
  Enabled: true
893
897
 
898
+ Lint/NonLocalExitFromIterator:
899
+ Description: 'Do not use return in iterator to cause non-local exit.'
900
+ Enabled: true
901
+
894
902
  Lint/ParenthesesAsGroupedExpression:
895
903
  Description: >-
896
904
  Checks for method calls with a space before the opening
@@ -969,12 +977,54 @@ Lint/Void:
969
977
  Description: 'Possible use of operator/literal/variable in void context.'
970
978
  Enabled: true
971
979
 
980
+ ##################### Performance #############################
981
+
982
+ Performance/Detect:
983
+ Description: >-
984
+ Use `detect` instead of `select.first`, `find_all.first`,
985
+ `select.last`, and `find_all.last`.
986
+ Enabled: true
987
+
988
+ Performance/FlatMap:
989
+ Description: >-
990
+ Use `Enumerable#flat_map`
991
+ instead of `Enumerable#map...Array#flatten(1)`
992
+ or `Enumberable#collect..Array#flatten(1)`
993
+ Enabled: true
994
+ EnabledForFlattenWithoutParams: false
995
+ # If enabled, this cop will warn about usages of
996
+ # `flatten` being called without any parameters.
997
+ # This can be dangerous since `flat_map` will only flatten 1 level, and
998
+ # `flatten` without any parameters can flatten multiple levels.
999
+
1000
+ Performance/ReverseEach:
1001
+ Description: 'Use `reverse_each` instead of `reverse.each`.'
1002
+ Enabled: true
1003
+
1004
+ Performance/Sample:
1005
+ Description: >-
1006
+ Use `sample` instead of `shuffle.first`,
1007
+ `shuffle.last`, and `shuffle[Fixnum]`.
1008
+ Enabled: true
1009
+
1010
+ Performance/Size:
1011
+ Description: >-
1012
+ Use `size` instead of `count` for counting
1013
+ the number of elements in `Array` and `Hash`.
1014
+ Enabled: true
1015
+
972
1016
  ##################### Rails ##################################
973
1017
 
974
1018
  Rails/ActionFilter:
975
1019
  Description: 'Enforces consistent use of action filter methods.'
976
1020
  Enabled: true
977
1021
 
1022
+ Rails/Date:
1023
+ Description: >-
1024
+ Checks the correct usage of date aware methods,
1025
+ such as Date.today, Date.current etc.
1026
+ Enabled: true
1027
+
978
1028
  Rails/DefaultScope:
979
1029
  Description: 'Checks if the argument passed to default_scope is a block.'
980
1030
  Enabled: true
@@ -983,6 +1033,14 @@ Rails/Delegate:
983
1033
  Description: 'Prefer delegate method for delegations.'
984
1034
  Enabled: true
985
1035
 
1036
+ Rails/FindBy:
1037
+ Description: 'Prefer find_by over where.first.'
1038
+ Enabled: true
1039
+
1040
+ Rails/FindEach:
1041
+ Description: 'Prefer all.find_each over all.find.'
1042
+ Enabled: true
1043
+
986
1044
  Rails/HasAndBelongsToMany:
987
1045
  Description: 'Prefer has_many :through to has_and_belongs_to_many.'
988
1046
  Enabled: true
@@ -1001,6 +1059,10 @@ Rails/ScopeArgs:
1001
1059
  Description: 'Checks the arguments of ActiveRecord scopes.'
1002
1060
  Enabled: true
1003
1061
 
1062
+ Rails/TimeZone:
1063
+ Description: 'Checks the correct usage of time zone aware methods.'
1064
+ Enabled: true
1065
+
1004
1066
  Rails/Validation:
1005
1067
  Description: 'Use validates :attribute, hash of validations.'
1006
1068
  Enabled: true
@@ -21,6 +21,7 @@ require 'rubocop/string_util'
21
21
  require 'rubocop/cop/util'
22
22
  require 'rubocop/cop/offense'
23
23
  require 'rubocop/cop/ignored_node'
24
+ require 'rubocop/cop/autocorrect_logic'
24
25
  require 'rubocop/cop/cop'
25
26
  require 'rubocop/cop/commissioner'
26
27
  require 'rubocop/cop/corrector'
@@ -86,6 +87,7 @@ require 'rubocop/cop/lint/invalid_character_literal'
86
87
  require 'rubocop/cop/lint/literal_in_condition'
87
88
  require 'rubocop/cop/lint/literal_in_interpolation'
88
89
  require 'rubocop/cop/lint/loop'
90
+ require 'rubocop/cop/lint/non_local_exit_from_iterator'
89
91
  require 'rubocop/cop/lint/parentheses_as_grouped_expression'
90
92
  require 'rubocop/cop/lint/require_parentheses'
91
93
  require 'rubocop/cop/lint/rescue_exception'
@@ -113,6 +115,12 @@ require 'rubocop/cop/metrics/method_length'
113
115
  require 'rubocop/cop/metrics/parameter_lists'
114
116
  require 'rubocop/cop/metrics/perceived_complexity'
115
117
 
118
+ require 'rubocop/cop/performance/detect'
119
+ require 'rubocop/cop/performance/flat_map'
120
+ require 'rubocop/cop/performance/reverse_each'
121
+ require 'rubocop/cop/performance/sample'
122
+ require 'rubocop/cop/performance/size'
123
+
116
124
  require 'rubocop/cop/style/access_modifier_indentation'
117
125
  require 'rubocop/cop/style/accessor_method_name'
118
126
  require 'rubocop/cop/style/alias'
@@ -124,11 +132,12 @@ require 'rubocop/cop/style/array_join'
124
132
  require 'rubocop/cop/style/ascii_comments'
125
133
  require 'rubocop/cop/style/ascii_identifiers'
126
134
  require 'rubocop/cop/style/attr'
135
+ require 'rubocop/cop/style/auto_resource_cleanup'
127
136
  require 'rubocop/cop/style/bare_percent_literals'
128
137
  require 'rubocop/cop/style/begin_block'
129
138
  require 'rubocop/cop/style/block_comments'
130
139
  require 'rubocop/cop/style/block_end_newline'
131
- require 'rubocop/cop/style/blocks'
140
+ require 'rubocop/cop/style/block_delimiters'
132
141
  require 'rubocop/cop/style/braces_around_hash_parameters'
133
142
  require 'rubocop/cop/style/case_equality'
134
143
  require 'rubocop/cop/style/case_indentation'
@@ -138,10 +147,13 @@ require 'rubocop/cop/style/class_and_module_children'
138
147
  require 'rubocop/cop/style/class_check'
139
148
  require 'rubocop/cop/style/class_methods'
140
149
  require 'rubocop/cop/style/class_vars'
150
+ require 'rubocop/cop/style/closing_parenthesis_indentation'
141
151
  require 'rubocop/cop/style/collection_methods'
142
152
  require 'rubocop/cop/style/colon_method_call'
153
+ require 'rubocop/cop/style/command_literal'
143
154
  require 'rubocop/cop/style/comment_annotation'
144
155
  require 'rubocop/cop/style/comment_indentation'
156
+ require 'rubocop/cop/style/copyright'
145
157
  require 'rubocop/cop/style/constant_name'
146
158
  require 'rubocop/cop/style/def_with_parentheses'
147
159
  require 'rubocop/cop/style/deprecated_hash_methods'
@@ -151,6 +163,7 @@ require 'rubocop/cop/style/double_negation'
151
163
  require 'rubocop/cop/style/each_with_object'
152
164
  require 'rubocop/cop/style/else_alignment'
153
165
  require 'rubocop/cop/style/empty_else'
166
+ require 'rubocop/cop/style/missing_else'
154
167
  require 'rubocop/cop/style/empty_line_between_defs'
155
168
  require 'rubocop/cop/style/empty_lines'
156
169
  require 'rubocop/cop/style/empty_lines_around_access_modifier'
@@ -247,6 +260,7 @@ require 'rubocop/cop/style/string_literals'
247
260
  require 'rubocop/cop/style/string_literals_in_interpolation'
248
261
  require 'rubocop/cop/style/struct_inheritance'
249
262
  require 'rubocop/cop/style/symbol_array'
263
+ require 'rubocop/cop/style/symbol_literal'
250
264
  require 'rubocop/cop/style/symbol_proc'
251
265
  require 'rubocop/cop/style/tab'
252
266
  require 'rubocop/cop/style/trailing_blank_lines'
@@ -256,7 +270,6 @@ require 'rubocop/cop/style/trivial_accessors'
256
270
  require 'rubocop/cop/style/unless_else'
257
271
  require 'rubocop/cop/style/unneeded_capital_w'
258
272
  require 'rubocop/cop/style/unneeded_percent_q'
259
- require 'rubocop/cop/style/unneeded_percent_x'
260
273
  require 'rubocop/cop/style/variable_interpolation'
261
274
  require 'rubocop/cop/style/variable_name'
262
275
  require 'rubocop/cop/style/when_then'
@@ -265,12 +278,16 @@ require 'rubocop/cop/style/while_until_modifier'
265
278
  require 'rubocop/cop/style/word_array'
266
279
 
267
280
  require 'rubocop/cop/rails/action_filter'
281
+ require 'rubocop/cop/rails/date'
268
282
  require 'rubocop/cop/rails/default_scope'
269
283
  require 'rubocop/cop/rails/delegate'
284
+ require 'rubocop/cop/rails/find_by'
285
+ require 'rubocop/cop/rails/find_each'
270
286
  require 'rubocop/cop/rails/has_and_belongs_to_many'
271
287
  require 'rubocop/cop/rails/output'
272
288
  require 'rubocop/cop/rails/read_write_attribute'
273
289
  require 'rubocop/cop/rails/scope_args'
290
+ require 'rubocop/cop/rails/time_zone'
274
291
  require 'rubocop/cop/rails/validation'
275
292
 
276
293
  require 'rubocop/formatter/base_formatter'
@@ -95,8 +95,9 @@ module RuboCop
95
95
  # TODO: This should be a private method
96
96
  def validate
97
97
  # Don't validate RuboCop's own files. Avoids infinite recursion.
98
- return if loaded_path.start_with?(File.join(ConfigLoader::RUBOCOP_HOME,
99
- 'config'))
98
+ base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
99
+ 'config'))
100
+ return if File.expand_path(loaded_path).start_with?(base_config_path)
100
101
 
101
102
  valid_cop_names, invalid_cop_names = @hash.keys.partition do |key|
102
103
  ConfigLoader.default_configuration.key?(key)
@@ -111,14 +112,33 @@ module RuboCop
111
112
  end
112
113
 
113
114
  def file_to_include?(file)
114
- absolute_file_path = File.expand_path(file)
115
115
  relative_file_path = path_relative_to_config(file)
116
+
117
+ # Optimization to quickly decide if the given file is hidden (on the top
118
+ # level) and can not be matched by any pattern.
119
+ is_hidden = relative_file_path.start_with?('.') &&
120
+ !relative_file_path.start_with?('..')
121
+ return false if is_hidden && !possibly_include_hidden?
122
+
123
+ absolute_file_path = File.expand_path(file)
124
+
116
125
  patterns_to_include.any? do |pattern|
117
126
  match_path?(pattern, relative_file_path, loaded_path) ||
118
127
  match_path?(pattern, absolute_file_path, loaded_path)
119
128
  end
120
129
  end
121
130
 
131
+ # Returns true if there's a chance that an Include pattern matches hidden
132
+ # files, false if that's definitely not possible.
133
+ def possibly_include_hidden?
134
+ if @possibly_include_hidden.nil?
135
+ @possibly_include_hidden = patterns_to_include.any? do |s|
136
+ s.is_a?(Regexp) || s.start_with?('.') || s.include?('/.')
137
+ end
138
+ end
139
+ @possibly_include_hidden
140
+ end
141
+
122
142
  def file_to_exclude?(file)
123
143
  file = File.expand_path(file)
124
144
  patterns_to_exclude.any? do |pattern|
@@ -114,7 +114,7 @@ module RuboCop
114
114
  # is not possible to reproduce now, but we want to avoid it in case
115
115
  # it's still there. So we only load the YAML code if we find some real
116
116
  # code in there.
117
- hash = yaml_code =~ /^[A-Z]/i ? YAML.load(yaml_code) : {}
117
+ hash = yaml_code =~ /^[A-Z]/i ? yaml_safe_load(yaml_code) : {}
118
118
  puts "configuration from #{absolute_path}" if debug?
119
119
 
120
120
  unless hash.is_a?(Hash)
@@ -124,6 +124,14 @@ module RuboCop
124
124
  hash
125
125
  end
126
126
 
127
+ def yaml_safe_load(yaml_code)
128
+ if YAML.respond_to?(:safe_load) # Ruby 2.1+
129
+ YAML.safe_load(yaml_code, [Regexp])
130
+ else
131
+ YAML.load(yaml_code)
132
+ end
133
+ end
134
+
127
135
  def resolve_inheritance(path, hash)
128
136
  base_configs(path, hash['inherit_from']).reverse_each do |base_config|
129
137
  base_config.each do |k, v|
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # This module encapsulates the logic for autocorrect behaviour for a cop
6
+ module AutocorrectLogic
7
+ def autocorrect?
8
+ autocorrect_requested? && support_autocorrect? && autocorrect_enabled?
9
+ end
10
+
11
+ def autocorrect_requested?
12
+ @options.fetch(:auto_correct, false)
13
+ end
14
+
15
+ def support_autocorrect?
16
+ respond_to?(:autocorrect, true)
17
+ end
18
+
19
+ def autocorrect_enabled?
20
+ # allow turning off autocorrect on a cop by cop basis
21
+ return true unless cop_config
22
+ cop_config['AutoCorrect'] != 'False'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -47,6 +47,7 @@ module RuboCop
47
47
  extend AST::Sexp
48
48
  include Util
49
49
  include IgnoredNode
50
+ include AutocorrectLogic
50
51
 
51
52
  attr_reader :config, :offenses, :corrections
52
53
  attr_accessor :processed_source # TODO: Bad design.
@@ -105,7 +106,7 @@ module RuboCop
105
106
 
106
107
  def initialize(config = nil, options = nil)
107
108
  @config = config || Config.new
108
- @options = options || { auto_correct: false, debug: false }
109
+ @options = options || { debug: false }
109
110
 
110
111
  @offenses = []
111
112
  @corrections = []
@@ -119,10 +120,6 @@ module RuboCop
119
120
  @config.for_cop(self)
120
121
  end
121
122
 
122
- def autocorrect?
123
- @options[:auto_correct] && support_autocorrect?
124
- end
125
-
126
123
  def debug?
127
124
  @options[:debug]
128
125
  end
@@ -132,12 +129,14 @@ module RuboCop
132
129
  config['AllCops'] && config['AllCops']['DisplayCopNames']
133
130
  end
134
131
 
135
- def message(_node = nil)
136
- self.class::MSG
132
+ def display_style_guide?
133
+ style_guide_url &&
134
+ (@options[:display_style_guide] ||
135
+ config['AllCops'] && config['AllCops']['DisplayStyleGuide'])
137
136
  end
138
137
 
139
- def support_autocorrect?
140
- respond_to?(:autocorrect, true)
138
+ def message(_node = nil)
139
+ self.class::MSG
141
140
  end
142
141
 
143
142
  def add_offense(node, loc, message = nil, severity = nil)
@@ -151,18 +150,24 @@ module RuboCop
151
150
  severity = custom_severity || severity || default_severity
152
151
 
153
152
  message ||= message(node)
154
- message = display_cop_names? ? "#{name}: #{message}" : message
155
-
156
- corrected = begin
157
- autocorrect(node) if autocorrect?
158
- autocorrect?
159
- rescue CorrectionNotPossible
160
- false
161
- end
153
+ message = annotate_message(message)
154
+
155
+ corrected = correct(node)
156
+
162
157
  @offenses << Offense.new(severity, location, message, name, corrected)
163
158
  yield if block_given?
164
159
  end
165
160
 
161
+ def correct(node)
162
+ return nil unless support_autocorrect?
163
+ return false unless autocorrect?
164
+
165
+ autocorrect(node)
166
+ true
167
+ rescue CorrectionNotPossible
168
+ false
169
+ end
170
+
166
171
  def config_to_allow_offenses
167
172
  Formatter::DisabledConfigFormatter.config_to_allow_offenses[cop_name]
168
173
  end
@@ -183,8 +188,19 @@ module RuboCop
183
188
  !file_name_matches_any?(file, 'Exclude', false)
184
189
  end
185
190
 
191
+ def style_guide_url
192
+ url = cop_config && cop_config['StyleGuide']
193
+ (url.nil? || url.empty?) ? nil : url
194
+ end
195
+
186
196
  private
187
197
 
198
+ def annotate_message(message)
199
+ message = "#{name}: #{message}" if display_cop_names?
200
+ message = "#{message} (#{style_guide_url})" if display_style_guide?
201
+ message
202
+ end
203
+
188
204
  def file_name_matches_any?(file, parameter, default_result)
189
205
  patterns = cop_config && cop_config[parameter]
190
206
  return default_result unless patterns