rubocop 1.9.0 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -14
  3. data/assets/output.html.erb +1 -1
  4. data/config/default.yml +70 -17
  5. data/config/obsoletion.yml +4 -0
  6. data/lib/rubocop.rb +5 -0
  7. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  8. data/lib/rubocop/cli/command/suggest_extensions.rb +3 -2
  9. data/lib/rubocop/comment_config.rb +43 -94
  10. data/lib/rubocop/config.rb +4 -1
  11. data/lib/rubocop/cop/base.rb +1 -0
  12. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
  13. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
  14. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
  15. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
  16. data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
  17. data/lib/rubocop/cop/exclude_limit.rb +26 -0
  18. data/lib/rubocop/cop/gemspec/date_assignment.rb +57 -0
  19. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
  20. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
  21. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
  22. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
  23. data/lib/rubocop/cop/generator.rb +2 -2
  24. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  25. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
  26. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
  27. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
  28. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
  29. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
  30. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
  31. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
  32. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
  33. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
  34. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
  35. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
  36. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
  37. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +11 -8
  38. data/lib/rubocop/cop/layout/argument_alignment.rb +6 -5
  39. data/lib/rubocop/cop/layout/array_alignment.rb +7 -6
  40. data/lib/rubocop/cop/layout/assignment_indentation.rb +6 -3
  41. data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
  42. data/lib/rubocop/cop/layout/block_end_newline.rb +4 -8
  43. data/lib/rubocop/cop/layout/class_structure.rb +1 -0
  44. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +14 -15
  45. data/lib/rubocop/cop/layout/comment_indentation.rb +16 -16
  46. data/lib/rubocop/cop/layout/else_alignment.rb +9 -6
  47. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +20 -3
  48. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +37 -17
  49. data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
  50. data/lib/rubocop/cop/layout/first_argument_indentation.rb +27 -7
  51. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +9 -6
  52. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +22 -15
  53. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -5
  54. data/lib/rubocop/cop/layout/indentation_consistency.rb +9 -6
  55. data/lib/rubocop/cop/layout/indentation_style.rb +27 -30
  56. data/lib/rubocop/cop/layout/indentation_width.rb +20 -9
  57. data/lib/rubocop/cop/layout/line_length.rb +2 -1
  58. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +26 -0
  59. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -5
  60. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +10 -5
  61. data/lib/rubocop/cop/layout/parameter_alignment.rb +6 -5
  62. data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
  63. data/lib/rubocop/cop/layout/space_before_brackets.rb +9 -4
  64. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  65. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
  66. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
  67. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
  68. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
  69. data/lib/rubocop/cop/lint/debugger.rb +60 -14
  70. data/lib/rubocop/cop/lint/deprecated_constants.rb +5 -0
  71. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +14 -4
  72. data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
  73. data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
  74. data/lib/rubocop/cop/lint/duplicate_require.rb +3 -2
  75. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
  76. data/lib/rubocop/cop/lint/else_layout.rb +1 -1
  77. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
  78. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
  79. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
  80. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
  81. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
  82. data/lib/rubocop/cop/lint/multiple_comparison.rb +5 -4
  83. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
  84. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
  85. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
  86. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
  87. data/lib/rubocop/cop/lint/number_conversion.rb +11 -2
  88. data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
  89. data/lib/rubocop/cop/lint/rand_one.rb +1 -0
  90. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -2
  91. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
  92. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
  93. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -3
  94. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
  95. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
  96. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
  97. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
  98. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
  99. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
  100. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  101. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
  102. data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
  103. data/lib/rubocop/cop/lint/suppressed_exception.rb +44 -1
  104. data/lib/rubocop/cop/lint/symbol_conversion.rb +91 -3
  105. data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
  106. data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
  107. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
  108. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
  109. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
  110. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
  111. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
  112. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
  113. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
  114. data/lib/rubocop/cop/lint/useless_times.rb +3 -0
  115. data/lib/rubocop/cop/message_annotator.rb +4 -1
  116. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
  117. data/lib/rubocop/cop/metrics/module_length.rb +1 -0
  118. data/lib/rubocop/cop/metrics/parameter_lists.rb +6 -2
  119. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
  120. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
  121. data/lib/rubocop/cop/mixin/alignment.rb +10 -3
  122. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  123. data/lib/rubocop/cop/mixin/code_length.rb +3 -1
  124. data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
  125. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
  126. data/lib/rubocop/cop/mixin/def_node.rb +1 -0
  127. data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
  128. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
  129. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
  130. data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
  131. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
  132. data/lib/rubocop/cop/mixin/line_length_help.rb +11 -6
  133. data/lib/rubocop/cop/mixin/method_complexity.rb +4 -1
  134. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
  135. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -23
  136. data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
  137. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +3 -3
  138. data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
  139. data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
  140. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -6
  141. data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
  142. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
  143. data/lib/rubocop/cop/naming/constant_name.rb +2 -0
  144. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +6 -0
  145. data/lib/rubocop/cop/naming/method_name.rb +3 -0
  146. data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
  147. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -0
  148. data/lib/rubocop/cop/registry.rb +10 -1
  149. data/lib/rubocop/cop/security/eval.rb +1 -0
  150. data/lib/rubocop/cop/security/json_load.rb +1 -0
  151. data/lib/rubocop/cop/security/marshal_load.rb +1 -0
  152. data/lib/rubocop/cop/security/open.rb +1 -0
  153. data/lib/rubocop/cop/security/yaml_load.rb +1 -0
  154. data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -2
  155. data/lib/rubocop/cop/style/alias.rb +1 -0
  156. data/lib/rubocop/cop/style/and_or.rb +3 -1
  157. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
  158. data/lib/rubocop/cop/style/array_coercion.rb +2 -0
  159. data/lib/rubocop/cop/style/array_join.rb +1 -0
  160. data/lib/rubocop/cop/style/attr.rb +1 -0
  161. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +59 -71
  162. data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +62 -0
  163. data/lib/rubocop/cop/style/case_equality.rb +2 -1
  164. data/lib/rubocop/cop/style/case_like_if.rb +15 -4
  165. data/lib/rubocop/cop/style/class_equality_comparison.rb +3 -0
  166. data/lib/rubocop/cop/style/collection_compact.rb +2 -0
  167. data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
  168. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  169. data/lib/rubocop/cop/style/commented_keyword.rb +10 -10
  170. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
  171. data/lib/rubocop/cop/style/constant_visibility.rb +28 -0
  172. data/lib/rubocop/cop/style/date_time.rb +3 -0
  173. data/lib/rubocop/cop/style/dir.rb +1 -0
  174. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
  175. data/lib/rubocop/cop/style/documentation.rb +30 -3
  176. data/lib/rubocop/cop/style/documentation_method.rb +1 -0
  177. data/lib/rubocop/cop/style/double_negation.rb +3 -2
  178. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
  179. data/lib/rubocop/cop/style/each_with_object.rb +1 -0
  180. data/lib/rubocop/cop/style/empty_literal.rb +9 -0
  181. data/lib/rubocop/cop/style/endless_method.rb +1 -0
  182. data/lib/rubocop/cop/style/eval_with_location.rb +90 -28
  183. data/lib/rubocop/cop/style/even_odd.rb +1 -0
  184. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
  185. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -1
  186. data/lib/rubocop/cop/style/exponential_notation.rb +6 -7
  187. data/lib/rubocop/cop/style/float_division.rb +4 -0
  188. data/lib/rubocop/cop/style/format_string.rb +2 -0
  189. data/lib/rubocop/cop/style/format_string_token.rb +1 -0
  190. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +0 -3
  191. data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
  192. data/lib/rubocop/cop/style/hash_conversion.rb +108 -0
  193. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
  194. data/lib/rubocop/cop/style/hash_except.rb +1 -0
  195. data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
  196. data/lib/rubocop/cop/style/hash_syntax.rb +16 -15
  197. data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
  198. data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
  199. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +37 -11
  200. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
  201. data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
  202. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +46 -2
  203. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -3
  204. data/lib/rubocop/cop/style/min_max.rb +1 -0
  205. data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
  206. data/lib/rubocop/cop/style/module_function.rb +5 -0
  207. data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -3
  208. data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
  209. data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
  210. data/lib/rubocop/cop/style/negated_if_else_condition.rb +16 -2
  211. data/lib/rubocop/cop/style/nil_comparison.rb +6 -1
  212. data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
  213. data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
  214. data/lib/rubocop/cop/style/numeric_literals.rb +6 -9
  215. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -1
  216. data/lib/rubocop/cop/style/option_hash.rb +1 -0
  217. data/lib/rubocop/cop/style/or_assignment.rb +2 -0
  218. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
  219. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
  220. data/lib/rubocop/cop/style/proc.rb +1 -0
  221. data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
  222. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
  223. data/lib/rubocop/cop/style/redundant_begin.rb +44 -4
  224. data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
  225. data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
  226. data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
  227. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
  228. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
  229. data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
  230. data/lib/rubocop/cop/style/redundant_return.rb +4 -0
  231. data/lib/rubocop/cop/style/redundant_self.rb +7 -3
  232. data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
  233. data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
  234. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
  235. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  236. data/lib/rubocop/cop/style/rescue_modifier.rb +17 -14
  237. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
  238. data/lib/rubocop/cop/style/return_nil.rb +6 -0
  239. data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
  240. data/lib/rubocop/cop/style/sample.rb +1 -0
  241. data/lib/rubocop/cop/style/signal_exception.rb +3 -0
  242. data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
  243. data/lib/rubocop/cop/style/single_line_methods.rb +4 -1
  244. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
  245. data/lib/rubocop/cop/style/sole_nested_conditional.rb +20 -4
  246. data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
  247. data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
  248. data/lib/rubocop/cop/style/string_chars.rb +38 -0
  249. data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
  250. data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
  251. data/lib/rubocop/cop/style/strip.rb +1 -0
  252. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -0
  253. data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
  254. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
  255. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +5 -0
  256. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
  257. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
  258. data/lib/rubocop/cop/style/unless_logical_operators.rb +105 -0
  259. data/lib/rubocop/cop/style/unpack_first.rb +1 -0
  260. data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
  261. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
  262. data/lib/rubocop/cop/util.rb +4 -1
  263. data/lib/rubocop/directive_comment.rb +69 -9
  264. data/lib/rubocop/ext/regexp_parser.rb +3 -6
  265. data/lib/rubocop/formatter/clang_style_formatter.rb +4 -2
  266. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
  267. data/lib/rubocop/formatter/simple_text_formatter.rb +2 -1
  268. data/lib/rubocop/formatter/tap_formatter.rb +4 -2
  269. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
  270. data/lib/rubocop/magic_comment.rb +1 -1
  271. data/lib/rubocop/name_similarity.rb +1 -1
  272. data/lib/rubocop/target_finder.rb +1 -0
  273. data/lib/rubocop/target_ruby.rb +21 -13
  274. data/lib/rubocop/version.rb +1 -1
  275. metadata +14 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec2d9f7ba4857375232c4e42ea44accdb38b2873c83315f3029a546e315622e0
4
- data.tar.gz: 01df5c9957cca7c79cf8cab073c1bae675d684761561835d6d93f554f3743905
3
+ metadata.gz: b8e99fa7dca255059fe40cb6426a3ac3f25ca31eaa7d0bef131216ebc4f6d984
4
+ data.tar.gz: a810490713929f48307639eb0d3acf37555c529d41691e9dc6468d2443b69dc4
5
5
  SHA512:
6
- metadata.gz: 55a5a8deae643b6d76dc5220c7136a7c5413ecb93ca85ec61dcd3aa9ff0adb3c1ab356ec81f72273771ab3125317fc105bfcaf0c7e1e1ae07f6295c7fa33c26e
7
- data.tar.gz: 642d925df9f18c6c42b532eb0193965c6a85a93bd9339523757882eb6e9029052161a32bbc4421e454a210fe2ab5318ae64459dc4a9d792ee0cb5e4b259568ff
6
+ metadata.gz: 5e7baebccb7c9d41aa23bfcf9c0e4c930d0e383bbe5b992c67b11e7edf0e56692ff2d9855cadeaf3e9d0aef57425ba0c2412e18b76ac8248f49b985bad001006
7
+ data.tar.gz: 5a4514d8eebb852646161720437cf752b2b5b628f75f55131e71c26bc35f11a0e9aa7d576340b2123838f710c51e2bb463e639181c4eb6671a2cff04694cb957
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/rubocop-hq/rubocop/master/logo/rubo-logo-horizontal.png" alt="RuboCop Logo"/>
2
+ <img src="https://raw.githubusercontent.com/rubocop/rubocop/master/logo/rubo-logo-horizontal.png" alt="RuboCop Logo"/>
3
3
  </p>
4
4
 
5
5
  ----------
6
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
6
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
7
7
  [![Gem Version](https://badge.fury.io/rb/rubocop.svg)](https://badge.fury.io/rb/rubocop)
8
- [![CircleCI Status](https://circleci.com/gh/rubocop-hq/rubocop/tree/master.svg?style=svg)](https://circleci.com/gh/rubocop-hq/rubocop/tree/master)
9
- [![Actions Status](https://github.com/rubocop-hq/rubocop/workflows/CI/badge.svg?branch=master)](https://github.com/rubocop-hq/rubocop/actions?query=workflow%3ACI)
10
- [![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop-hq/rubocop/test_coverage)
11
- [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop-hq/rubocop/maintainability)
8
+ [![CircleCI Status](https://circleci.com/gh/rubocop/rubocop/tree/master.svg?style=svg)](https://circleci.com/gh/rubocop/rubocop/tree/master)
9
+ [![Actions Status](https://github.com/rubocop/rubocop/workflows/CI/badge.svg?branch=master)](https://github.com/rubocop/rubocop/actions?query=workflow%3ACI)
10
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop/rubocop/maintainability)
12
12
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)
13
13
 
14
14
  > Role models are important. <br/>
@@ -20,7 +20,7 @@ Guide](https://rubystyle.guide). Apart from reporting the problems discovered in
20
20
  RuboCop can also automatically fix many of them for you.
21
21
 
22
22
  RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various
23
- [configuration options](https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml).
23
+ [configuration options](https://github.com/rubocop/rubocop/blob/master/config/default.yml).
24
24
 
25
25
  ----------
26
26
  [![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/bbatsov)
@@ -45,16 +45,16 @@ gem 'rubocop', require: false
45
45
  ```
46
46
 
47
47
  RuboCop is stable between major versions, both in terms of API and cop configuration.
48
- We aim the ease the maintenance of RuboCop extensions and the upgrades between RuboCop
48
+ We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop
49
49
  releases. All big changes are reserved for major releases.
50
50
  To prevent an unwanted RuboCop update you might want to use a conservative version lock
51
51
  in your `Gemfile`:
52
52
 
53
53
  ```rb
54
- gem 'rubocop', '~> 1.9', require: false
54
+ gem 'rubocop', '~> 1.12', require: false
55
55
  ```
56
56
 
57
- See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details.
57
+ See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
58
58
 
59
59
  ## Quickstart
60
60
 
@@ -82,7 +82,7 @@ See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibi
82
82
 
83
83
  If you use RuboCop in your project, you can include one of these badges in your readme to let people know that your code is written following the community Ruby Style Guide.
84
84
 
85
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
85
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
86
86
 
87
87
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
88
88
 
@@ -90,7 +90,7 @@ If you use RuboCop in your project, you can include one of these badges in your
90
90
  Here are the Markdown snippets for the two badges:
91
91
 
92
92
  ``` markdown
93
- [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
93
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
94
94
 
95
95
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
96
96
  ```
@@ -116,14 +116,14 @@ See the [team page](https://docs.rubocop.org/rubocop/about/team.html) for more d
116
116
  ## Logo
117
117
 
118
118
  RuboCop's logo was created by [Dimiter Petrov](https://www.chadomoto.com/). You can find the logo in various
119
- formats [here](https://github.com/rubocop-hq/rubocop/tree/master/logo).
119
+ formats [here](https://github.com/rubocop/rubocop/tree/master/logo).
120
120
 
121
121
  The logo is licensed under a
122
122
  [Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/deed.en_GB).
123
123
 
124
124
  ## Contributors
125
125
 
126
- Here's a [list](https://github.com/rubocop-hq/rubocop/graphs/contributors) of
126
+ Here's a [list](https://github.com/rubocop/rubocop/graphs/contributors) of
127
127
  all the people who have contributed to the development of RuboCop.
128
128
 
129
129
  I'm extremely grateful to each and every one of them!
@@ -254,7 +254,7 @@
254
254
  <% end %>
255
255
  </div>
256
256
  <footer>
257
- Generated by <a href="https://github.com/rubocop-hq/rubocop">RuboCop</a>
257
+ Generated by <a href="https://github.com/rubocop/rubocop">RuboCop</a>
258
258
  <span class="version"><%= RuboCop::Version::STRING %></span>
259
259
  </footer>
260
260
  </body>
data/config/default.yml CHANGED
@@ -203,6 +203,13 @@ Bundler/OrderedGems:
203
203
 
204
204
  #################### Gemspec ###############################
205
205
 
206
+ Gemspec/DateAssignment:
207
+ Description: 'Checks that `date =` is not used in gemspec file, it is set automatically when the gem is packaged.'
208
+ Enabled: pending
209
+ VersionAdded: '1.10'
210
+ Include:
211
+ - '**/*.gemspec'
212
+
206
213
  Gemspec/DuplicatedAssignment:
207
214
  Description: 'An attribute assignment method calls should be listed only once in a gemspec.'
208
215
  Enabled: true
@@ -1446,23 +1453,31 @@ Lint/Debugger:
1446
1453
  Description: 'Check for debugger calls.'
1447
1454
  Enabled: true
1448
1455
  VersionAdded: '0.14'
1449
- VersionChanged: '0.49'
1450
- DebuggerReceivers:
1451
- - binding
1452
- - Kernel
1453
- - Pry
1456
+ VersionChanged: '1.10'
1457
+ DebuggerReceivers: [] # deprecated
1454
1458
  DebuggerMethods:
1455
- - debugger
1456
- - byebug
1457
- - remote_byebug
1458
- - pry
1459
- - remote_pry
1460
- - pry_remote
1461
- - console
1462
- - rescue
1463
- - save_and_open_page
1464
- - save_and_open_screenshot
1465
- - irb
1459
+ # Groups are available so that a specific group can be disabled in
1460
+ # a user's configuration, but are otherwise not significant.
1461
+ Kernel:
1462
+ - binding.irb
1463
+ Byebug:
1464
+ - byebug
1465
+ - remote_byebug
1466
+ - Kernel.byebug
1467
+ - Kernel.remote_byebug
1468
+ Capybara:
1469
+ - save_and_open_page
1470
+ - save_and_open_screenshot
1471
+ Pry:
1472
+ - binding.pry
1473
+ - binding.remote_pry
1474
+ - binding.pry_remote
1475
+ - Pry.rescue
1476
+ Rails:
1477
+ - debugger
1478
+ - Kernel.debugger
1479
+ WebConsole:
1480
+ - binding.console
1466
1481
 
1467
1482
  Lint/DeprecatedClassMethods:
1468
1483
  Description: 'Check for deprecated class method calls.'
@@ -2040,13 +2055,18 @@ Lint/SuppressedException:
2040
2055
  StyleGuide: '#dont-hide-exceptions'
2041
2056
  Enabled: true
2042
2057
  AllowComments: true
2058
+ AllowNil: true
2043
2059
  VersionAdded: '0.9'
2044
- VersionChanged: '0.81'
2060
+ VersionChanged: '1.12'
2045
2061
 
2046
2062
  Lint/SymbolConversion:
2047
2063
  Description: 'Checks for unnecessary symbol conversions.'
2048
2064
  Enabled: pending
2049
2065
  VersionAdded: '1.9'
2066
+ EnforcedStyle: strict
2067
+ SupportedStyles:
2068
+ - strict
2069
+ - consistent
2050
2070
 
2051
2071
  Lint/Syntax:
2052
2072
  Description: 'Checks for syntax errors.'
@@ -2474,6 +2494,7 @@ Naming/MemoizedInstanceVariableName:
2474
2494
  - disallowed
2475
2495
  - required
2476
2496
  - optional
2497
+ Safe: false
2477
2498
 
2478
2499
  Naming/MethodName:
2479
2500
  Description: 'Use the configured style when naming methods.'
@@ -3087,6 +3108,8 @@ Style/ConstantVisibility:
3087
3108
  visibility declarations.
3088
3109
  Enabled: false
3089
3110
  VersionAdded: '0.66'
3111
+ VersionChanged: '1.10'
3112
+ IgnoreModules: false
3090
3113
 
3091
3114
  # Checks that you have put a copyright in a comment before any code.
3092
3115
  #
@@ -3157,6 +3180,7 @@ Style/Documentation:
3157
3180
  Description: 'Document classes and non-namespace modules.'
3158
3181
  Enabled: true
3159
3182
  VersionAdded: '0.9'
3183
+ AllowedConstants: []
3160
3184
  Exclude:
3161
3185
  - 'spec/**/*'
3162
3186
  - 'test/**/*'
@@ -3425,6 +3449,13 @@ Style/HashAsLastArrayItem:
3425
3449
  - braces
3426
3450
  - no_braces
3427
3451
 
3452
+ Style/HashConversion:
3453
+ Description: 'Avoid Hash[] in favor of ary.to_h or literal hashes.'
3454
+ Enabled: pending
3455
+ VersionAdded: '1.10'
3456
+ VersionChanged: '1.11'
3457
+ AllowSplatArgument: true
3458
+
3428
3459
  Style/HashEachMethods:
3429
3460
  Description: 'Use Hash#each_key and Hash#each_value.'
3430
3461
  StyleGuide: '#hash-each'
@@ -3521,6 +3552,9 @@ Style/IfWithBooleanLiteralBranches:
3521
3552
  Description: 'Checks for redundant `if` with boolean literal branches.'
3522
3553
  Enabled: pending
3523
3554
  VersionAdded: '1.9'
3555
+ SafeAutoCorrect: false
3556
+ AllowedMethods:
3557
+ - nonzero?
3524
3558
 
3525
3559
  Style/IfWithSemicolon:
3526
3560
  Description: 'Do not use if x; .... Use the ternary operator instead.'
@@ -3645,6 +3679,7 @@ Style/MethodCallWithArgsParentheses:
3645
3679
  AllowParenthesesInMultilineCall: false
3646
3680
  AllowParenthesesInChaining: false
3647
3681
  AllowParenthesesInCamelCaseMethod: false
3682
+ AllowParenthesesInStringInterpolation: false
3648
3683
  EnforcedStyle: require_parentheses
3649
3684
  SupportedStyles:
3650
3685
  - require_parentheses
@@ -4464,6 +4499,13 @@ Style/StderrPuts:
4464
4499
  Enabled: true
4465
4500
  VersionAdded: '0.51'
4466
4501
 
4502
+ Style/StringChars:
4503
+ Description: 'Checks for uses of `String#split` with empty string or regexp literal argument.'
4504
+ StyleGuide: '#string-chars'
4505
+ Enabled: pending
4506
+ Safe: false
4507
+ VersionAdded: '1.12'
4508
+
4467
4509
  Style/StringConcatenation:
4468
4510
  Description: 'Checks for places where string concatenation can be replaced with string interpolation.'
4469
4511
  StyleGuide: '#string-interpolation'
@@ -4561,6 +4603,7 @@ Style/SymbolProc:
4561
4603
  Safe: false
4562
4604
  VersionAdded: '0.26'
4563
4605
  VersionChanged: '1.5'
4606
+ AllowMethodsWithArguments: false
4564
4607
  # A list of method names to be ignored by the check.
4565
4608
  # The names should be fairly unique, otherwise you'll end up ignoring lots of code.
4566
4609
  IgnoredMethods:
@@ -4713,6 +4756,16 @@ Style/UnlessElse:
4713
4756
  Enabled: true
4714
4757
  VersionAdded: '0.9'
4715
4758
 
4759
+ Style/UnlessLogicalOperators:
4760
+ Description: >-
4761
+ Checks for use of logical operators in an unless condition.
4762
+ Enabled: false
4763
+ VersionAdded: '1.11'
4764
+ EnforcedStyle: forbid_mixed_logical_operators
4765
+ SupportedStyles:
4766
+ - forbid_mixed_logical_operators
4767
+ - forbid_logical_operators
4768
+
4716
4769
  Style/UnpackFirst:
4717
4770
  Description: >-
4718
4771
  Checks for accessing the first element of `String#unpack`
@@ -187,6 +187,10 @@ changed_parameters:
187
187
  parameters: ExcludedMethods
188
188
  alternative: IgnoredMethods
189
189
  severity: warning
190
+ - cops: Lint/Debugger
191
+ parameters: DebuggerReceivers
192
+ reason: "`DebuggerReceivers` is no longer necessary, method receivers should be specified in `DebuggerMethods` instead."
193
+ severity: warning
190
194
 
191
195
  # Enforced styles that have been removed or replaced
192
196
  changed_enforced_styles:
data/lib/rubocop.rb CHANGED
@@ -35,6 +35,7 @@ require_relative 'rubocop/cop/offense'
35
35
  require_relative 'rubocop/cop/message_annotator'
36
36
  require_relative 'rubocop/cop/ignored_node'
37
37
  require_relative 'rubocop/cop/autocorrect_logic'
38
+ require_relative 'rubocop/cop/exclude_limit'
38
39
  require_relative 'rubocop/cop/badge'
39
40
  require_relative 'rubocop/cop/registry'
40
41
  require_relative 'rubocop/cop/base'
@@ -151,6 +152,7 @@ require_relative 'rubocop/cop/bundler/gem_comment'
151
152
  require_relative 'rubocop/cop/bundler/insecure_protocol_source'
152
153
  require_relative 'rubocop/cop/bundler/ordered_gems'
153
154
 
155
+ require_relative 'rubocop/cop/gemspec/date_assignment'
154
156
  require_relative 'rubocop/cop/gemspec/duplicated_assignment'
155
157
  require_relative 'rubocop/cop/gemspec/ordered_dependencies'
156
158
  require_relative 'rubocop/cop/gemspec/required_ruby_version'
@@ -471,6 +473,7 @@ require_relative 'rubocop/cop/style/global_std_stream'
471
473
  require_relative 'rubocop/cop/style/global_vars'
472
474
  require_relative 'rubocop/cop/style/guard_clause'
473
475
  require_relative 'rubocop/cop/style/hash_as_last_array_item'
476
+ require_relative 'rubocop/cop/style/hash_conversion'
474
477
  require_relative 'rubocop/cop/style/hash_each_methods'
475
478
  require_relative 'rubocop/cop/style/hash_except'
476
479
  require_relative 'rubocop/cop/style/hash_like_case'
@@ -579,6 +582,7 @@ require_relative 'rubocop/cop/style/slicing_with_range'
579
582
  require_relative 'rubocop/cop/style/special_global_vars'
580
583
  require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
581
584
  require_relative 'rubocop/cop/style/stderr_puts'
585
+ require_relative 'rubocop/cop/style/string_chars'
582
586
  require_relative 'rubocop/cop/style/string_concatenation'
583
587
  require_relative 'rubocop/cop/style/string_hash_keys'
584
588
  require_relative 'rubocop/cop/style/string_literals'
@@ -602,6 +606,7 @@ require_relative 'rubocop/cop/style/trailing_method_end_statement'
602
606
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
603
607
  require_relative 'rubocop/cop/style/trivial_accessors'
604
608
  require_relative 'rubocop/cop/style/unless_else'
609
+ require_relative 'rubocop/cop/style/unless_logical_operators'
605
610
  require_relative 'rubocop/cop/style/unpack_first'
606
611
  require_relative 'rubocop/cop/style/variable_interpolation'
607
612
  require_relative 'rubocop/cop/style/when_then'
@@ -86,7 +86,7 @@ module RuboCop
86
86
  def maybe_print_corrected_source
87
87
  # Integration tools (like RubyMine) expect to have only the JSON result
88
88
  # when specifying JSON format. Similar HTML and JUnit are targeted as well.
89
- # See: https://github.com/rubocop-hq/rubocop/issues/8673
89
+ # See: https://github.com/rubocop/rubocop/issues/8673
90
90
  return if INTEGRATION_FORMATTERS.include?(@options[:format])
91
91
 
92
92
  return unless @options[:stdin] && @options[:auto_correct]
@@ -22,7 +22,7 @@ module RuboCop
22
22
  'RuboCop extension libraries might be helpful:'
23
23
 
24
24
  extensions.sort.each do |extension|
25
- puts " * #{extension} (http://github.com/rubocop-hq/#{extension})"
25
+ puts " * #{extension} (https://github.com/rubocop/#{extension})"
26
26
  end
27
27
 
28
28
  puts
@@ -43,7 +43,8 @@ module RuboCop
43
43
  # 2. When given RuboCop options that it doesn't make sense for
44
44
  # 3. For all formatters except specified in `INCLUDED_FORMATTERS'`
45
45
  ENV['CI'] ||
46
- @options[:only] || @options[:debug] || @options[:list_target_files] || @options[:out] ||
46
+ @options[:only] || @options[:debug] || @options[:list_target_files] ||
47
+ @options[:out] || @options[:stdin] ||
47
48
  !INCLUDED_FORMATTERS.include?(current_formatter)
48
49
  end
49
50
 
@@ -4,22 +4,6 @@ module RuboCop
4
4
  # This class parses the special `rubocop:disable` comments in a source
5
5
  # and provides a way to check if each cop is enabled at arbitrary line.
6
6
  class CommentConfig
7
- # @api private
8
- REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
9
-
10
- # @api private
11
- COP_NAME_PATTERN = '([A-Z]\w+/)*(?:[A-Z]\w+)'
12
- # @api private
13
- COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
14
- # @api private
15
- COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
16
-
17
- # @api private
18
- COMMENT_DIRECTIVE_REGEXP = Regexp.new(
19
- "# rubocop : ((?:disable|enable|todo))\\b #{COPS_PATTERN}"
20
- .gsub(' ', '\s*')
21
- )
22
-
23
7
  CopAnalysis = Struct.new(:line_ranges, :start_line_number)
24
8
 
25
9
  attr_reader :processed_source
@@ -56,13 +40,13 @@ module RuboCop
56
40
  private
57
41
 
58
42
  def extra_enabled_comments_with_names(extras:, names:)
59
- each_directive do |comment, cop_names, disabled|
60
- next unless comment_only_line?(comment.loc.expression.line)
43
+ each_directive do |directive|
44
+ next unless comment_only_line?(directive.line_number)
61
45
 
62
- if !disabled && enable_all?(comment)
63
- handle_enable_all(names, extras, comment)
46
+ if directive.enabled_all?
47
+ handle_enable_all(directive, names, extras)
64
48
  else
65
- handle_switch(cop_names, names, disabled, extras, comment)
49
+ handle_switch(directive, names, extras)
66
50
  end
67
51
  end
68
52
 
@@ -72,9 +56,11 @@ module RuboCop
72
56
  def analyze # rubocop:todo Metrics/AbcSize
73
57
  analyses = Hash.new { |hash, key| hash[key] = CopAnalysis.new([], nil) }
74
58
 
75
- each_mentioned_cop do |cop_name, disabled, line, single_line|
76
- analyses[cop_name] =
77
- analyze_cop(analyses[cop_name], disabled, line, single_line)
59
+ each_directive do |directive|
60
+ directive.cop_names.each do |cop_name|
61
+ cop_name = qualified_cop_name(cop_name)
62
+ analyses[cop_name] = analyze_cop(analyses[cop_name], directive)
63
+ end
78
64
  end
79
65
 
80
66
  analyses.each_with_object({}) do |element, hash|
@@ -83,37 +69,42 @@ module RuboCop
83
69
  end
84
70
  end
85
71
 
86
- def analyze_cop(analysis, disabled, line, single_line)
87
- if single_line
88
- analyze_single_line(analysis, line, disabled)
89
- elsif disabled
90
- analyze_disabled(analysis, line)
72
+ def analyze_cop(analysis, directive)
73
+ # Disabling cops after comments like `#=SomeDslDirective` does not related to single line
74
+ if !comment_only_line?(directive.line_number) || directive.single_line?
75
+ analyze_single_line(analysis, directive)
76
+ elsif directive.disabled?
77
+ analyze_disabled(analysis, directive)
91
78
  else
92
- analyze_rest(analysis, line)
79
+ analyze_rest(analysis, directive)
93
80
  end
94
81
  end
95
82
 
96
- def analyze_single_line(analysis, line, disabled)
97
- return analysis unless disabled
83
+ def analyze_single_line(analysis, directive)
84
+ return analysis unless directive.disabled?
98
85
 
99
- CopAnalysis.new(analysis.line_ranges + [(line..line)],
100
- analysis.start_line_number)
86
+ line = directive.line_number
87
+ start_line = analysis.start_line_number
88
+
89
+ CopAnalysis.new(analysis.line_ranges + [(line..line)], start_line)
101
90
  end
102
91
 
103
- def analyze_disabled(analysis, line)
104
- if (start_line = analysis.start_line_number)
105
- # Cop already disabled on this line, so we end the current disabled
106
- # range before we start a new range.
107
- return CopAnalysis.new(analysis.line_ranges + [start_line..line], line)
108
- end
92
+ def analyze_disabled(analysis, directive)
93
+ line = directive.line_number
94
+ start_line = analysis.start_line_number
95
+
96
+ # Cop already disabled on this line, so we end the current disabled
97
+ # range before we start a new range.
98
+ return CopAnalysis.new(analysis.line_ranges + [start_line..line], line) if start_line
109
99
 
110
100
  CopAnalysis.new(analysis.line_ranges, line)
111
101
  end
112
102
 
113
- def analyze_rest(analysis, line)
114
- if (start_line = analysis.start_line_number)
115
- return CopAnalysis.new(analysis.line_ranges + [start_line..line], nil)
116
- end
103
+ def analyze_rest(analysis, directive)
104
+ line = directive.line_number
105
+ start_line = analysis.start_line_number
106
+
107
+ return CopAnalysis.new(analysis.line_ranges + [start_line..line], nil) if start_line
117
108
 
118
109
  CopAnalysis.new(analysis.line_ranges, nil)
119
110
  end
@@ -124,54 +115,17 @@ module RuboCop
124
115
  analysis.line_ranges + [(analysis.start_line_number..Float::INFINITY)]
125
116
  end
126
117
 
127
- def each_mentioned_cop
128
- each_directive do |comment, cop_names, disabled|
129
- comment_line_number = comment.loc.expression.line
130
- single_line = !comment_only_line?(comment_line_number) ||
131
- directive_on_comment_line?(comment)
132
-
133
- cop_names.each do |cop_name|
134
- yield qualified_cop_name(cop_name), disabled, comment_line_number,
135
- single_line
136
- end
137
- end
138
- end
139
-
140
- def directive_on_comment_line?(comment)
141
- comment.text[1..-1].match?(COMMENT_DIRECTIVE_REGEXP)
142
- end
143
-
144
118
  def each_directive
145
119
  processed_source.comments.each do |comment|
146
- directive = directive_parts(comment)
147
- next unless directive
148
-
149
- yield comment, *directive
120
+ directive = DirectiveComment.new(comment)
121
+ yield directive if directive.cop_names
150
122
  end
151
123
  end
152
124
 
153
- def directive_parts(comment)
154
- match = comment.text.match(COMMENT_DIRECTIVE_REGEXP)
155
- return unless match
156
-
157
- switch, cops_string = match.captures
158
-
159
- cop_names =
160
- cops_string == 'all' ? all_cop_names : cops_string.split(/,\s*/)
161
-
162
- disabled = %w[disable todo].include?(switch)
163
-
164
- [cop_names, disabled]
165
- end
166
-
167
125
  def qualified_cop_name(cop_name)
168
126
  Cop::Registry.qualified_cop_name(cop_name.strip, processed_source.file_path)
169
127
  end
170
128
 
171
- def all_cop_names
172
- @all_cop_names ||= Cop::Registry.global.names - [REDUNDANT_DISABLE]
173
- end
174
-
175
129
  def non_comment_token_line_numbers
176
130
  @non_comment_token_line_numbers ||= begin
177
131
  non_comment_tokens = processed_source.tokens.reject(&:comment?)
@@ -179,12 +133,7 @@ module RuboCop
179
133
  end
180
134
  end
181
135
 
182
- def enable_all?(comment)
183
- _, cops = comment.text.match(COMMENT_DIRECTIVE_REGEXP).captures
184
- cops == 'all'
185
- end
186
-
187
- def handle_enable_all(names, extras, comment)
136
+ def handle_enable_all(directive, names, extras)
188
137
  enabled_cops = 0
189
138
  names.each do |name, counter|
190
139
  next unless counter.positive?
@@ -193,19 +142,19 @@ module RuboCop
193
142
  enabled_cops += 1
194
143
  end
195
144
 
196
- extras[comment] << 'all' if enabled_cops.zero?
145
+ extras[directive.comment] << 'all' if enabled_cops.zero?
197
146
  end
198
147
 
199
148
  # Collect cops that have been disabled or enabled by name in a directive comment
200
149
  # so that `Lint/RedundantCopEnableDirective` can register offenses correctly.
201
- def handle_switch(cop_names, names, disabled, extras, comment)
202
- cop_names.each do |name|
203
- if disabled
150
+ def handle_switch(directive, names, extras)
151
+ directive.cop_names.each do |name|
152
+ if directive.disabled?
204
153
  names[name] += 1
205
154
  elsif (names[name]).positive?
206
155
  names[name] -= 1
207
156
  else
208
- extras[comment] << name
157
+ extras[directive.comment] << name
209
158
  end
210
159
  end
211
160
  end