sonicop 26.8.112 → 26.8.113

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.
Files changed (343) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +11 -11
  3. data/Cargo.toml +4 -4
  4. data/README.ja.md +36 -23
  5. data/README.md +38 -26
  6. data/lib/sonicop/version.rb +1 -1
  7. data/src/config/inheritance.rs +45 -3
  8. data/src/engine.rs +11 -7
  9. data/src/lib.rs +1 -0
  10. data/src/nul_bytes.rs +2 -6
  11. data/src/parser.rs +37 -0
  12. data/src/profile.rs +13 -1
  13. data/src/rules/bundler/duplicated_group.rs +3 -2
  14. data/src/rules/bundler/gem_comment.rs +5 -4
  15. data/src/rules/gemspec/attribute_assignment.rs +4 -3
  16. data/src/rules/gemspec/deprecated_attribute_assignment.rs +7 -6
  17. data/src/rules/gemspec/duplicated_assignment.rs +4 -3
  18. data/src/rules/gemspec/require_mfa.rs +10 -9
  19. data/src/rules/gemspec/required_ruby_version.rs +3 -2
  20. data/src/rules/gemspec/support.rs +3 -2
  21. data/src/rules/layout/array_alignment.rs +1 -2
  22. data/src/rules/layout/block_end_newline.rs +5 -5
  23. data/src/rules/layout/class_structure.rs +5 -3
  24. data/src/rules/layout/closing_heredoc_indentation.rs +4 -3
  25. data/src/rules/layout/closing_parenthesis_indentation.rs +1 -2
  26. data/src/rules/layout/condition_position.rs +3 -2
  27. data/src/rules/layout/def_end_alignment.rs +2 -2
  28. data/src/rules/layout/dot_position.rs +1 -2
  29. data/src/rules/layout/empty_line_after_guard_clause.rs +3 -6
  30. data/src/rules/layout/empty_line_after_multiline_condition.rs +5 -5
  31. data/src/rules/layout/empty_lines_around_access_modifier.rs +2 -3
  32. data/src/rules/layout/empty_lines_around_arguments.rs +4 -4
  33. data/src/rules/layout/empty_lines_around_exception_handling_keywords.rs +1 -2
  34. data/src/rules/layout/empty_lines_around_method_body.rs +3 -2
  35. data/src/rules/layout/end_alignment.rs +2 -2
  36. data/src/rules/layout/extra_spacing.rs +7 -6
  37. data/src/rules/layout/first_array_element_indentation.rs +1 -2
  38. data/src/rules/layout/first_hash_element_indentation.rs +8 -6
  39. data/src/rules/layout/hash_alignment.rs +4 -4
  40. data/src/rules/layout/heredoc_argument_closing_parenthesis.rs +6 -5
  41. data/src/rules/layout/heredoc_indentation.rs +4 -3
  42. data/src/rules/layout/indentation_style.rs +4 -3
  43. data/src/rules/layout/indentation_width.rs +14 -13
  44. data/src/rules/layout/line_continuation_leading_space.rs +4 -3
  45. data/src/rules/layout/line_continuation_spacing.rs +2 -2
  46. data/src/rules/layout/line_length.rs +101 -57
  47. data/src/rules/layout/multiline_assignment_layout.rs +4 -3
  48. data/src/rules/layout/multiline_block_layout.rs +1 -2
  49. data/src/rules/layout/multiline_expression.rs +60 -31
  50. data/src/rules/layout/multiline_hash_brace_layout.rs +4 -3
  51. data/src/rules/layout/multiline_method_call_indentation.rs +1 -1
  52. data/src/rules/layout/multiline_operation_indentation.rs +3 -3
  53. data/src/rules/layout/redundant_line_break.rs +3 -2
  54. data/src/rules/layout/single_line_block_chain.rs +4 -3
  55. data/src/rules/layout/space_around_block_parameters.rs +1 -2
  56. data/src/rules/layout/space_around_equals_in_parameter_default.rs +1 -2
  57. data/src/rules/layout/space_around_operators.rs +1 -2
  58. data/src/rules/layout/space_before_brackets.rs +6 -5
  59. data/src/rules/layout/space_before_comma.rs +3 -2
  60. data/src/rules/layout/space_inside_range_literal.rs +8 -6
  61. data/src/rules/layout/support.rs +9 -7
  62. data/src/rules/layout/tokens.rs +15 -6
  63. data/src/rules/lint/access_modifier.rs +19 -10
  64. data/src/rules/lint/ambiguity.rs +2 -2
  65. data/src/rules/lint/ambiguous_block_association.rs +7 -10
  66. data/src/rules/lint/ambiguous_regexp_literal.rs +7 -5
  67. data/src/rules/lint/array_literal_in_regexp.rs +4 -3
  68. data/src/rules/lint/assignment_in_condition.rs +3 -2
  69. data/src/rules/lint/blocks.rs +2 -1
  70. data/src/rules/lint/boolean_symbol.rs +4 -4
  71. data/src/rules/lint/constant_definition_in_block.rs +1 -2
  72. data/src/rules/lint/constant_reassignment.rs +2 -1
  73. data/src/rules/lint/deprecated_open_ssl_constant.rs +1 -2
  74. data/src/rules/lint/disjunctive_assignment_in_constructor.rs +2 -2
  75. data/src/rules/lint/duplicate_branch.rs +6 -5
  76. data/src/rules/lint/duplicate_case_condition.rs +5 -5
  77. data/src/rules/lint/duplicate_hash_key.rs +4 -3
  78. data/src/rules/lint/duplicate_match_pattern.rs +7 -5
  79. data/src/rules/lint/duplicate_methods.rs +4 -3
  80. data/src/rules/lint/duplicate_require.rs +1 -2
  81. data/src/rules/lint/duplicate_set_element.rs +3 -2
  82. data/src/rules/lint/empty_conditional_body.rs +4 -3
  83. data/src/rules/lint/empty_in_pattern.rs +3 -2
  84. data/src/rules/lint/empty_when.rs +4 -4
  85. data/src/rules/lint/ensure_return.rs +3 -2
  86. data/src/rules/lint/float_comparison.rs +8 -6
  87. data/src/rules/lint/format_parameter_mismatch.rs +4 -3
  88. data/src/rules/lint/hash_compare_by_identity.rs +5 -4
  89. data/src/rules/lint/heredoc_method_call_position.rs +3 -2
  90. data/src/rules/lint/implicit_string_concatenation.rs +7 -5
  91. data/src/rules/lint/ineffective_access_modifier.rs +5 -4
  92. data/src/rules/lint/inherit_exception.rs +4 -3
  93. data/src/rules/lint/literal_as_condition.rs +5 -3
  94. data/src/rules/lint/literal_assignment_in_condition.rs +4 -3
  95. data/src/rules/lint/literal_in_interpolation.rs +5 -5
  96. data/src/rules/lint/literals.rs +10 -8
  97. data/src/rules/lint/no_return_in_begin_end_blocks.rs +2 -2
  98. data/src/rules/lint/node_equality.rs +8 -5
  99. data/src/rules/lint/non_atomic_file_operation.rs +1 -1
  100. data/src/rules/lint/non_deterministic_require_order.rs +5 -3
  101. data/src/rules/lint/non_local_exit_from_iterator.rs +3 -2
  102. data/src/rules/lint/number_conversion.rs +1 -1
  103. data/src/rules/lint/out_of_range_regexp_ref.rs +6 -4
  104. data/src/rules/lint/redundant_dir_glob_sort.rs +1 -2
  105. data/src/rules/lint/redundant_safe_navigation.rs +4 -3
  106. data/src/rules/lint/redundant_splat_expansion.rs +4 -2
  107. data/src/rules/lint/redundant_string_coercion.rs +3 -2
  108. data/src/rules/lint/regexp_source.rs +2 -2
  109. data/src/rules/lint/require_range_parentheses.rs +5 -5
  110. data/src/rules/lint/rescue_exception.rs +4 -3
  111. data/src/rules/lint/rescue_type.rs +3 -2
  112. data/src/rules/lint/return_in_void_context.rs +2 -2
  113. data/src/rules/lint/safe_navigation_chain.rs +3 -2
  114. data/src/rules/lint/self_assignment.rs +3 -2
  115. data/src/rules/lint/shadowed_argument.rs +2 -2
  116. data/src/rules/lint/shadowed_exception.rs +2 -2
  117. data/src/rules/lint/suppressed_exception_in_number_conversion.rs +4 -3
  118. data/src/rules/lint/symbol_conversion.rs +6 -5
  119. data/src/rules/lint/syntax.rs +4 -3
  120. data/src/rules/lint/triple_quotes.rs +3 -2
  121. data/src/rules/lint/unescaped_bracket_in_regexp.rs +1 -1
  122. data/src/rules/lint/unexpected_block_arity.rs +3 -2
  123. data/src/rules/lint/unmodified_reduce_accumulator.rs +7 -6
  124. data/src/rules/lint/unreachable_pattern_branch.rs +4 -4
  125. data/src/rules/lint/unused_block_argument.rs +2 -2
  126. data/src/rules/lint/unused_method_argument.rs +1 -2
  127. data/src/rules/lint/useless_assignment.rs +3 -2
  128. data/src/rules/lint/useless_constant_scoping.rs +3 -2
  129. data/src/rules/lint/useless_else_without_rescue.rs +4 -3
  130. data/src/rules/lint/useless_rescue.rs +5 -4
  131. data/src/rules/lint/useless_ruby2_keywords.rs +2 -1
  132. data/src/rules/lint/useless_setter_call.rs +5 -4
  133. data/src/rules/lint/useless_times.rs +4 -3
  134. data/src/rules/lint/variable_force.rs +146 -100
  135. data/src/rules/lint/void.rs +5 -4
  136. data/src/rules/metrics/block_nesting.rs +1 -2
  137. data/src/rules/metrics/collection_literal_length.rs +2 -1
  138. data/src/rules/metrics/complexity.rs +18 -13
  139. data/src/rules/metrics/fragments.rs +10 -14
  140. data/src/rules/metrics/locals.rs +23 -12
  141. data/src/rules/metrics/parameter_lists.rs +7 -6
  142. data/src/rules/metrics/support.rs +1 -1
  143. data/src/rules/mod.rs +464 -62
  144. data/src/rules/naming/ascii_identifiers.rs +3 -3
  145. data/src/rules/naming/block_forwarding.rs +9 -8
  146. data/src/rules/naming/constant_name.rs +1 -1
  147. data/src/rules/naming/predicate_method.rs +6 -5
  148. data/src/rules/naming/predicate_prefix.rs +10 -8
  149. data/src/rules/naming/rescued_exceptions_variable_name.rs +8 -6
  150. data/src/rules/naming/support.rs +7 -5
  151. data/src/rules/naming/variable_number.rs +4 -4
  152. data/src/rules/node_ext.rs +1 -1
  153. data/src/rules/ruby_literal.rs +3 -2
  154. data/src/rules/security/compound_hash.rs +3 -2
  155. data/src/rules/security/open.rs +5 -4
  156. data/src/rules/send_node.rs +134 -0
  157. data/src/rules/single_line.rs +4 -4
  158. data/src/rules/style/access_modifier_declarations.rs +1 -1
  159. data/src/rules/style/alias.rs +1 -2
  160. data/src/rules/style/and_or.rs +2 -2
  161. data/src/rules/style/arguments_forwarding.rs +5 -5
  162. data/src/rules/style/array_coercion.rs +5 -5
  163. data/src/rules/style/array_first_last.rs +3 -3
  164. data/src/rules/style/array_intersect.rs +2 -2
  165. data/src/rules/style/array_intersect_with_single_element.rs +1 -1
  166. data/src/rules/style/attr.rs +1 -1
  167. data/src/rules/style/auto_resource_cleanup.rs +1 -1
  168. data/src/rules/style/bitwise_predicate.rs +2 -2
  169. data/src/rules/style/block_args.rs +1 -1
  170. data/src/rules/style/block_delimiters.rs +7 -6
  171. data/src/rules/style/case_equality.rs +3 -2
  172. data/src/rules/style/case_like_if.rs +1 -1
  173. data/src/rules/style/class_and_module_children.rs +7 -5
  174. data/src/rules/style/class_methods.rs +1 -1
  175. data/src/rules/style/collection_compact.rs +4 -4
  176. data/src/rules/style/combinable_defined.rs +2 -2
  177. data/src/rules/style/combinable_loops.rs +1 -1
  178. data/src/rules/style/comparable_clamp.rs +2 -2
  179. data/src/rules/style/concat_array_literals.rs +3 -3
  180. data/src/rules/style/conditional.rs +8 -1
  181. data/src/rules/style/constant_visibility.rs +3 -3
  182. data/src/rules/style/copyright.rs +1 -1
  183. data/src/rules/style/data_inheritance.rs +1 -1
  184. data/src/rules/style/def_with_parentheses.rs +1 -1
  185. data/src/rules/style/document_dynamic_eval_definition.rs +1 -1
  186. data/src/rules/style/documentation.rs +1 -1
  187. data/src/rules/style/each_for_simple_loop.rs +1 -1
  188. data/src/rules/style/each_with_object.rs +4 -4
  189. data/src/rules/style/empty_block_parameter.rs +1 -1
  190. data/src/rules/style/empty_case_condition.rs +6 -6
  191. data/src/rules/style/empty_class_definition.rs +1 -1
  192. data/src/rules/style/empty_else.rs +1 -1
  193. data/src/rules/style/empty_heredoc.rs +1 -1
  194. data/src/rules/style/empty_lambda_parameter.rs +1 -1
  195. data/src/rules/style/empty_literal.rs +2 -2
  196. data/src/rules/style/empty_method.rs +1 -1
  197. data/src/rules/style/empty_string_inside_interpolation.rs +1 -1
  198. data/src/rules/style/endless.rs +1 -1
  199. data/src/rules/style/env_home.rs +1 -1
  200. data/src/rules/style/even_odd.rs +1 -1
  201. data/src/rules/style/exact_regexp_match.rs +1 -1
  202. data/src/rules/style/expand_path_arguments.rs +3 -3
  203. data/src/rules/style/explicit_block_argument.rs +3 -3
  204. data/src/rules/style/file_open_call.rs +3 -3
  205. data/src/rules/style/file_write.rs +1 -1
  206. data/src/rules/style/for.rs +1 -1
  207. data/src/rules/style/format_string.rs +2 -2
  208. data/src/rules/style/format_string_token.rs +6 -6
  209. data/src/rules/style/guard_clause.rs +8 -7
  210. data/src/rules/style/hash_as_last_array_item.rs +4 -4
  211. data/src/rules/style/hash_each_methods.rs +1 -1
  212. data/src/rules/style/hash_like_case.rs +8 -8
  213. data/src/rules/style/hash_lookup_method.rs +3 -3
  214. data/src/rules/style/hash_subset.rs +16 -10
  215. data/src/rules/style/hash_syntax.rs +4 -4
  216. data/src/rules/style/hash_transform.rs +20 -18
  217. data/src/rules/style/identical_conditional_branches.rs +4 -5
  218. data/src/rules/style/if_inside_else.rs +3 -3
  219. data/src/rules/style/if_unless_modifier.rs +13 -14
  220. data/src/rules/style/if_with_boolean_literal_branches.rs +1 -1
  221. data/src/rules/style/if_with_semicolon.rs +1 -1
  222. data/src/rules/style/in_pattern_then.rs +2 -2
  223. data/src/rules/style/inverse_methods.rs +2 -2
  224. data/src/rules/style/invertible_unless_condition.rs +3 -3
  225. data/src/rules/style/it_block_parameter.rs +1 -1
  226. data/src/rules/style/keyword_arguments_merging.rs +2 -2
  227. data/src/rules/style/keyword_parameters_order.rs +1 -1
  228. data/src/rules/style/magic_comment_format.rs +3 -2
  229. data/src/rules/style/map_chain.rs +1 -1
  230. data/src/rules/style/map_compact_with_conditional_block.rs +3 -3
  231. data/src/rules/style/map_into_array.rs +7 -7
  232. data/src/rules/style/map_join.rs +3 -3
  233. data/src/rules/style/method_call_with_args_parentheses.rs +7 -7
  234. data/src/rules/style/method_call_without_args_parentheses.rs +2 -2
  235. data/src/rules/style/method_def_parentheses.rs +2 -3
  236. data/src/rules/style/min_max.rs +3 -3
  237. data/src/rules/style/min_max_comparison.rs +2 -2
  238. data/src/rules/style/missing_else.rs +1 -1
  239. data/src/rules/style/missing_respond_to_missing.rs +1 -1
  240. data/src/rules/style/mixin_grouping.rs +1 -1
  241. data/src/rules/style/multiline_block_chain.rs +2 -2
  242. data/src/rules/style/multiline_if_then.rs +1 -1
  243. data/src/rules/style/multiline_in_pattern_then.rs +1 -1
  244. data/src/rules/style/multiline_method_signature.rs +1 -1
  245. data/src/rules/style/multiline_when_then.rs +2 -2
  246. data/src/rules/style/mutable_constant.rs +3 -3
  247. data/src/rules/style/negated_if.rs +2 -2
  248. data/src/rules/style/negated_if_else_condition.rs +2 -2
  249. data/src/rules/style/negated_while.rs +1 -1
  250. data/src/rules/style/negative_array_index.rs +2 -2
  251. data/src/rules/style/nested_modifier.rs +1 -1
  252. data/src/rules/style/nested_parenthesized_calls.rs +2 -2
  253. data/src/rules/style/nested_ternary_operator.rs +2 -2
  254. data/src/rules/style/next.rs +1 -1
  255. data/src/rules/style/nil_lambda.rs +2 -2
  256. data/src/rules/style/nodes.rs +21 -0
  257. data/src/rules/style/non_nil_check.rs +2 -2
  258. data/src/rules/style/numbered_parameters_limit.rs +2 -2
  259. data/src/rules/style/one_line_conditional.rs +4 -4
  260. data/src/rules/style/optional_arguments.rs +1 -1
  261. data/src/rules/style/or_assignment.rs +1 -1
  262. data/src/rules/style/parallel_assignment.rs +9 -10
  263. data/src/rules/style/parens.rs +1 -1
  264. data/src/rules/style/parentheses_around_condition.rs +3 -3
  265. data/src/rules/style/partition_instead_of_double_select.rs +3 -3
  266. data/src/rules/style/percent.rs +9 -7
  267. data/src/rules/style/percent_q_literals.rs +4 -3
  268. data/src/rules/style/preferred_hash_methods.rs +1 -1
  269. data/src/rules/style/random_with_offset.rs +1 -1
  270. data/src/rules/style/reduce_to_hash.rs +6 -6
  271. data/src/rules/style/redundant_argument.rs +1 -1
  272. data/src/rules/style/redundant_assignment.rs +5 -5
  273. data/src/rules/style/redundant_begin.rs +2 -2
  274. data/src/rules/style/redundant_capital_w.rs +3 -2
  275. data/src/rules/style/redundant_condition.rs +9 -7
  276. data/src/rules/style/redundant_current_directory_in_path.rs +2 -2
  277. data/src/rules/style/redundant_double_splat_hash_braces.rs +4 -4
  278. data/src/rules/style/redundant_file_extension_in_require.rs +2 -2
  279. data/src/rules/style/redundant_format.rs +16 -14
  280. data/src/rules/style/redundant_freeze.rs +1 -1
  281. data/src/rules/style/redundant_heredoc_delimiter_quotes.rs +1 -1
  282. data/src/rules/style/redundant_initialize.rs +2 -2
  283. data/src/rules/style/redundant_interpolation.rs +2 -2
  284. data/src/rules/style/redundant_interpolation_unfreeze.rs +2 -2
  285. data/src/rules/style/redundant_line_continuation.rs +5 -4
  286. data/src/rules/style/redundant_parentheses.rs +16 -15
  287. data/src/rules/style/redundant_regexp_argument.rs +1 -1
  288. data/src/rules/style/redundant_regexp_character_class.rs +4 -3
  289. data/src/rules/style/redundant_regexp_escape.rs +3 -2
  290. data/src/rules/style/redundant_return.rs +1 -2
  291. data/src/rules/style/redundant_self.rs +11 -11
  292. data/src/rules/style/redundant_sort.rs +1 -1
  293. data/src/rules/style/redundant_sort_by.rs +1 -1
  294. data/src/rules/style/redundant_string_escape.rs +6 -5
  295. data/src/rules/style/regexp_literal.rs +3 -2
  296. data/src/rules/style/require_order.rs +2 -2
  297. data/src/rules/style/rescue_modifier.rs +1 -1
  298. data/src/rules/style/rescue_standard_error.rs +1 -1
  299. data/src/rules/style/return_nil.rs +2 -2
  300. data/src/rules/style/return_nil_in_predicate_method_definition.rs +2 -2
  301. data/src/rules/style/safe_navigation.rs +2 -2
  302. data/src/rules/style/sample.rs +3 -3
  303. data/src/rules/style/select_by.rs +2 -2
  304. data/src/rules/style/select_by_range.rs +1 -1
  305. data/src/rules/style/semicolon.rs +5 -4
  306. data/src/rules/style/single_argument_dig.rs +1 -1
  307. data/src/rules/style/single_line_block_params.rs +7 -6
  308. data/src/rules/style/single_line_do_end_block.rs +13 -12
  309. data/src/rules/style/single_line_methods.rs +2 -2
  310. data/src/rules/style/slicing_with_range.rs +2 -2
  311. data/src/rules/style/sole_nested_conditional.rs +4 -4
  312. data/src/rules/style/special_global_vars.rs +2 -2
  313. data/src/rules/style/stabby_lambda_parentheses.rs +1 -1
  314. data/src/rules/style/statement_modifier.rs +3 -2
  315. data/src/rules/style/static_class.rs +1 -1
  316. data/src/rules/style/string_concatenation.rs +9 -7
  317. data/src/rules/style/string_hash_keys.rs +3 -2
  318. data/src/rules/style/string_literals.rs +3 -3
  319. data/src/rules/style/string_literals_in_interpolation.rs +1 -1
  320. data/src/rules/style/struct_inheritance.rs +3 -3
  321. data/src/rules/style/super_arguments.rs +2 -2
  322. data/src/rules/style/super_with_args_parentheses.rs +1 -1
  323. data/src/rules/style/swap_values.rs +1 -1
  324. data/src/rules/style/symbol_array.rs +1 -1
  325. data/src/rules/style/symbol_proc.rs +3 -3
  326. data/src/rules/style/tally_method.rs +4 -4
  327. data/src/rules/style/ternary_parentheses.rs +4 -4
  328. data/src/rules/style/top_level_method_definition.rs +1 -1
  329. data/src/rules/style/trailing_body.rs +1 -1
  330. data/src/rules/style/trailing_comma_in_array_literal.rs +1 -1
  331. data/src/rules/style/trailing_comma_in_hash_literal.rs +1 -1
  332. data/src/rules/style/trailing_method_end_statement.rs +1 -1
  333. data/src/rules/style/trailing_underscore_variable.rs +4 -5
  334. data/src/rules/style/trivial_accessors.rs +2 -2
  335. data/src/rules/style/unless_logical_operators.rs +1 -1
  336. data/src/rules/style/unpack_first.rs +1 -1
  337. data/src/rules/style/when_then.rs +4 -4
  338. data/src/rules/style/while_until_do.rs +1 -1
  339. data/src/rules/style/while_until_modifier.rs +3 -3
  340. data/src/rules/style/word_array.rs +3 -3
  341. data/src/rules/style/yoda_condition.rs +2 -2
  342. data/src/rules/support.rs +33 -8
  343. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd4ccd5169f98c0ac8c5aedbe9dd4662344c27da16b2a4ea009a5f95b77a0cff
4
- data.tar.gz: d516055ea9785026bda48a405d49ad97fc0e0851469bafa7d71cb341b663bda3
3
+ metadata.gz: 60de249d7f58e674b388a3514790bbaf79f4fc4ce59338d281b1684fbe124bd2
4
+ data.tar.gz: afe8bb37e97f4c4043825877ca906d79e7511dc98e1ac6270a8b2d84a3824f30
5
5
  SHA512:
6
- metadata.gz: a28ead40c6fd72e5e79ea4c69e3d6dabeeb1a5af3004110548ae02cbad6310bbdaf6fe7f5765afc3014d77dd640dcad02821465be4d6d866808f080bc697f822
7
- data.tar.gz: f422f7e53c4e4a7535ac1910ca2bbf50a0e7fae1851fcb94621a0dcec388bf4bdd0164962b140187085e15eabb5e31351f0e4c0a04ae6cb050fa8b1f7834e009
6
+ metadata.gz: 856f0aab5b6a28b07ddc026d2513b9415f7b50b3697b1e256667796683b929dade0950e22b71dc90259d98ab6ef5ffb43f5db7ab059e2d3948deacdafc080251
7
+ data.tar.gz: ebfba527d38101fec7b231c916dfb5ee3c47f602da107a555a8a7df56c1393c4c2ed968f1f113881a73a723cd8136593e7c1e304ffd81fe52b2e1795ff216d7e
data/Cargo.lock CHANGED
@@ -128,9 +128,9 @@ dependencies = [
128
128
 
129
129
  [[package]]
130
130
  name = "bstr"
131
- version = "1.13.0"
131
+ version = "1.13.1"
132
132
  source = "registry+https://github.com/rust-lang/crates.io-index"
133
- checksum = "1f7dc094d718f2e1c1559ad110e27eeaae14a5465d3d56dd6dbd793079fbd530"
133
+ checksum = "6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f"
134
134
  dependencies = [
135
135
  "memchr",
136
136
  "regex-automata",
@@ -145,9 +145,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
145
145
 
146
146
  [[package]]
147
147
  name = "cc"
148
- version = "1.4.0"
148
+ version = "1.4.3"
149
149
  source = "registry+https://github.com/rust-lang/crates.io-index"
150
- checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
150
+ checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d"
151
151
  dependencies = [
152
152
  "find-msvc-tools",
153
153
  "shlex",
@@ -317,9 +317,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
317
317
 
318
318
  [[package]]
319
319
  name = "find-msvc-tools"
320
- version = "0.1.9"
320
+ version = "0.1.11"
321
321
  source = "registry+https://github.com/rust-lang/crates.io-index"
322
- checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
322
+ checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890"
323
323
 
324
324
  [[package]]
325
325
  name = "foreign-types"
@@ -549,9 +549,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
549
549
 
550
550
  [[package]]
551
551
  name = "pkg-config"
552
- version = "0.3.33"
552
+ version = "0.3.34"
553
553
  source = "registry+https://github.com/rust-lang/crates.io-index"
554
- checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
554
+ checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
555
555
 
556
556
  [[package]]
557
557
  name = "predicates"
@@ -793,7 +793,7 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
793
793
 
794
794
  [[package]]
795
795
  name = "sonicop"
796
- version = "26.8.112"
796
+ version = "26.8.113"
797
797
  dependencies = [
798
798
  "anyhow",
799
799
  "assert_cmd",
@@ -880,9 +880,9 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
880
880
 
881
881
  [[package]]
882
882
  name = "tree-sitter"
883
- version = "0.26.11"
883
+ version = "0.26.12"
884
884
  source = "registry+https://github.com/rust-lang/crates.io-index"
885
- checksum = "af1c71c1c4cc0920b20d6b0f6572e7682cd07a6a2faec71067a31fa394c586df"
885
+ checksum = "83c567a8e18ae93f20982c90370b16fd24023aeaf52f6052b96957ab253a0fec"
886
886
  dependencies = [
887
887
  "cc",
888
888
  "regex",
data/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sonicop"
3
- version = "26.8.112"
3
+ version = "26.8.113"
4
4
  edition = "2024"
5
5
  rust-version = "1.85"
6
6
  description = "A fast, native RuboCop-compatible Ruby linter and formatter"
@@ -29,7 +29,7 @@ serde_json = "1.0.151"
29
29
  serde_yaml_ng = "0.10"
30
30
  shell-words = "1.1.1"
31
31
  tempfile = "3.27.0"
32
- tree-sitter = "0.26.11"
32
+ tree-sitter = "0.26.12"
33
33
  tree-sitter-ruby = { git = "https://github.com/owayo/tree-sitter-ruby.git", tag = "v26.8.103" }
34
34
  ureq = { version = "3.4", default-features = false, features = ["native-tls"] }
35
35
 
@@ -44,8 +44,8 @@ lto = "thin"
44
44
  codegen-units = 1
45
45
  strip = true
46
46
 
47
- # `cargo build --profile profiling` keeps the symbols a sampling profiler needs while
48
- # generating exactly the code `--release` does.
47
+ # `cargo build --profile profiling` はサンプリングプロファイラ用のシンボルを残しつつ、
48
+ # `--release` と同じ最適化コードを生成する。
49
49
  [profile.profiling]
50
50
  inherits = "release"
51
51
  debug = 1
data/README.ja.md CHANGED
@@ -153,6 +153,8 @@ sonicop --show-cops
153
153
  `AllCops/DisabledByDefault`、`Include`/`Exclude`、Cop ごとの `Enabled`、`Exclude`、
154
154
  `Severity`、`Safe`、`SafeAutoCorrect` と設定値に対応します。宣言されたプラグイン由来の
155
155
  Cop は「認識済み・未実装」として受理し、Ruby プラグインコード自体は実行しません。
156
+ リモート設定のリクエストには 30 秒のネットワークタイムアウトを設け、応答は 1 件あたり
157
+ 5 MiB に制限します。
156
158
 
157
159
  ```yaml
158
160
  inherit_from: .rubocop_todo.yml
@@ -229,52 +231,63 @@ autocorrect は RuboCop 自身のツリーと Mastodon でバイト単位に一
229
231
  既定の実行はどちらの群にも届きません。)
230
232
  各値は暖機後 2 回の最速値です。
231
233
 
232
- | コーパス | ファイル | RuboCop 並列 | Sonicop 並列 | RuboCop 単一 | Sonicop 単一 |
233
- |---|---:|---:|---:|---:|---:|
234
- | rubocop/rubocop | 1,765 | 12.71 秒 | **4.59 秒** | 42.74 秒 | **13.75 秒** |
235
- | mastodon/mastodon | 3,290 | 29.95 秒 | **6.48 秒** | 37.60 秒 | **15.88 秒** |
236
- | Homebrew/brew | 2,179 | 18.20 秒 | **4.31 秒** | 38.72 秒 | **11.67 秒** |
237
- | rails/rails | 3,551 | 52.55 秒 | **16.88 秒** | 162.55 秒 | **63.97 秒** |
238
- | ruby/ruby | 7,466 | 132.17 秒 | **43.10 秒** | 199.78 秒 | **76.07 秒** |
234
+ | コーパス | ファイル | offense | RuboCop 並列 | Sonicop 並列 | RuboCop 単一 | Sonicop 単一 |
235
+ |---|---:|---:|---:|---:|---:|---:|
236
+ | rubocop/rubocop | 1,780 | 5,826 | 10.85 秒 | **1.53 秒** | 41.44 秒 | **8.96 秒** |
237
+ | mastodon/mastodon | 3,292 | 15,293 | 22.59 秒 | **3.04 秒** | 34.74 秒 | **6.86 秒** |
238
+ | Homebrew/brew | 2,296 | 51,527 | 13.56 秒 | **2.21 秒** | 40.36 秒 | **6.51 秒** |
239
+ | rails/rails | 3,562 | 168,615 | 32.90 秒 | **8.84 秒** | 85.71 秒 | **19.17 秒** |
240
+ | ruby/ruby | 7,477 | 765,975 | 86.89 秒 | **15.59 秒** | 193.59 秒 | **37.98 秒** |
239
241
 
240
- 差は並列で 2.8〜4.6 倍、単一プロセスで 2.43.3 倍と幅があり、1 コーパスでは代表できません。
242
+ 差は並列で 3.77.4 倍、単一プロセスで 4.56.2 倍と幅があり、1 コーパスでは代表できません。
241
243
  **単一プロセスの列を読み、並列は目安として扱ってください。** 同じ 2 つのバイナリを 1 日に
242
244
  3 回測ったところ、単一プロセスの値は毎回 16% 以内に収まったのに対し、RuboCop 自身のツリーでの
243
245
  並列の倍率は、マシンが他に何をしていたかだけで 3.3 倍から 9.2 倍まで動きました。単一プロセスは
244
246
  エンジンを測っていますが、並列はエンジンに加えて「その実行でスケジューリングがそのツリーに
245
247
  どれだけ噛み合ったか」を測っています。
246
248
 
247
- 仕事を省いて速いわけではありません。この同じ 394 Cop について、RuboCop 自身のツリー・
248
- Rails・Mastodon 3 つで**すべての offense が一致**します(計 188,812 件、どちらの側にも
249
- 残りません)。autocorrect は前者と後者でバイト単位に一致します。
249
+ 仕事を省いて速いわけではありません。この同じ 394 Cop について、表のどのコーパスでも
250
+ **offense の総数が一致**し、RuboCop 自身のツリーと Mastodon ではその 1 件ずつが同じ位置・
251
+ 同じメッセージ・同じ severity です。Rails は 168,615 件のうち 2 件だけ食い違います
252
+ (Sonicop が出す `Style/CaseLikeIf` 1 件と、出さない `Metrics/AbcSize` 1 件)。
253
+ RuboCop 自身のツリーでは 1 件の `correctable` フラグが違います。
254
+ autocorrect は前者と後者でバイト単位に一致します。
250
255
 
251
- 再現時に注意が必要な点が 3 つあります。RuboCop は **`--cache false` と併用すると
256
+ 再現時に注意が必要な点が 4 つあります。RuboCop は **`--cache false` と併用すると
252
257
  `--parallel` を黙って無効化します**。そのためここでの並列実行はキャッシュを有効にしたうえで
253
258
  実行ごとにキャッシュディレクトリを消しており、`--cache false --parallel` で計測すると
254
259
  単一プロセスを測ることになり差が過大に出ます。また RuboCop の既定は単一プロセス、
255
260
  Sonicop は `--no-parallel` を渡さない限り並列です。そして**両方ともキャッシュを空にする**
256
261
  必要があります。Sonicop も既定でキャッシュするため、同じツリーを 2 回目に流すと自分の
257
262
  キャッシュが答えてしまい、エンジンについては何も測れません。どちらにも使い捨ての
258
- キャッシュディレクトリを渡してください。
263
+ キャッシュディレクトリを渡してください。最後に、そのキャッシュディレクトリは**実パス**である
264
+ 必要があります。macOS の `mktemp -d` は `/var/folders/…` を返し、その `/var` は symlink なので
265
+ RuboCop はそこを拒み、キャッシュ無しで走ってしまいます。
259
266
 
260
267
  ```bash
261
268
  # RuboCop(並列・キャッシュは毎回空・既定の全 394 Cop)
262
- rubocop --force-default-config --cache true --cache-root "$(mktemp -d)" \
269
+ root=$(mktemp -d /private/tmp/bench.XXXXXX)
270
+ rubocop --force-default-config --cache true --cache-root "$root" \
263
271
  --no-color --parallel -f quiet
264
272
 
265
273
  # Sonicop(キャッシュは毎回空)
266
- sonicop --force-default-config --cache-root "$(mktemp -d)" --format quiet
274
+ sonicop --force-default-config --cache-root "$root" --format quiet
267
275
  ```
268
276
 
277
+ キャッシュの書き込みもこの数値に含まれており、無料ではありません。索引は全 offense を
278
+ 「見つかった行のテキスト」付きで保持するため、`ruby/ruby` では 336 MB になります。
279
+ 2 回目の実行(キャッシュ命中)は `ruby/ruby` で 1.59 秒、Rails で 0.42 秒です。
280
+
269
281
  測定機は Apple M2(8 コア)、Ruby 4.0.6(YJIT 利用可)、RubyGems 導入の RuboCop 1.89.0。
270
- 1 分平均のロードアベレージは、計測開始時が 4.0、終了時が 3.1 でした。**アイドル状態ではありません**。
271
- RuboCop 自身のツリーだけは後から単独で測り直しています(負荷 3.7 4.0)。1 回目はリリース
272
- ビルドの終わりがけに走ってしまい、値が 60% ほど高く出たためです。**負荷の違う 1 行を同じ表に
273
- 並べることはできません**。
274
- 両者を同じ条件で測っているため倍率は保たれますが、秒数そのものは下限ではなく、静かなマシンなら
275
- より速く出ます。コアを奪い合うものが動いていると両者とも膨らみ、その度合いは一致しません。それが
276
- 並列の列があれだけ動く理由です。秒数そのものが重要なときは、他に負荷のない状態で測り、**実行の
277
- 前後でロードアベレージを記録してください**その情報が無い数値は、別の数値と比べられません。
282
+ 2026-08-31 に、`rubocop_rubocop` 2693129 / `mastodon_mastodon` b59ddc7 / `Homebrew_brew` b42173b /
283
+ `rails_rails` a19f07f / `ruby_ruby` 22e4a75 の各リビジョンに対して測定しました。
284
+ 1 分平均のロードアベレージは各行の測定時点で 4.5〜7.1 で、その大半は RuboCop 自身の並列
285
+ ワーカーです(計測する以上避けられません)。**アイドル状態ではありません。**
286
+ 各コーパスで両者を連続して同じ条件で測っているため倍率は保たれますが、秒数そのものは下限ではなく、
287
+ 静かなマシンならより速く出ます。コアを奪い合うものが動いていると両者とも膨らみ、その度合いは
288
+ 一致しません。それが並列の列があれだけ動く理由です。秒数そのものが重要なときは、他に負荷のない
289
+ 状態で測り、**実行の前後でロードアベレージを記録してください**その情報が無い数値は、
290
+ 別の数値と比べられません。
278
291
 
279
292
  ## 開発
280
293
 
data/README.md CHANGED
@@ -160,6 +160,8 @@ run. Local and HTTPS `inherit_from`, `inherit_gem`, `inherit_mode`,
160
160
  `AllCops/DisabledByDefault`, `Include`, and `Exclude`, plus per-cop `Enabled`, `Exclude`,
161
161
  `Severity`, `Safe`, `SafeAutoCorrect`, and cop settings are supported. Cops supplied by declared
162
162
  plugins are accepted as recognized-but-unimplemented without executing Ruby plugin code.
163
+ Remote configuration requests use 30-second network timeouts, and each response is limited to
164
+ 5 MiB.
163
165
 
164
166
  ```yaml
165
167
  inherit_from: .rubocop_todo.yml
@@ -240,52 +242,62 @@ once the 159 RuboCop ships as `Enabled: pending` and the 56 it ships as `Enabled
240
242
  aside; a default run reaches neither group on either side.) Times are the fastest of two
241
243
  warmed runs.
242
244
 
243
- | Corpus | Files | RuboCop parallel | Sonicop parallel | RuboCop single | Sonicop single |
244
- |---|---:|---:|---:|---:|---:|
245
- | rubocop/rubocop | 1,765 | 12.71 s | **4.59 s** | 42.74 s | **13.75 s** |
246
- | mastodon/mastodon | 3,290 | 29.95 s | **6.48 s** | 37.60 s | **15.88 s** |
247
- | Homebrew/brew | 2,179 | 18.20 s | **4.31 s** | 38.72 s | **11.67 s** |
248
- | rails/rails | 3,551 | 52.55 s | **16.88 s** | 162.55 s | **63.97 s** |
249
- | ruby/ruby | 7,466 | 132.17 s | **43.10 s** | 199.78 s | **76.07 s** |
245
+ | Corpus | Files | Offenses | RuboCop parallel | Sonicop parallel | RuboCop single | Sonicop single |
246
+ |---|---:|---:|---:|---:|---:|---:|
247
+ | rubocop/rubocop | 1,780 | 5,826 | 10.85 s | **1.53 s** | 41.44 s | **8.96 s** |
248
+ | mastodon/mastodon | 3,292 | 15,293 | 22.59 s | **3.04 s** | 34.74 s | **6.86 s** |
249
+ | Homebrew/brew | 2,296 | 51,527 | 13.56 s | **2.21 s** | 40.36 s | **6.51 s** |
250
+ | rails/rails | 3,562 | 168,615 | 32.90 s | **8.84 s** | 85.71 s | **19.17 s** |
251
+ | ruby/ruby | 7,477 | 765,975 | 86.89 s | **15.59 s** | 193.59 s | **37.98 s** |
250
252
 
251
- The gap is 2.8x to 4.6x in parallel and 2.4x to 3.3x single-process, so no single corpus summarizes
253
+ The gap is 3.7x to 7.4x in parallel and 4.5x to 6.2x single-process, so no single corpus summarizes
252
254
  it. **Read the single-process column and treat the parallel one as indicative.** Measuring the same
253
255
  two binaries three times over a day put the single-process figures within 16% of each other every
254
256
  time, while the parallel ratio on RuboCop's own tree moved between 3.3x and 9.2x purely with what
255
257
  else the machine was doing. Single-process measures the engines; parallel measures the engines plus
256
258
  how well each one's scheduling happens to fit that tree on that run.
257
259
 
258
- The speed is not bought by skipping work: over those same 394 cops the two agree on **every offense**
259
- on RuboCop's own tree, on Rails and on Mastodon 188,812 offenses with nothing on either side of the
260
- ledger and autocorrect is byte-identical on the first and the last.
260
+ The speed is not bought by skipping work. Over those same 394 cops the two find the **same number of
261
+ offenses** on every corpus in the table, and on RuboCop's own tree and on Mastodon every one of them
262
+ is at the same position with the same message and severity. Rails, at 168,615 offenses, differs in
263
+ two of them — one `Style/CaseLikeIf` Sonicop reports and one `Metrics/AbcSize` it does not — and
264
+ RuboCop's own tree differs in one offense's `correctable` flag. Autocorrect is byte-identical on the
265
+ first and the last.
261
266
 
262
- Three details matter for reproducing this. RuboCop **silently turns `--parallel` off when combined
267
+ Four details matter for reproducing this. RuboCop **silently turns `--parallel` off when combined
263
268
  with `--cache false`**, so its parallel runs here use a cache directory that is deleted before each
264
269
  run rather than disabled; timing it with `--cache false --parallel` measures a single process and
265
270
  overstates the difference. RuboCop's default is a single process, while Sonicop is parallel unless
266
- `--no-parallel` is passed. And both sides need a **cold** cache: Sonicop caches by default too, so a
267
- second run over the same tree answers from its own cache and measures nothing about the engine.
268
- Give each tool a throwaway cache root.
271
+ `--no-parallel` is passed. Both sides need a **cold** cache: Sonicop caches by default too, so a
272
+ second run over the same tree answers from its own cache and measures nothing about the engine
273
+ give each tool a throwaway cache root. And the cache root must be a **real path**: macOS `mktemp -d`
274
+ returns `/var/folders/…`, whose `/var` is a symlink, and RuboCop refuses such a location and runs
275
+ with no cache at all.
269
276
 
270
277
  ```bash
271
278
  # RuboCop, parallel, cold cache, its full default set of 394 cops
272
- rubocop --force-default-config --cache true --cache-root "$(mktemp -d)" \
279
+ root=$(mktemp -d /private/tmp/bench.XXXXXX)
280
+ rubocop --force-default-config --cache true --cache-root "$root" \
273
281
  --no-color --parallel -f quiet
274
282
 
275
283
  # Sonicop, cold cache
276
- sonicop --force-default-config --cache-root "$(mktemp -d)" --format quiet
284
+ sonicop --force-default-config --cache-root "$root" --format quiet
277
285
  ```
278
286
 
287
+ Writing the cache is part of these numbers, and it is not free: the index holds every offense with
288
+ the source line it was found on, which is 336 MB over `ruby/ruby`. A second run against a warm cache
289
+ answers in 1.59 s there, and in 0.42 s over Rails.
290
+
279
291
  Machine: Apple M2 (8 cores), Ruby 4.0.6 with YJIT available, RubyGems-installed RuboCop 1.89.0.
280
- The one-minute load average was 4.0 when the run started and 3.1 when it finished — the machine was
281
- in use, not idle. RuboCop's own tree was re-measured on its own afterwards, at load 3.7 rising to 4.0,
282
- because the first pass over it ran while a release build was still finishing and its numbers came out
283
- 60% high; a row measured under a different load cannot sit in the same table as the others. Both tools
284
- ran under the same conditions, so the ratios hold, but the absolute
285
- seconds are not a floor: expect better on a quiet machine. Anything competing for cores inflates
286
- both sides, and not by the same factor on each, which is what makes the parallel column move as much
287
- as it does. If the absolute numbers matter to you, measure on an idle machine and record the load
288
- either side of the run — a figure without that context cannot be compared with another one.
292
+ Measured on 2026-08-31 against the corpora at `rubocop_rubocop` 2693129, `mastodon_mastodon` b59ddc7,
293
+ `Homebrew_brew` b42173b, `rails_rails` a19f07f and `ruby_ruby` 22e4a75. The one-minute load average
294
+ was between 4.5 and 7.1 as each row was taken most of it RuboCop's own parallel workers, which is
295
+ inherent to measuring them. **The machine was in use, not idle.** Both tools ran back to back under
296
+ the same conditions on each corpus, so the ratios hold, but the absolute seconds are not a floor:
297
+ expect better on a quiet machine. Anything competing for cores inflates both sides, and not by the
298
+ same factor on each, which is what makes the parallel column move as much as it does. If the
299
+ absolute numbers matter to you, measure on an idle machine and record the load either side of the
300
+ run — a figure without that context cannot be compared with another one.
289
301
 
290
302
  ## Development
291
303
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Generated from Cargo.toml by `rake version:sync`. Do not edit by hand.
4
4
  module Sonicop
5
- VERSION = '26.8.112'
5
+ VERSION = '26.8.113'
6
6
  end
@@ -8,6 +8,8 @@ use std::time::Duration;
8
8
  use anyhow::{Context, Result, bail};
9
9
  use serde_yaml_ng::{Mapping, Value};
10
10
 
11
+ const MAX_REMOTE_CONFIG_BYTES: u64 = 5 * 1024 * 1024;
12
+
11
13
  /// Configuration files whose inheritance has already been resolved, keyed by canonical path for
12
14
  /// local files and by URL for remote ones.
13
15
  ///
@@ -164,7 +166,8 @@ fn fetch_remote_config(url: &str) -> Result<String> {
164
166
  response
165
167
  .body_mut()
166
168
  .with_config()
167
- .limit(5 * 1024 * 1024)
169
+ // ureq は指定値と同じ長さでも上限超過にするため、論理上限を含む 1 バイト先を渡す。
170
+ .limit(MAX_REMOTE_CONFIG_BYTES + 1)
168
171
  .read_to_string()
169
172
  .with_context(|| format!("failed to read remote configuration: {url}"))
170
173
  }
@@ -459,14 +462,17 @@ fn mode_keys(mode: &Value, name: &str) -> HashSet<String> {
459
462
  mod tests {
460
463
  use std::collections::HashSet;
461
464
  use std::fs;
465
+ use std::io::{Read, Write};
466
+ use std::net::TcpListener;
462
467
  use std::path::Path;
468
+ use std::thread;
463
469
 
464
470
  use serde_yaml_ng::Value;
465
471
  use tempfile::tempdir;
466
472
 
467
473
  use super::{
468
- InheritMode, PARSED_CONFIG_COUNT, deep_merge, join_remote_url, load_with_inheritance,
469
- merge_config, merge_inherited_config,
474
+ InheritMode, MAX_REMOTE_CONFIG_BYTES, PARSED_CONFIG_COUNT, deep_merge, fetch_remote_config,
475
+ join_remote_url, load_with_inheritance, merge_config, merge_inherited_config,
470
476
  };
471
477
  use crate::config::Config;
472
478
 
@@ -483,6 +489,24 @@ mod tests {
483
489
  load_with_inheritance(path, &mut HashSet::new())
484
490
  }
485
491
 
492
+ fn serve_once(body: Vec<u8>) -> (String, thread::JoinHandle<()>) {
493
+ let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
494
+ let address = listener.local_addr().unwrap();
495
+ let server = thread::spawn(move || {
496
+ let (mut stream, _) = listener.accept().unwrap();
497
+ let mut request = [0; 1024];
498
+ assert_ne!(stream.read(&mut request).unwrap(), 0);
499
+ write!(
500
+ stream,
501
+ "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
502
+ body.len()
503
+ )
504
+ .unwrap();
505
+ stream.write_all(&body).unwrap();
506
+ });
507
+ (format!("http://{address}/config.yml"), server)
508
+ }
509
+
486
510
  fn cop_exclude(merged: &Value, cop: &str) -> Value {
487
511
  merged
488
512
  .as_mapping()
@@ -577,6 +601,24 @@ mod tests {
577
601
  assert!(join_remote_url("no-directory", "shared.yml").is_err());
578
602
  }
579
603
 
604
+ #[test]
605
+ fn remote_configuration_enforces_the_response_size_limit() {
606
+ let limit = MAX_REMOTE_CONFIG_BYTES as usize;
607
+
608
+ let (url, server) = serve_once(vec![b'a'; limit]);
609
+ let accepted = fetch_remote_config(&url).unwrap();
610
+ server.join().unwrap();
611
+ assert_eq!(accepted.len(), limit);
612
+
613
+ let (url, server) = serve_once(vec![b'a'; limit + 1]);
614
+ let error = fetch_remote_config(&url).unwrap_err().to_string();
615
+ server.join().unwrap();
616
+ assert!(
617
+ error.starts_with("failed to read remote configuration:"),
618
+ "unexpected error: {error}"
619
+ );
620
+ }
621
+
580
622
  #[test]
581
623
  fn merges_configurations_without_losing_untouched_keys() {
582
624
  let merged = merge_config(
data/src/engine.rs CHANGED
@@ -10,7 +10,6 @@ use ignore::WalkBuilder;
10
10
  use rayon::prelude::*;
11
11
  use serde::{Deserialize, Serialize};
12
12
  use tempfile::NamedTempFile;
13
- use tree_sitter::Parser;
14
13
 
15
14
  use crate::config::{Config, ConfigStore};
16
15
  use crate::cop_name::selector_matches;
@@ -554,7 +553,16 @@ fn persist_cache_index(path: &Path, index: &CacheIndex) -> bool {
554
553
  let Ok(mut temporary) = NamedTempFile::new_in(parent) else {
555
554
  return false;
556
555
  };
557
- if serde_json::to_writer(temporary.as_file_mut(), index).is_err()
556
+ // **Buffered.** `serde_json::to_writer` hands the writer each token as it produces it, so an
557
+ // unbuffered `File` turns one index into millions of `write` calls. The index holds every
558
+ // offense of every file with the source line it was found on, which is 336 MB over `ruby/ruby`:
559
+ // writing it a token at a time cost 115 seconds of a 135-second run, nearly all of it blocked
560
+ // in the kernel rather than serializing.
561
+ let written = {
562
+ let mut writer = std::io::BufWriter::with_capacity(1 << 20, temporary.as_file_mut());
563
+ serde_json::to_writer(&mut writer, index).is_ok() && writer.flush().is_ok()
564
+ };
565
+ if !written
558
566
  || temporary.as_file_mut().flush().is_err()
559
567
  || temporary.as_file().sync_all().is_err()
560
568
  {
@@ -992,12 +1000,8 @@ fn inspect_planned(
992
1000
  let length_as_read = text.len();
993
1001
  let text = crate::nul_bytes::as_ruby_reads_it(&text).unwrap_or(text);
994
1002
  let source = SourceFile::new(path, text).read_as_long_as(length_as_read);
995
- let mut parser = Parser::new();
996
- parser
997
- .set_language(&tree_sitter_ruby::LANGUAGE.into())
998
- .context("failed to initialize the Ruby parser")?;
999
1003
  let tree = crate::profile::phase(crate::profile::Phase::Parse, || {
1000
- parser.parse(source.text(), None)
1004
+ crate::parser::parse(source.text())
1001
1005
  })
1002
1006
  .context("Ruby parser returned no syntax tree")?;
1003
1007
  let ast = crate::profile::phase(crate::profile::Phase::Index, || {
data/src/lib.rs CHANGED
@@ -14,6 +14,7 @@ pub mod engine;
14
14
  mod formatter;
15
15
  mod magic_comment;
16
16
  mod nul_bytes;
17
+ mod parser;
17
18
  mod profile;
18
19
  mod ruby_version;
19
20
  pub mod rules;
data/src/nul_bytes.rs CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  use std::ops::Range;
25
25
 
26
- use tree_sitter::{Node, Parser};
26
+ use tree_sitter::Node;
27
27
 
28
28
  /// The byte a NUL inside a comment is read as.
29
29
  ///
@@ -144,11 +144,7 @@ thread_local! {
144
144
  fn parse(text: &str) -> Option<tree_sitter::Tree> {
145
145
  #[cfg(test)]
146
146
  PARSES.with(|parses| parses.set(parses.get() + 1));
147
- let mut parser = Parser::new();
148
- parser
149
- .set_language(&tree_sitter_ruby::LANGUAGE.into())
150
- .ok()?;
151
- parser.parse(text, None)
147
+ crate::parser::parse(text)
152
148
  }
153
149
 
154
150
  /// The nodes that hold the text of a literal. `%w` and `%i` wrap theirs in a `bare_string` or a
data/src/parser.rs ADDED
@@ -0,0 +1,37 @@
1
+ //! One Ruby parser per worker thread.
2
+ //!
3
+ //! `Parser::new` allocates the parse stack, the lexer buffers and the reusable subtree pool, and
4
+ //! `set_language` resets all of them. That is work the file being read has nothing to do with, and
5
+ //! several places used to repeat it for every file, every recovered fragment and every syntax
6
+ //! probe. A sampling profile put it among the costs of a run.
7
+ //!
8
+ //! The tree a parse returns owns its own storage, so nothing here is shared with the caller.
9
+
10
+ use std::cell::RefCell;
11
+
12
+ use tree_sitter::{Parser, Tree};
13
+
14
+ thread_local! {
15
+ static PARSER: RefCell<Option<Parser>> = const { RefCell::new(None) };
16
+ }
17
+
18
+ /// Parses `text` with this thread's parser, building one on first use.
19
+ ///
20
+ /// `None` means the parser produced no tree at all, which is not the same as a tree holding
21
+ /// errors: a source the grammar cannot read still comes back as a tree with `ERROR` nodes.
22
+ pub(crate) fn parse(text: &str) -> Option<Tree> {
23
+ PARSER.with(|slot| {
24
+ let mut slot = slot.borrow_mut();
25
+ let parser = match slot.as_mut() {
26
+ Some(parser) => parser,
27
+ None => {
28
+ let mut parser = Parser::new();
29
+ parser
30
+ .set_language(&tree_sitter_ruby::LANGUAGE.into())
31
+ .expect("the grammar the whole run is parsed with");
32
+ slot.insert(parser)
33
+ }
34
+ };
35
+ parser.parse(text, None)
36
+ })
37
+ }
data/src/profile.rs CHANGED
@@ -101,10 +101,18 @@ pub(crate) enum Phase {
101
101
  CacheKey,
102
102
  /// Reading a cached report back and turning it into offenses.
103
103
  CacheLoad,
104
+ /// `VariableForce`, built on the first cop of a file that asks for it.
105
+ Variables,
106
+ /// The code the grammar swallowed, recovered on the first cop that asks.
107
+ Fragments,
108
+ /// The Metrics cops' local-variable replay, built on the first cop that asks.
109
+ MetricLocals,
110
+ /// The lexer token stream, rebuilt on the first cop that asks.
111
+ LayoutTokens,
104
112
  }
105
113
 
106
114
  impl Phase {
107
- const COUNT: usize = 13;
115
+ const COUNT: usize = 17;
108
116
  const NAMES: [&'static str; Self::COUNT] = [
109
117
  "read",
110
118
  "parse",
@@ -119,6 +127,10 @@ impl Phase {
119
127
  "shebang",
120
128
  "cache_key",
121
129
  "cache_load",
130
+ "variables",
131
+ "fragments",
132
+ "metric_locals",
133
+ "layout_tokens",
122
134
  ];
123
135
  }
124
136
 
@@ -2,10 +2,11 @@ use tree_sitter::Node;
2
2
 
3
3
  use crate::diagnostic::Offense;
4
4
  use crate::rules::RuleContext;
5
- use crate::rules::send_node::{arguments, first_line_range, named_children, send_range};
5
+ use crate::rules::send_node::{arguments, first_line_range, send_range};
6
6
 
7
7
  use super::support::declarations;
8
8
  use crate::rules::node_ext::NodeExt;
9
+ use crate::rules::send_node::named_children_of;
9
10
 
10
11
  /// `SOURCE_BLOCK_NAMES`. A group declared under a different source, git remote, platform or path is
11
12
  /// a different group even when it goes by the same name.
@@ -71,7 +72,7 @@ fn attributes(node: Node<'_>, context: &RuleContext<'_>) -> String {
71
72
  // `group :a, foo: 1` and `group :a, foo: 1` agree however they were spaced.
72
73
  if parts.len() > 1 || parts[0].kind_str() == "hash" {
73
74
  let mut pairs: Vec<String> = match parts[0].kind_str() == "hash" {
74
- true => named_children(parts[0]),
75
+ true => named_children_of(parts[0], context),
75
76
  false => parts.to_vec(),
76
77
  }
77
78
  .into_iter()
@@ -7,10 +7,11 @@ use tree_sitter::Node;
7
7
  use crate::diagnostic::Offense;
8
8
  use crate::rules::RuleContext;
9
9
  use crate::rules::node_ext::NodeExt;
10
- use crate::rules::push_named_children;
10
+ use crate::rules::{push_named_children_in};
11
11
  use crate::rules::send_node::{arguments, is_string, pair_key_symbol, send_range, string_text};
12
12
 
13
13
  use super::support::gem_declarations;
14
+ use crate::rules::send_node::named_children_iter;
14
15
 
15
16
  const MSG: &str = "Missing gem description comment.";
16
17
 
@@ -179,7 +180,7 @@ fn subtree_lines(node: Node<'_>, context: &RuleContext<'_>) -> HashSet<usize> {
179
180
  continue;
180
181
  }
181
182
  lines.insert(context.source.line_column(current.start_byte()).0);
182
- push_named_children(current, &mut stack);
183
+ push_named_children_in(current, context, &mut stack);
183
184
  }
184
185
  lines
185
186
  }
@@ -224,8 +225,8 @@ fn gem_options<'a>(node: Node<'_>, context: &'a RuleContext<'_>) -> Vec<&'a str>
224
225
  };
225
226
  let pairs: Vec<Node<'_>> = match last.first().kind_str() {
226
227
  "hash" if last.parts().len() == 1 => {
227
- let mut cursor = last.first().walk();
228
- last.first().named_children(&mut cursor).collect()
228
+ let _cursor = last.first().walk();
229
+ named_children_iter(last.first(), context).collect()
229
230
  }
230
231
  _ => last.parts().to_vec(),
231
232
  };
@@ -3,9 +3,10 @@ use tree_sitter::Node;
3
3
  use crate::diagnostic::Offense;
4
4
  use crate::rules::RuleContext;
5
5
  use crate::rules::node_ext::NodeExt;
6
- use crate::rules::send_node::{is_plain_send, named_children};
6
+ use crate::rules::send_node::is_plain_send;
7
7
 
8
8
  use super::support::{first_specification_variable, is_literal, is_specification_receiver};
9
+ use crate::rules::send_node::named_children_of;
9
10
 
10
11
  pub(super) fn check(context: &RuleContext<'_>, offenses: &mut Vec<Offense>) {
11
12
  let variable = first_specification_variable(context);
@@ -34,7 +35,7 @@ pub(super) fn check(context: &RuleContext<'_>, offenses: &mut Vec<Offense>) {
34
35
  // multiple assignment carries no value of its own, so it never matches upstream's
35
36
  // `(send _ :[]= literal? _)`, which insists on both an index and a value.
36
37
  "left_assignment_list" => {
37
- for target in named_children(left) {
38
+ for target in named_children_of(left, context) {
38
39
  if target.kind_str() == "call"
39
40
  && let Some(attribute) = assigned_attribute(target, variable, context)
40
41
  {
@@ -93,7 +94,7 @@ fn indexed_attribute<'a>(
93
94
  if !is_specification_receiver(receiver, variable, context) {
94
95
  return None;
95
96
  }
96
- let indices = named_children(target);
97
+ let indices = named_children_of(target, context);
97
98
  let [index] = indices.get(1..)? else {
98
99
  return None;
99
100
  };