rubocop 0.8.3 → 0.9.0

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

Potentially problematic release.


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

Files changed (381) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -4
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +70 -1
  5. data/README.md +101 -11
  6. data/config/default.yml +10 -2
  7. data/config/enabled.yml +85 -11
  8. data/lib/rubocop.rb +97 -73
  9. data/lib/rubocop/cli.rb +177 -92
  10. data/lib/rubocop/config.rb +56 -11
  11. data/lib/rubocop/config_store.rb +2 -0
  12. data/lib/rubocop/cop/cop.rb +52 -8
  13. data/lib/rubocop/cop/lint/assignment_in_condition.rb +54 -0
  14. data/lib/rubocop/cop/lint/end_alignment.rb +180 -0
  15. data/lib/rubocop/cop/lint/end_in_method.rb +30 -0
  16. data/lib/rubocop/cop/lint/ensure_return.rb +22 -0
  17. data/lib/rubocop/cop/lint/eval.rb +22 -0
  18. data/lib/rubocop/cop/lint/handle_exceptions.rb +20 -0
  19. data/lib/rubocop/cop/lint/literal_in_condition.rb +63 -0
  20. data/lib/rubocop/cop/lint/loop.rb +29 -0
  21. data/lib/rubocop/cop/lint/rescue_exception.rb +29 -0
  22. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +33 -0
  23. data/lib/rubocop/cop/lint/unreachable_code.rb +35 -0
  24. data/lib/rubocop/cop/lint/unused_local_variable.rb +32 -0
  25. data/lib/rubocop/cop/lint/void.rb +58 -0
  26. data/lib/rubocop/cop/offence.rb +112 -12
  27. data/lib/rubocop/cop/rails/validation.rb +34 -0
  28. data/lib/rubocop/cop/style/access_control.rb +58 -0
  29. data/lib/rubocop/cop/style/alias.rb +28 -0
  30. data/lib/rubocop/cop/style/align_parameters.rb +39 -0
  31. data/lib/rubocop/cop/style/and_or.rb +45 -0
  32. data/lib/rubocop/cop/style/ascii_comments.rb +21 -0
  33. data/lib/rubocop/cop/style/ascii_identifiers.rb +22 -0
  34. data/lib/rubocop/cop/style/attr.rb +20 -0
  35. data/lib/rubocop/cop/style/avoid_class_vars.rb +20 -0
  36. data/lib/rubocop/cop/style/avoid_for.rb +18 -0
  37. data/lib/rubocop/cop/style/avoid_global_vars.rb +65 -0
  38. data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +21 -0
  39. data/lib/rubocop/cop/style/avoid_perlisms.rb +50 -0
  40. data/lib/rubocop/cop/style/begin_block.rb +18 -0
  41. data/lib/rubocop/cop/style/block_comments.rb +20 -0
  42. data/lib/rubocop/cop/style/block_nesting.rb +47 -0
  43. data/lib/rubocop/cop/style/blocks.rb +27 -0
  44. data/lib/rubocop/cop/style/case_equality.rb +22 -0
  45. data/lib/rubocop/cop/style/case_indentation.rb +28 -0
  46. data/lib/rubocop/cop/style/character_literal.rb +37 -0
  47. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +33 -0
  48. data/lib/rubocop/cop/style/class_methods.rb +22 -0
  49. data/lib/rubocop/cop/style/collection_methods.rb +37 -0
  50. data/lib/rubocop/cop/style/colon_method_call.rb +29 -0
  51. data/lib/rubocop/cop/style/constant_name.rb +31 -0
  52. data/lib/rubocop/cop/style/def_parentheses.rb +70 -0
  53. data/lib/rubocop/cop/style/documentation.rb +58 -0
  54. data/lib/rubocop/cop/style/dot_position.rb +25 -0
  55. data/lib/rubocop/cop/style/empty_line_between_defs.rb +26 -0
  56. data/lib/rubocop/cop/style/empty_lines.rb +40 -0
  57. data/lib/rubocop/cop/style/empty_literal.rb +53 -0
  58. data/lib/rubocop/cop/style/encoding.rb +29 -0
  59. data/lib/rubocop/cop/style/end_block.rb +18 -0
  60. data/lib/rubocop/cop/style/end_of_line.rb +23 -0
  61. data/lib/rubocop/cop/style/favor_join.rb +29 -0
  62. data/lib/rubocop/cop/style/favor_modifier.rb +118 -0
  63. data/lib/rubocop/cop/style/favor_sprintf.rb +28 -0
  64. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +54 -0
  65. data/lib/rubocop/cop/style/hash_syntax.rb +47 -0
  66. data/lib/rubocop/cop/style/if_then_else.rb +80 -0
  67. data/lib/rubocop/cop/style/lambda.rb +47 -0
  68. data/lib/rubocop/cop/style/leading_comment_space.rb +25 -0
  69. data/lib/rubocop/cop/style/line_continuation.rb +26 -0
  70. data/lib/rubocop/cop/style/line_length.rb +30 -0
  71. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +61 -0
  72. data/lib/rubocop/cop/style/method_call_parentheses.rb +22 -0
  73. data/lib/rubocop/cop/style/method_length.rb +57 -0
  74. data/lib/rubocop/cop/style/not.rb +24 -0
  75. data/lib/rubocop/cop/style/numeric_literals.rb +25 -0
  76. data/lib/rubocop/cop/{op_method.rb → style/op_method.rb} +4 -3
  77. data/lib/rubocop/cop/style/parameter_lists.rb +42 -0
  78. data/lib/rubocop/cop/style/parentheses_around_condition.rb +42 -0
  79. data/lib/rubocop/cop/style/proc.rb +30 -0
  80. data/lib/rubocop/cop/style/reduce_arguments.rb +34 -0
  81. data/lib/rubocop/cop/style/regexp_literal.rb +39 -0
  82. data/lib/rubocop/cop/style/rescue_modifier.rb +55 -0
  83. data/lib/rubocop/cop/style/semicolon.rb +51 -0
  84. data/lib/rubocop/cop/style/single_line_methods.rb +48 -0
  85. data/lib/rubocop/cop/style/space_after_comma_etc.rb +69 -0
  86. data/lib/rubocop/cop/style/space_after_control_keyword.rb +32 -0
  87. data/lib/rubocop/cop/style/string_literals.rb +36 -0
  88. data/lib/rubocop/cop/style/surrounding_space.rb +314 -0
  89. data/lib/rubocop/cop/style/symbol_array.rb +31 -0
  90. data/lib/rubocop/cop/style/symbol_name.rb +27 -0
  91. data/lib/rubocop/cop/style/tab.rb +25 -0
  92. data/lib/rubocop/cop/style/ternary_operator.rb +49 -0
  93. data/lib/rubocop/cop/style/trailing_whitespace.rb +24 -0
  94. data/lib/rubocop/cop/style/trivial_accessors.rb +32 -0
  95. data/lib/rubocop/cop/style/unless_else.rb +26 -0
  96. data/lib/rubocop/cop/style/variable_interpolation.rb +32 -0
  97. data/lib/rubocop/cop/style/when_then.rb +25 -0
  98. data/lib/rubocop/cop/style/while_until_do.rb +45 -0
  99. data/lib/rubocop/cop/style/word_array.rb +44 -0
  100. data/lib/rubocop/cop/util.rb +1 -0
  101. data/lib/rubocop/cop/variable_inspector.rb +280 -0
  102. data/lib/rubocop/formatter/base_formatter.rb +119 -0
  103. data/lib/rubocop/formatter/clang_style_formatter.rb +21 -0
  104. data/lib/rubocop/formatter/emacs_style_formatter.rb +17 -0
  105. data/lib/rubocop/formatter/formatter_set.rb +77 -0
  106. data/lib/rubocop/formatter/json_formatter.rb +76 -0
  107. data/lib/rubocop/formatter/progress_formatter.rb +63 -0
  108. data/lib/rubocop/formatter/simple_text_formatter.rb +62 -0
  109. data/lib/rubocop/version.rb +15 -1
  110. data/rubocop.gemspec +1 -2
  111. data/spec/.rubocop.yml +5 -0
  112. data/spec/project_spec.rb +4 -7
  113. data/spec/rubocop/cli_spec.rb +383 -146
  114. data/spec/rubocop/config_spec.rb +61 -0
  115. data/spec/rubocop/config_store_spec.rb +2 -2
  116. data/spec/rubocop/cops/cop_spec.rb +14 -7
  117. data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +111 -0
  118. data/spec/rubocop/cops/lint/end_alignment_spec.rb +426 -0
  119. data/spec/rubocop/cops/lint/end_in_method_spec.rb +35 -0
  120. data/spec/rubocop/cops/lint/ensure_return_spec.rb +37 -0
  121. data/spec/rubocop/cops/lint/eval_spec.rb +41 -0
  122. data/spec/rubocop/cops/lint/handle_exceptions_spec.rb +36 -0
  123. data/spec/rubocop/cops/lint/literal_in_condition_spec.rb +35 -0
  124. data/spec/rubocop/cops/lint/loop_spec.rb +33 -0
  125. data/spec/rubocop/cops/lint/rescue_exception_spec.rb +127 -0
  126. data/spec/rubocop/cops/lint/shadowing_outer_local_variable_spec.rb +180 -0
  127. data/spec/rubocop/cops/lint/unreachable_code_spec.rb +69 -0
  128. data/spec/rubocop/cops/lint/unused_local_variable_spec.rb +484 -0
  129. data/spec/rubocop/cops/lint/void_spec.rb +63 -0
  130. data/spec/rubocop/cops/offence_spec.rb +107 -10
  131. data/spec/rubocop/cops/rails/validation_spec.rb +27 -0
  132. data/spec/rubocop/cops/style/access_control_spec.rb +142 -0
  133. data/spec/rubocop/cops/style/alias_spec.rb +47 -0
  134. data/spec/rubocop/cops/style/align_parameters_spec.rb +199 -0
  135. data/spec/rubocop/cops/style/and_or_spec.rb +39 -0
  136. data/spec/rubocop/cops/style/ascii_comments_spec.rb +28 -0
  137. data/spec/rubocop/cops/style/ascii_identifiers_spec.rb +28 -0
  138. data/spec/rubocop/cops/style/attr_spec.rb +20 -0
  139. data/spec/rubocop/cops/style/avoid_class_vars_spec.rb +27 -0
  140. data/spec/rubocop/cops/style/avoid_for_spec.rb +37 -0
  141. data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +34 -0
  142. data/spec/rubocop/cops/style/avoid_perl_backrefs_spec.rb +20 -0
  143. data/spec/rubocop/cops/style/avoid_perlisms_spec.rb +47 -0
  144. data/spec/rubocop/cops/style/begin_block_spec.rb +19 -0
  145. data/spec/rubocop/cops/style/block_comments_spec.rb +27 -0
  146. data/spec/rubocop/cops/style/block_nesting_spec.rb +159 -0
  147. data/spec/rubocop/cops/style/blocks_spec.rb +35 -0
  148. data/spec/rubocop/cops/style/case_equality_spec.rb +18 -0
  149. data/spec/rubocop/cops/style/case_indentation_spec.rb +88 -0
  150. data/spec/rubocop/cops/style/character_literal_spec.rb +28 -0
  151. data/spec/rubocop/cops/style/class_and_module_camel_case_spec.rb +46 -0
  152. data/spec/rubocop/cops/style/class_methods_spec.rb +51 -0
  153. data/spec/rubocop/cops/style/collection_methods_spec.rb +46 -0
  154. data/spec/rubocop/cops/style/colon_method_call_spec.rb +55 -0
  155. data/spec/rubocop/cops/style/constant_name_spec.rb +56 -0
  156. data/spec/rubocop/cops/style/def_with_parentheses_spec.rb +40 -0
  157. data/spec/rubocop/cops/style/def_without_parentheses_spec.rb +34 -0
  158. data/spec/rubocop/cops/style/documentation_spec.rb +79 -0
  159. data/spec/rubocop/cops/style/dot_position_spec.rb +30 -0
  160. data/spec/rubocop/cops/style/empty_line_between_defs_spec.rb +85 -0
  161. data/spec/rubocop/cops/style/empty_lines_spec.rb +40 -0
  162. data/spec/rubocop/cops/style/empty_literal_spec.rb +91 -0
  163. data/spec/rubocop/cops/style/encoding_spec.rb +49 -0
  164. data/spec/rubocop/cops/style/end_block_spec.rb +19 -0
  165. data/spec/rubocop/cops/style/end_of_line_spec.rb +25 -0
  166. data/spec/rubocop/cops/style/favor_join_spec.rb +37 -0
  167. data/spec/rubocop/cops/style/favor_modifier_spec.rb +160 -0
  168. data/spec/rubocop/cops/style/favor_sprintf_spec.rb +53 -0
  169. data/spec/rubocop/cops/style/favor_unless_over_negated_if_spec.rb +64 -0
  170. data/spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb +47 -0
  171. data/spec/rubocop/cops/style/hash_syntax_spec.rb +51 -0
  172. data/spec/rubocop/cops/style/if_with_semicolon_spec.rb +25 -0
  173. data/spec/rubocop/cops/style/lambda_spec.rb +45 -0
  174. data/spec/rubocop/cops/style/leading_comment_space_spec.rb +65 -0
  175. data/spec/rubocop/cops/style/line_continuation_spec.rb +26 -0
  176. data/spec/rubocop/cops/style/line_length_spec.rb +25 -0
  177. data/spec/rubocop/cops/style/method_and_variable_snake_case_spec.rb +95 -0
  178. data/spec/rubocop/cops/style/method_call_parentheses_spec.rb +25 -0
  179. data/spec/rubocop/cops/style/method_length_spec.rb +151 -0
  180. data/spec/rubocop/cops/style/multiline_if_then_spec.rb +81 -0
  181. data/spec/rubocop/cops/style/not_spec.rb +28 -0
  182. data/spec/rubocop/cops/style/numeric_literals_spec.rb +51 -0
  183. data/spec/rubocop/cops/style/one_line_conditional_spec.rb +18 -0
  184. data/spec/rubocop/cops/style/op_method_spec.rb +80 -0
  185. data/spec/rubocop/cops/style/parameter_lists_spec.rb +49 -0
  186. data/spec/rubocop/cops/style/parentheses_around_condition_spec.rb +59 -0
  187. data/spec/rubocop/cops/style/proc_spec.rb +28 -0
  188. data/spec/rubocop/cops/style/reduce_arguments_spec.rb +59 -0
  189. data/spec/rubocop/cops/style/regexp_literal_spec.rb +83 -0
  190. data/spec/rubocop/cops/style/rescue_modifier_spec.rb +122 -0
  191. data/spec/rubocop/cops/style/semicolon_spec.rb +95 -0
  192. data/spec/rubocop/cops/style/single_line_methods_spec.rb +54 -0
  193. data/spec/rubocop/cops/style/space_after_colon_spec.rb +29 -0
  194. data/spec/rubocop/cops/style/space_after_comma_spec.rb +31 -0
  195. data/spec/rubocop/cops/style/space_after_control_keyword_spec.rb +69 -0
  196. data/spec/rubocop/cops/style/space_after_semicolon_spec.rb +24 -0
  197. data/spec/rubocop/cops/style/space_around_braces_spec.rb +49 -0
  198. data/spec/rubocop/cops/style/space_around_equals_in_default_parameter_spec.rb +34 -0
  199. data/spec/rubocop/cops/style/space_around_operators_spec.rb +216 -0
  200. data/spec/rubocop/cops/style/space_inside_brackets_spec.rb +51 -0
  201. data/spec/rubocop/cops/style/space_inside_hash_literal_braces_spec.rb +99 -0
  202. data/spec/rubocop/cops/style/space_inside_parens_spec.rb +33 -0
  203. data/spec/rubocop/cops/style/string_literals_spec.rb +62 -0
  204. data/spec/rubocop/cops/style/symbol_array_spec.rb +45 -0
  205. data/spec/rubocop/cops/style/symbol_name_spec.rb +122 -0
  206. data/spec/rubocop/cops/style/tab_spec.rb +23 -0
  207. data/spec/rubocop/cops/style/ternary_operator_spec.rb +42 -0
  208. data/spec/rubocop/cops/style/trailing_whitespace_spec.rb +29 -0
  209. data/spec/rubocop/cops/style/trivial_accessors_spec.rb +338 -0
  210. data/spec/rubocop/cops/style/unless_else_spec.rb +31 -0
  211. data/spec/rubocop/cops/style/variable_interpolation_spec.rb +53 -0
  212. data/spec/rubocop/cops/style/when_then_spec.rb +40 -0
  213. data/spec/rubocop/cops/style/while_until_do_spec.rb +47 -0
  214. data/spec/rubocop/cops/style/word_array_spec.rb +61 -0
  215. data/spec/rubocop/cops/variable_inspector_spec.rb +374 -0
  216. data/spec/rubocop/formatter/base_formatter_spec.rb +190 -0
  217. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +70 -0
  218. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +32 -0
  219. data/spec/rubocop/formatter/formatter_set_spec.rb +132 -0
  220. data/spec/rubocop/formatter/json_formatter_spec.rb +142 -0
  221. data/spec/rubocop/formatter/progress_formatter_spec.rb +196 -0
  222. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +74 -0
  223. data/spec/spec_helper.rb +23 -8
  224. data/spec/support/mri_syntax_checker.rb +69 -0
  225. data/spec/support/shared_examples.rb +33 -0
  226. metadata +315 -243
  227. data/lib/rubocop/cop/access_control.rb +0 -41
  228. data/lib/rubocop/cop/alias.rb +0 -17
  229. data/lib/rubocop/cop/align_parameters.rb +0 -37
  230. data/lib/rubocop/cop/and_or.rb +0 -36
  231. data/lib/rubocop/cop/ascii_comments.rb +0 -17
  232. data/lib/rubocop/cop/ascii_identifiers.rb +0 -19
  233. data/lib/rubocop/cop/avoid_class_vars.rb +0 -15
  234. data/lib/rubocop/cop/avoid_for.rb +0 -17
  235. data/lib/rubocop/cop/avoid_global_vars.rb +0 -61
  236. data/lib/rubocop/cop/avoid_perl_backrefs.rb +0 -17
  237. data/lib/rubocop/cop/avoid_perlisms.rb +0 -47
  238. data/lib/rubocop/cop/block_comments.rb +0 -17
  239. data/lib/rubocop/cop/block_nesting.rb +0 -35
  240. data/lib/rubocop/cop/blocks.rb +0 -23
  241. data/lib/rubocop/cop/case_indentation.rb +0 -22
  242. data/lib/rubocop/cop/class_and_module_camel_case.rb +0 -29
  243. data/lib/rubocop/cop/class_methods.rb +0 -15
  244. data/lib/rubocop/cop/collection_methods.rb +0 -29
  245. data/lib/rubocop/cop/colon_method_call.rb +0 -20
  246. data/lib/rubocop/cop/constant_name.rb +0 -24
  247. data/lib/rubocop/cop/def_parentheses.rb +0 -62
  248. data/lib/rubocop/cop/empty_line_between_defs.rb +0 -22
  249. data/lib/rubocop/cop/empty_lines.rb +0 -34
  250. data/lib/rubocop/cop/empty_literal.rb +0 -49
  251. data/lib/rubocop/cop/encoding.rb +0 -19
  252. data/lib/rubocop/cop/end_of_line.rb +0 -15
  253. data/lib/rubocop/cop/ensure_return.rb +0 -19
  254. data/lib/rubocop/cop/eval.rb +0 -19
  255. data/lib/rubocop/cop/favor_join.rb +0 -22
  256. data/lib/rubocop/cop/favor_modifier.rb +0 -92
  257. data/lib/rubocop/cop/favor_percent_r.rb +0 -19
  258. data/lib/rubocop/cop/favor_sprintf.rb +0 -21
  259. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +0 -49
  260. data/lib/rubocop/cop/handle_exceptions.rb +0 -17
  261. data/lib/rubocop/cop/hash_syntax.rb +0 -41
  262. data/lib/rubocop/cop/if_then_else.rb +0 -75
  263. data/lib/rubocop/cop/lambda.rb +0 -42
  264. data/lib/rubocop/cop/leading_comment_space.rb +0 -19
  265. data/lib/rubocop/cop/line_continuation.rb +0 -15
  266. data/lib/rubocop/cop/line_length.rb +0 -23
  267. data/lib/rubocop/cop/loop.rb +0 -33
  268. data/lib/rubocop/cop/method_and_variable_snake_case.rb +0 -55
  269. data/lib/rubocop/cop/method_length.rb +0 -52
  270. data/lib/rubocop/cop/not.rb +0 -21
  271. data/lib/rubocop/cop/numeric_literals.rb +0 -21
  272. data/lib/rubocop/cop/parameter_lists.rb +0 -23
  273. data/lib/rubocop/cop/parentheses_around_condition.rb +0 -40
  274. data/lib/rubocop/cop/percent_r.rb +0 -19
  275. data/lib/rubocop/cop/proc.rb +0 -26
  276. data/lib/rubocop/cop/reduce_arguments.rb +0 -29
  277. data/lib/rubocop/cop/rescue_exception.rb +0 -26
  278. data/lib/rubocop/cop/rescue_modifier.rb +0 -15
  279. data/lib/rubocop/cop/semicolon.rb +0 -31
  280. data/lib/rubocop/cop/single_line_methods.rb +0 -44
  281. data/lib/rubocop/cop/space_after_comma_etc.rb +0 -62
  282. data/lib/rubocop/cop/space_after_control_keyword.rb +0 -29
  283. data/lib/rubocop/cop/string_literals.rb +0 -25
  284. data/lib/rubocop/cop/surrounding_space.rb +0 -285
  285. data/lib/rubocop/cop/symbol_array.rb +0 -31
  286. data/lib/rubocop/cop/symbol_name.rb +0 -23
  287. data/lib/rubocop/cop/syntax.rb +0 -49
  288. data/lib/rubocop/cop/tab.rb +0 -15
  289. data/lib/rubocop/cop/ternary_operator.rb +0 -43
  290. data/lib/rubocop/cop/trailing_whitespace.rb +0 -15
  291. data/lib/rubocop/cop/trivial_accessors.rb +0 -26
  292. data/lib/rubocop/cop/unless_else.rb +0 -23
  293. data/lib/rubocop/cop/variable_interpolation.rb +0 -29
  294. data/lib/rubocop/cop/when_then.rb +0 -17
  295. data/lib/rubocop/cop/word_array.rb +0 -37
  296. data/lib/rubocop/report/emacs_style.rb +0 -17
  297. data/lib/rubocop/report/plain_text.rb +0 -18
  298. data/lib/rubocop/report/report.rb +0 -44
  299. data/spec/rubocop/cops/access_control_spec.rb +0 -129
  300. data/spec/rubocop/cops/alias_spec.rb +0 -39
  301. data/spec/rubocop/cops/align_parameters_spec.rb +0 -197
  302. data/spec/rubocop/cops/and_or_spec.rb +0 -37
  303. data/spec/rubocop/cops/ascii_comments_spec.rb +0 -26
  304. data/spec/rubocop/cops/ascii_identifiers_spec.rb +0 -26
  305. data/spec/rubocop/cops/avoid_class_vars_spec.rb +0 -25
  306. data/spec/rubocop/cops/avoid_for_spec.rb +0 -35
  307. data/spec/rubocop/cops/avoid_global_vars_spec.rb +0 -32
  308. data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +0 -18
  309. data/spec/rubocop/cops/avoid_perlisms_spec.rb +0 -44
  310. data/spec/rubocop/cops/block_comments_spec.rb +0 -25
  311. data/spec/rubocop/cops/block_nesting_spec.rb +0 -148
  312. data/spec/rubocop/cops/blocks_spec.rb +0 -33
  313. data/spec/rubocop/cops/case_indentation_spec.rb +0 -86
  314. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +0 -44
  315. data/spec/rubocop/cops/class_methods_spec.rb +0 -49
  316. data/spec/rubocop/cops/collection_methods_spec.rb +0 -44
  317. data/spec/rubocop/cops/colon_method_call_spec.rb +0 -53
  318. data/spec/rubocop/cops/constant_name_spec.rb +0 -42
  319. data/spec/rubocop/cops/def_with_parentheses_spec.rb +0 -38
  320. data/spec/rubocop/cops/def_without_parentheses_spec.rb +0 -32
  321. data/spec/rubocop/cops/empty_line_between_defs_spec.rb +0 -83
  322. data/spec/rubocop/cops/empty_lines_spec.rb +0 -38
  323. data/spec/rubocop/cops/empty_literal_spec.rb +0 -90
  324. data/spec/rubocop/cops/encoding_spec.rb +0 -47
  325. data/spec/rubocop/cops/end_of_line_spec.rb +0 -23
  326. data/spec/rubocop/cops/ensure_return_spec.rb +0 -35
  327. data/spec/rubocop/cops/eval_spec.rb +0 -39
  328. data/spec/rubocop/cops/favor_join_spec.rb +0 -35
  329. data/spec/rubocop/cops/favor_modifier_spec.rb +0 -146
  330. data/spec/rubocop/cops/favor_percent_r_spec.rb +0 -29
  331. data/spec/rubocop/cops/favor_sprintf_spec.rb +0 -51
  332. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +0 -62
  333. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +0 -45
  334. data/spec/rubocop/cops/handle_exceptions_spec.rb +0 -34
  335. data/spec/rubocop/cops/hash_syntax_spec.rb +0 -49
  336. data/spec/rubocop/cops/if_with_semicolon_spec.rb +0 -23
  337. data/spec/rubocop/cops/lambda_spec.rb +0 -43
  338. data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -54
  339. data/spec/rubocop/cops/line_continuation_spec.rb +0 -24
  340. data/spec/rubocop/cops/line_length_spec.rb +0 -23
  341. data/spec/rubocop/cops/loop_spec.rb +0 -31
  342. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +0 -93
  343. data/spec/rubocop/cops/method_length_spec.rb +0 -147
  344. data/spec/rubocop/cops/multiline_if_then_spec.rb +0 -79
  345. data/spec/rubocop/cops/not_spec.rb +0 -26
  346. data/spec/rubocop/cops/numeric_literals_spec.rb +0 -49
  347. data/spec/rubocop/cops/one_line_conditional_spec.rb +0 -16
  348. data/spec/rubocop/cops/op_method_spec.rb +0 -78
  349. data/spec/rubocop/cops/parameter_lists_spec.rb +0 -24
  350. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +0 -61
  351. data/spec/rubocop/cops/percent_r_spec.rb +0 -29
  352. data/spec/rubocop/cops/proc_spec.rb +0 -26
  353. data/spec/rubocop/cops/reduce_arguments_spec.rb +0 -57
  354. data/spec/rubocop/cops/rescue_exception_spec.rb +0 -125
  355. data/spec/rubocop/cops/rescue_modifier_spec.rb +0 -37
  356. data/spec/rubocop/cops/semicolon_spec.rb +0 -88
  357. data/spec/rubocop/cops/single_line_methods_spec.rb +0 -50
  358. data/spec/rubocop/cops/space_after_colon_spec.rb +0 -27
  359. data/spec/rubocop/cops/space_after_comma_spec.rb +0 -29
  360. data/spec/rubocop/cops/space_after_control_keyword_spec.rb +0 -67
  361. data/spec/rubocop/cops/space_after_semicolon_spec.rb +0 -22
  362. data/spec/rubocop/cops/space_around_braces_spec.rb +0 -47
  363. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +0 -32
  364. data/spec/rubocop/cops/space_around_operators_spec.rb +0 -209
  365. data/spec/rubocop/cops/space_inside_brackets_spec.rb +0 -49
  366. data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +0 -86
  367. data/spec/rubocop/cops/space_inside_parens_spec.rb +0 -31
  368. data/spec/rubocop/cops/string_literals_spec.rb +0 -58
  369. data/spec/rubocop/cops/symbol_array_spec.rb +0 -41
  370. data/spec/rubocop/cops/symbol_name_spec.rb +0 -119
  371. data/spec/rubocop/cops/syntax_spec.rb +0 -41
  372. data/spec/rubocop/cops/tab_spec.rb +0 -21
  373. data/spec/rubocop/cops/ternary_operator_spec.rb +0 -40
  374. data/spec/rubocop/cops/trailing_whitespace_spec.rb +0 -27
  375. data/spec/rubocop/cops/trivial_accessors_spec.rb +0 -337
  376. data/spec/rubocop/cops/unless_else_spec.rb +0 -29
  377. data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -49
  378. data/spec/rubocop/cops/when_then_spec.rb +0 -38
  379. data/spec/rubocop/cops/word_array_spec.rb +0 -47
  380. data/spec/rubocop/reports/emacs_style_spec.rb +0 -25
  381. data/spec/rubocop/reports/report_spec.rb +0 -29
@@ -6,6 +6,8 @@ module Rubocop
6
6
  # The CLI is a class responsible of handling all the command line interface
7
7
  # logic.
8
8
  class CLI
9
+ DEFAULT_FORMATTER = 'progress'
10
+
9
11
  # If set true while running,
10
12
  # RuboCop will abort processing and exit gracefully.
11
13
  attr_accessor :wants_to_quit
@@ -15,10 +17,8 @@ module Rubocop
15
17
 
16
18
  def initialize
17
19
  @cops = Cop::Cop.all
18
- @processed_file_count = 0
19
- @total_offences = 0
20
20
  @errors = []
21
- @options = { mode: :default }
21
+ @options = {}
22
22
  ConfigStore.prepare
23
23
  end
24
24
 
@@ -29,45 +29,42 @@ module Rubocop
29
29
  def run(args = ARGV)
30
30
  trap_interrupt
31
31
 
32
- parse_options(args)
33
-
34
32
  begin
35
- validate_only_option if @options[:only]
36
- rescue ArgumentError => e
37
- puts e.message
33
+ parse_options(args)
34
+ rescue => e
35
+ $stderr.puts e.message
38
36
  return 1
39
37
  end
40
38
 
41
- target_files(args).each do |file|
42
- break if wants_to_quit?
39
+ # filter out Rails cops unless requested
40
+ @cops.reject! { |cop_klass| cop_klass.rails? } unless @options[:rails]
43
41
 
44
- config = ConfigStore.for(file)
45
- report = Report.create(file, @options[:mode])
42
+ target_files = target_files(args)
43
+ target_files.each(&:freeze).freeze
44
+ inspected_files = []
45
+ any_failed = false
46
46
 
47
- puts "Scanning #{file}" if @options[:debug]
47
+ formatter_set.started(target_files)
48
48
 
49
- syntax_cop = Rubocop::Cop::Syntax.new
50
- syntax_cop.debug = @options[:debug]
51
- syntax_cop.inspect_file(file)
49
+ target_files.each do |file|
50
+ break if wants_to_quit?
52
51
 
53
- # In case of a syntax error we just report that error and do
54
- # no more checking in the file.
55
- unless syntax_cop.offences.map(&:severity).include?(:error)
56
- inspect_file(file, config, report)
57
- end
52
+ puts "Scanning #{file}" if @options[:debug]
53
+ formatter_set.file_started(file, {})
58
54
 
59
- report << syntax_cop
60
- @total_offences += syntax_cop.offences.count
55
+ offences = inspect_file(file)
61
56
 
62
- @processed_file_count += 1
63
- report.display unless report.empty?
57
+ any_failed = true unless offences.empty?
58
+ inspected_files << file
59
+ formatter_set.file_finished(file, offences.freeze)
64
60
  end
65
61
 
66
- unless @options[:silent]
67
- display_summary(@processed_file_count, @total_offences, @errors)
68
- end
62
+ formatter_set.finished(inspected_files.freeze)
63
+ formatter_set.close_output_files
69
64
 
70
- (@total_offences == 0) && !wants_to_quit ? 0 : 1
65
+ display_error_summary(@errors) unless @options[:silent]
66
+
67
+ !any_failed && !wants_to_quit ? 0 : 1
71
68
  end
72
69
 
73
70
  def validate_only_option
@@ -76,44 +73,56 @@ module Rubocop
76
73
  end
77
74
  end
78
75
 
79
- def inspect_file(file, config, report)
76
+ def inspect_file(file)
80
77
  begin
81
- ast, comments, tokens, source = CLI.parse(file) do |source_buffer|
82
- source_buffer.read
83
- end
84
- rescue Parser::SyntaxError, Encoding::UndefinedConversionError,
85
- ArgumentError => e
78
+ ast, comments, tokens, source_buffer, source, syntax_offences =
79
+ CLI.parse(file) { |sb| sb.read }
80
+
81
+ rescue Encoding::UndefinedConversionError, ArgumentError => e
86
82
  handle_error(e, "An error occurred while parsing #{file}.".color(:red))
87
- return
83
+ return []
88
84
  end
89
85
 
86
+ # If we got any syntax errors, return only the syntax offences.
87
+ # Parser may return nil for AST even though there are no syntax errors.
88
+ # e.g. sources which contain only comments
89
+ return syntax_offences unless syntax_offences.empty?
90
+
91
+ config = ConfigStore.for(file)
90
92
  disabled_lines = disabled_lines_in(source)
91
93
 
92
- @cops.each do |cop_class|
94
+ set_config_for_all_cops(config)
95
+
96
+ @cops.reduce([]) do |offences, cop_class|
93
97
  cop_name = cop_class.cop_name
94
- cop_class.config = config.for_cop(cop_name)
95
98
  if config.cop_enabled?(cop_name)
96
- cop = setup_cop(cop_class,
97
- disabled_lines)
99
+ cop = setup_cop(cop_class, disabled_lines)
98
100
  if !@options[:only] || @options[:only] == cop_name
99
101
  begin
100
- cop.inspect(source, tokens, ast, comments)
102
+ cop.inspect(source_buffer, source, tokens, ast, comments)
101
103
  rescue => e
102
104
  handle_error(e,
103
105
  "An error occurred while #{cop.name}".color(:red) +
104
106
  " cop was inspecting #{file}.".color(:red))
105
107
  end
106
108
  end
107
- @total_offences += cop.offences.count
108
- report << cop if cop.has_report?
109
+ offences.concat(cop.offences)
109
110
  end
111
+ offences
112
+ end.sort
113
+ end
114
+
115
+ def set_config_for_all_cops(config)
116
+ @cops.each do |cop_class|
117
+ cop_class.config = config.for_cop(cop_class.cop_name)
110
118
  end
111
119
  end
112
120
 
113
- def setup_cop(cop_class, disabled_lines)
121
+ def setup_cop(cop_class, disabled_lines = nil)
114
122
  cop = cop_class.new
115
123
  cop.debug = @options[:debug]
116
- cop.disabled_lines = disabled_lines[cop_class.cop_name]
124
+ cop.autocorrect = @options[:autocorrect]
125
+ cop.disabled_lines = disabled_lines[cop_class.cop_name] if disabled_lines
117
126
  cop
118
127
  end
119
128
 
@@ -127,35 +136,83 @@ module Rubocop
127
136
  end
128
137
  end
129
138
 
139
+ # rubocop:disable MethodLength
130
140
  def parse_options(args)
141
+ convert_deprecated_options!(args)
142
+
131
143
  OptionParser.new do |opts|
132
144
  opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'
133
145
 
134
- opts.on('-d', '--debug', 'Display debug info') do |d|
146
+ opts.on('-d', '--debug', 'Display debug info.') do |d|
135
147
  @options[:debug] = d
136
148
  end
137
- opts.on('-e', '--emacs', 'Emacs style output') do
138
- @options[:mode] = :emacs_style
139
- end
140
- opts.on('-c FILE', '--config FILE', 'Configuration file') do |f|
149
+ opts.on('-c', '--config FILE', 'Specify configuration file.') do |f|
141
150
  @options[:config] = f
142
151
  ConfigStore.set_options_config(@options[:config])
143
152
  end
144
- opts.on('--only COP', 'Run just one cop') do |s|
153
+ opts.on('--only COP', 'Run just one cop.') do |s|
145
154
  @options[:only] = s
155
+ validate_only_option
156
+ end
157
+ opts.on('-f', '--format FORMATTER',
158
+ 'Choose an output formatter. This option',
159
+ 'can be specified multiple times to enable',
160
+ 'multiple formatters at the same time.',
161
+ ' [p]rogress (default)',
162
+ ' [s]imple',
163
+ ' [c]lang',
164
+ ' [e]macs',
165
+ ' [j]son',
166
+ ' custom formatter class name') do |key|
167
+ @options[:formatters] ||= []
168
+ @options[:formatters] << [key]
169
+ end
170
+ opts.on('-o', '--out FILE',
171
+ 'Write output to a file instead of STDOUT.',
172
+ 'This option applies to the previously',
173
+ 'specified --format, or the default format',
174
+ 'if no format is specified.') do |path|
175
+ @options[:formatters] ||= [[DEFAULT_FORMATTER]]
176
+ @options[:formatters].last << path
177
+ end
178
+ opts.on('-r', '--require FILE', 'Require Ruby file.') do |f|
179
+ require f
180
+ end
181
+ opts.on('-R', '--rails', 'Run extra Rails cops.') do |r|
182
+ @options[:rails] = r
146
183
  end
147
- opts.on('-s', '--silent', 'Silence summary') do |s|
184
+ opts.on('-a', '--auto-correct', 'Auto-correct offences.') do |a|
185
+ @options[:autocorrect] = a
186
+ end
187
+ opts.on('-s', '--silent', 'Silence summary.') do |s|
148
188
  @options[:silent] = s
149
189
  end
150
- opts.on('-n', '--no-color', 'Disable color output') do |s|
190
+ opts.on('-n', '--no-color', 'Disable color output.') do |s|
151
191
  Sickill::Rainbow.enabled = false
152
192
  end
153
- opts.on('-v', '--version', 'Display version') do
154
- puts Rubocop::Version::STRING
193
+ opts.on('-v', '--version', 'Display version.') do
194
+ puts Rubocop::Version.version(false)
195
+ exit(0)
196
+ end
197
+ opts.on('-V', '--verbose-version', 'Display verbose version.') do
198
+ puts Rubocop::Version.version(true)
155
199
  exit(0)
156
200
  end
157
201
  end.parse!(args)
158
202
  end
203
+ # rubocop:enable MethodLength
204
+
205
+ def convert_deprecated_options!(args)
206
+ args.map! do |arg|
207
+ case arg
208
+ when '-e', '--emacs'
209
+ deprecate("#{arg} option", '--format emacs', '1.0.0')
210
+ %w(--format emacs)
211
+ else
212
+ arg
213
+ end
214
+ end.flatten!
215
+ end
159
216
 
160
217
  def trap_interrupt
161
218
  Signal.trap('INT') do
@@ -166,26 +223,15 @@ module Rubocop
166
223
  end
167
224
  end
168
225
 
169
- def display_summary(num_files, total_offences, errors)
170
- plural = num_files == 0 || num_files > 1 ? 's' : ''
171
- print "\n#{num_files} file#{plural} inspected, "
172
- offences_string = if total_offences.zero?
173
- 'no offences'
174
- elsif total_offences == 1
175
- '1 offence'
176
- else
177
- "#{total_offences} offences"
178
- end
179
- puts "#{offences_string} detected"
180
- .color(total_offences.zero? ? :green : :red)
181
-
182
- if errors.count > 0
183
- plural = errors.count > 1 ? 's' : ''
184
- puts "\n#{errors.count} error#{plural} occurred:".color(:red)
185
- errors.each { |error| puts error }
186
- puts 'Errors are usually caused by RuboCop bugs.'
187
- puts 'Please, report your problems to RuboCop\'s issue tracker.'
188
- end
226
+ def display_error_summary(errors)
227
+ return if errors.empty?
228
+ plural = errors.count > 1 ? 's' : ''
229
+ puts "\n#{errors.count} error#{plural} occurred:".color(:red)
230
+ errors.each { |error| puts error }
231
+ puts 'Errors are usually caused by RuboCop bugs.'
232
+ puts 'Please, report your problems to RuboCop\'s issue tracker.'
233
+ puts 'Mention the following information in the issue report:'
234
+ puts Rubocop::Version.version(true)
189
235
  end
190
236
 
191
237
  def disabled_lines_in(source)
@@ -222,25 +268,41 @@ module Rubocop
222
268
  def self.parse(file)
223
269
  parser = Parser::CurrentRuby.new
224
270
 
225
- parser.diagnostics.all_errors_are_fatal = true
226
- parser.diagnostics.ignore_warnings = true
271
+ # On JRuby and Rubinius, there's a risk that we hang in
272
+ # tokenize() if we don't set the all errors as fatal flag.
273
+ parser.diagnostics.all_errors_are_fatal = RUBY_ENGINE != 'ruby'
274
+ parser.diagnostics.ignore_warnings = false
227
275
 
276
+ diagnostics = []
228
277
  parser.diagnostics.consumer = lambda do |diagnostic|
229
- $stderr.puts(diagnostic.render)
278
+ diagnostics << diagnostic
230
279
  end
231
280
 
232
281
  source_buffer = Parser::Source::Buffer.new(file, 1)
233
282
  yield source_buffer
234
283
 
235
- ast, comments, tokens = parser.tokenize(source_buffer)
284
+ begin
285
+ ast, comments, tokens = parser.tokenize(source_buffer)
286
+ rescue Parser::SyntaxError # rubocop:disable HandleExceptions
287
+ # All errors are in diagnostics. No need to handle exception.
288
+ end
289
+
290
+ if tokens
291
+ tokens = tokens.map do |t|
292
+ type, details = *t
293
+ text, range = *details
294
+ Rubocop::Cop::Token.new(range, type, text)
295
+ end
296
+ end
236
297
 
237
- tokens = tokens.map do |t|
238
- type, details = *t
239
- text, range = *details
240
- Rubocop::Cop::Token.new(range, type, text)
298
+ syntax_offences = diagnostics.map do |d|
299
+ Cop::Offence.new(d.level, d.location, "#{d.message}",
300
+ 'Syntax')
241
301
  end
242
302
 
243
- [ast, comments, tokens, source_buffer.source.split($RS)]
303
+ source = source_buffer.source.split($RS)
304
+
305
+ [ast, comments, tokens, source_buffer, source, syntax_offences]
244
306
  end
245
307
 
246
308
  # Generate a list of target files by expanding globing patterns
@@ -262,7 +324,7 @@ module Rubocop
262
324
  end
263
325
  end
264
326
 
265
- files.uniq
327
+ files.map { |f| File.expand_path(f) }.uniq
266
328
  end
267
329
 
268
330
  # Finds all Ruby source files under the current or other supplied
@@ -274,13 +336,13 @@ module Rubocop
274
336
  # @param root Root directory under which to search for ruby source files
275
337
  # @return [Array] Array of filenames
276
338
  def ruby_files(root = Dir.pwd)
277
- files = Dir["#{root}/**/*"].reject { |file| FileTest.directory? file }
339
+ files = Dir["#{root}/**/*"].select { |file| FileTest.file?(file) }
278
340
 
279
341
  rb = []
280
342
 
281
343
  rb += files.select { |file| File.extname(file) == '.rb' }
282
344
  rb += files.select do |file|
283
- if File.extname(file) == ''
345
+ if File.extname(file) == '' && !excluded_file?(file)
284
346
  begin
285
347
  File.open(file) { |f| f.readline } =~ /#!.*ruby/
286
348
  rescue EOFError, ArgumentError => e
@@ -295,10 +357,7 @@ module Rubocop
295
357
  config.file_to_include?(file)
296
358
  end
297
359
 
298
- rb.reject do |file|
299
- config = ConfigStore.for(file)
300
- config.file_to_exclude?(file)
301
- end.uniq
360
+ rb.reject { |file| excluded_file?(file) }.uniq
302
361
  end
303
362
 
304
363
  private
@@ -306,8 +365,34 @@ module Rubocop
306
365
  def log_error(e, msg = '')
307
366
  if @options[:debug]
308
367
  error_message = "#{e.class}, #{e.message}"
309
- STDERR.puts "#{msg}\t#{error_message}"
368
+ warn "#{msg}\t#{error_message}"
369
+ end
370
+ end
371
+
372
+ def formatter_set
373
+ @formatter_set ||= begin
374
+ set = Formatter::FormatterSet.new(!@options[:silent])
375
+ pairs = @options[:formatters] || [[DEFAULT_FORMATTER]]
376
+ pairs.each do |formatter_key, output_path|
377
+ set.add_formatter(formatter_key, output_path)
378
+ end
379
+ set
380
+ rescue => error
381
+ warn error.message
382
+ exit(1)
310
383
  end
311
384
  end
385
+
386
+ def deprecate(subject, alternative = nil, version = nil)
387
+ message = "#{subject} is deprecated"
388
+ message << " and will be removed in RuboCop #{version}" if version
389
+ message << '.'
390
+ message << " Please use #{alternative} instead." if alternative
391
+ warn message
392
+ end
393
+
394
+ def excluded_file?(file)
395
+ ConfigStore.for(file).file_to_exclude?(file)
396
+ end
312
397
  end
313
398
  end
@@ -5,6 +5,11 @@ require 'yaml'
5
5
  require 'pathname'
6
6
 
7
7
  module Rubocop
8
+ # This class represents the configuration of the RuboCop application
9
+ # and all its cops. A Config is associated with a YAML configuration
10
+ # file from which it was read. Several different Configs can be used
11
+ # during a run of the rubocop program, if files in several
12
+ # directories are inspected.
8
13
  class Config < DelegateClass(Hash)
9
14
  class ValidationError < StandardError; end
10
15
 
@@ -16,22 +21,43 @@ module Rubocop
16
21
 
17
22
  class << self
18
23
  def load_file(path)
24
+ path = File.absolute_path(path)
19
25
  hash = YAML.load_file(path)
20
26
 
21
27
  base_configs(path, hash['inherit_from']).reverse.each do |base_config|
22
28
  base_config.each do |key, value|
23
29
  if value.is_a?(Hash)
30
+ if key == 'AllCops' && value['Excludes']
31
+ correct_relative_excludes(value, base_config, path)
32
+ end
24
33
  hash[key] = hash.has_key?(key) ? merge(value, hash[key]) : value
25
34
  end
26
35
  end
27
36
  end
28
37
 
29
38
  hash.delete('inherit_from')
30
- config = new(hash, File.realpath(path))
39
+ config = new(hash, path)
31
40
  config.warn_unless_valid
32
41
  config
33
42
  end
34
43
 
44
+ def correct_relative_excludes(all_cops, base_config, path)
45
+ all_cops['Excludes'].map! do |exclude_elem|
46
+ if exclude_elem.is_a?(String) && exclude_elem =~ %r([^/].*/)
47
+ rel_path = relative_path(base_config.loaded_path,
48
+ File.dirname(path))
49
+ rel_path.to_s.sub(/#{DOTFILE}$/, '') + exclude_elem
50
+ else
51
+ exclude_elem
52
+ end
53
+ end
54
+ end
55
+
56
+ def relative_path(path, base)
57
+ path_name = Pathname.new(File.expand_path(path))
58
+ path_name.relative_path_from(Pathname.new(base)).to_s
59
+ end
60
+
35
61
  # Return a recursive merge of two hashes. That is, a normal hash
36
62
  # merge, with the addition that any value that is a hash, and
37
63
  # occurs in both arguments, will also be merged. And so on.
@@ -72,21 +98,34 @@ module Rubocop
72
98
  # user's home directory is checked. If there's no .rubocop.yml
73
99
  # there either, the path to the default file is returned.
74
100
  def configuration_file_for(target_dir)
75
- possible_config_files = dirs_to_search(target_dir).map do |dir|
76
- File.join(dir, DOTFILE)
77
- end
78
-
79
- found_file = possible_config_files.find do |config_file|
80
- File.exist?(config_file)
81
- end
82
- found_file || DEFAULT_FILE
101
+ config_files_in_path(target_dir).first || DEFAULT_FILE
83
102
  end
84
103
 
85
104
  def configuration_from_file(config_file)
86
105
  config = load_file(config_file)
106
+ found_files = config_files_in_path(config_file)
107
+ if found_files.any? && found_files.last != config_file
108
+ add_excludes_from_higher_level(config, load_file(found_files.last))
109
+ end
87
110
  merge_with_default(config, config_file)
88
111
  end
89
112
 
113
+ def add_excludes_from_higher_level(config, highest_config)
114
+ if highest_config['AllCops'] && highest_config['AllCops']['Excludes']
115
+ config['AllCops'] ||= {}
116
+ config['AllCops']['Excludes'] ||= []
117
+ highest_config['AllCops']['Excludes'].each do |path|
118
+ unless path.is_a?(Regexp) || path.start_with?('/')
119
+ diff_in_level = config.loaded_path.count('/') -
120
+ highest_config.loaded_path.count('/')
121
+ path = '../' * diff_in_level + path
122
+ end
123
+ config['AllCops']['Excludes'] << path
124
+ end
125
+ config['AllCops']['Excludes'].uniq!
126
+ end
127
+ end
128
+
90
129
  def default_configuration
91
130
  @default_configuration ||= load_file(DEFAULT_FILE)
92
131
  end
@@ -97,6 +136,13 @@ module Rubocop
97
136
 
98
137
  private
99
138
 
139
+ def config_files_in_path(target)
140
+ possible_config_files = dirs_to_search(target).map do |dir|
141
+ File.join(dir, DOTFILE)
142
+ end
143
+ possible_config_files.select { |config_file| File.exist?(config_file) }
144
+ end
145
+
100
146
  def dirs_to_search(target_dir)
101
147
  dirs_to_search = []
102
148
  target_dir_pathname = Pathname.new(File.expand_path(target_dir))
@@ -181,8 +227,7 @@ module Rubocop
181
227
 
182
228
  def relative_path_to_loaded_dir(file)
183
229
  return file unless loaded_path
184
- file_pathname = Pathname.new(File.expand_path(file))
185
- file_pathname.relative_path_from(loaded_dir_pathname).to_s
230
+ Config.relative_path(file, loaded_dir_pathname)
186
231
  end
187
232
 
188
233
  def loaded_dir_pathname