reek 4.8.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +5 -5
  2. data/{samples/configuration/more_than_one_configuration_file/regular.reek → .reek.yml} +0 -0
  3. data/.rubocop.yml +17 -3
  4. data/.simplecov +1 -0
  5. data/.travis.yml +0 -5
  6. data/.yardopts +1 -1
  7. data/CHANGELOG.md +28 -0
  8. data/Gemfile +1 -1
  9. data/README.md +113 -98
  10. data/Rakefile +16 -3
  11. data/bin/reek +1 -3
  12. data/docs/API.md +2 -9
  13. data/docs/Basic-Smell-Options.md +51 -11
  14. data/docs/Code-Smells.md +1 -1
  15. data/docs/Command-Line-Options.md +14 -4
  16. data/docs/Duplicate-Method-Call.md +49 -1
  17. data/docs/Feature-Envy.md +44 -0
  18. data/docs/How-To-Write-New-Detectors.md +2 -3
  19. data/docs/{Prima-Donna-Method.md → Missing-Safe-Method.md} +11 -9
  20. data/docs/Rake-Task.md +1 -1
  21. data/docs/Reek-4-to-Reek-5-migration.md +193 -0
  22. data/docs/Reek-Driven-Development.md +1 -1
  23. data/docs/Uncommunicative-Method-Name.md +43 -4
  24. data/docs/Uncommunicative-Module-Name.md +48 -6
  25. data/docs/Uncommunicative-Parameter-Name.md +42 -4
  26. data/docs/Uncommunicative-Variable-Name.md +73 -2
  27. data/docs/Unused-Private-Method.md +1 -1
  28. data/docs/defaults.reek.yml +129 -0
  29. data/docs/yard_plugin.rb +1 -0
  30. data/features/command_line_interface/options.feature +46 -4
  31. data/features/command_line_interface/stdin.feature +27 -5
  32. data/features/configuration_files/accept_setting.feature +39 -22
  33. data/features/configuration_files/directory_specific_directives.feature +58 -53
  34. data/features/configuration_files/exclude_directives.feature +8 -7
  35. data/features/configuration_files/masking_smells.feature +35 -6
  36. data/features/configuration_files/mix_accept_reject_setting.feature +24 -21
  37. data/features/configuration_files/reject_setting.feature +45 -34
  38. data/features/configuration_files/schema_validation.feature +59 -0
  39. data/features/configuration_files/unused_private_method.feature +14 -12
  40. data/features/configuration_loading.feature +50 -7
  41. data/features/rake_task/rake_task.feature +5 -5
  42. data/features/reports/json.feature +4 -1
  43. data/features/reports/reports.feature +12 -12
  44. data/features/reports/yaml.feature +3 -0
  45. data/features/rspec_matcher.feature +9 -1
  46. data/features/step_definitions/reek_steps.rb +4 -0
  47. data/features/step_definitions/sample_file_steps.rb +9 -4
  48. data/features/support/env.rb +2 -2
  49. data/features/todo_list.feature +16 -13
  50. data/lib/reek/ast/node.rb +3 -6
  51. data/lib/reek/ast/object_refs.rb +1 -1
  52. data/lib/reek/ast/sexp_extensions/if.rb +1 -1
  53. data/lib/reek/ast/sexp_extensions/methods.rb +1 -1
  54. data/lib/reek/cli/application.rb +4 -3
  55. data/lib/reek/cli/command/report_command.rb +1 -2
  56. data/lib/reek/cli/command/todo_list_command.rb +4 -2
  57. data/lib/reek/cli/options.rb +27 -13
  58. data/lib/reek/cli/silencer.rb +14 -3
  59. data/lib/reek/code_comment.rb +14 -16
  60. data/lib/reek/configuration/app_configuration.rb +32 -28
  61. data/lib/reek/configuration/configuration_converter.rb +110 -0
  62. data/lib/reek/configuration/configuration_file_finder.rb +15 -40
  63. data/lib/reek/configuration/configuration_validator.rb +12 -23
  64. data/lib/reek/configuration/default_directive.rb +17 -3
  65. data/lib/reek/configuration/directory_directives.rb +17 -11
  66. data/lib/reek/configuration/excluded_paths.rb +1 -1
  67. data/lib/reek/configuration/rake_task_converter.rb +29 -0
  68. data/lib/reek/configuration/schema.yml +210 -0
  69. data/lib/reek/configuration/schema_validator.rb +38 -0
  70. data/lib/reek/context/attribute_context.rb +1 -1
  71. data/lib/reek/context/code_context.rb +4 -4
  72. data/lib/reek/context/method_context.rb +2 -2
  73. data/lib/reek/context/module_context.rb +1 -1
  74. data/lib/reek/context_builder.rb +9 -9
  75. data/lib/reek/detector_repository.rb +6 -0
  76. data/lib/reek/documentation_link.rb +2 -2
  77. data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +1 -1
  78. data/lib/reek/errors/bad_detector_in_comment_error.rb +1 -1
  79. data/lib/reek/errors/config_file_error.rb +11 -0
  80. data/lib/reek/errors/encoding_error.rb +2 -2
  81. data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +1 -1
  82. data/lib/reek/errors/incomprehensible_source_error.rb +2 -2
  83. data/lib/reek/errors/syntax_error.rb +41 -0
  84. data/lib/reek/examiner.rb +9 -19
  85. data/lib/reek/rake/task.rb +3 -3
  86. data/lib/reek/report.rb +15 -10
  87. data/lib/reek/report/base_report.rb +8 -12
  88. data/lib/reek/report/code_climate/code_climate_configuration.yml +5 -9
  89. data/lib/reek/report/documentation_link_warning_formatter.rb +17 -0
  90. data/lib/reek/report/heading_formatter.rb +54 -0
  91. data/lib/reek/report/json_report.rb +1 -1
  92. data/lib/reek/report/location_formatter.rb +40 -0
  93. data/lib/reek/report/progress_formatter.rb +79 -0
  94. data/lib/reek/report/simple_warning_formatter.rb +34 -0
  95. data/lib/reek/report/text_report.rb +1 -2
  96. data/lib/reek/report/xml_report.rb +3 -3
  97. data/lib/reek/report/yaml_report.rb +1 -1
  98. data/lib/reek/smell_configuration.rb +2 -2
  99. data/lib/reek/smell_detectors.rb +1 -2
  100. data/lib/reek/smell_detectors/attribute.rb +0 -1
  101. data/lib/reek/smell_detectors/base_detector.rb +8 -11
  102. data/lib/reek/smell_detectors/boolean_parameter.rb +0 -1
  103. data/lib/reek/smell_detectors/class_variable.rb +0 -1
  104. data/lib/reek/smell_detectors/control_parameter.rb +17 -32
  105. data/lib/reek/smell_detectors/data_clump.rb +3 -4
  106. data/lib/reek/smell_detectors/duplicate_method_call.rb +5 -6
  107. data/lib/reek/smell_detectors/feature_envy.rb +0 -1
  108. data/lib/reek/smell_detectors/instance_variable_assumption.rb +0 -1
  109. data/lib/reek/smell_detectors/irresponsible_module.rb +0 -1
  110. data/lib/reek/smell_detectors/long_parameter_list.rb +1 -2
  111. data/lib/reek/smell_detectors/long_yield_list.rb +2 -3
  112. data/lib/reek/smell_detectors/manual_dispatch.rb +2 -2
  113. data/lib/reek/smell_detectors/{prima_donna_method.rb → missing_safe_method.rb} +6 -7
  114. data/lib/reek/smell_detectors/module_initialize.rb +0 -1
  115. data/lib/reek/smell_detectors/nested_iterators.rb +4 -5
  116. data/lib/reek/smell_detectors/nil_check.rb +0 -1
  117. data/lib/reek/smell_detectors/repeated_conditional.rb +3 -4
  118. data/lib/reek/smell_detectors/subclassed_from_core_class.rb +0 -1
  119. data/lib/reek/smell_detectors/too_many_constants.rb +1 -2
  120. data/lib/reek/smell_detectors/too_many_instance_variables.rb +1 -2
  121. data/lib/reek/smell_detectors/too_many_methods.rb +1 -2
  122. data/lib/reek/smell_detectors/too_many_statements.rb +1 -2
  123. data/lib/reek/smell_detectors/uncommunicative_method_name.rb +2 -3
  124. data/lib/reek/smell_detectors/uncommunicative_module_name.rb +2 -3
  125. data/lib/reek/smell_detectors/uncommunicative_parameter_name.rb +2 -3
  126. data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +4 -5
  127. data/lib/reek/smell_detectors/unused_parameters.rb +0 -1
  128. data/lib/reek/smell_detectors/unused_private_method.rb +0 -1
  129. data/lib/reek/smell_detectors/utility_function.rb +1 -2
  130. data/lib/reek/smell_warning.rb +10 -8
  131. data/lib/reek/source/source_code.rb +40 -55
  132. data/lib/reek/source/source_locator.rb +7 -7
  133. data/lib/reek/spec.rb +6 -6
  134. data/lib/reek/spec/should_reek.rb +2 -2
  135. data/lib/reek/spec/should_reek_of.rb +9 -16
  136. data/lib/reek/spec/should_reek_only_of.rb +4 -4
  137. data/lib/reek/tree_dresser.rb +5 -5
  138. data/lib/reek/version.rb +1 -1
  139. data/reek.gemspec +3 -3
  140. data/samples/checkstyle.xml +1 -1
  141. data/samples/{clean.rb → clean_source/clean.rb} +0 -0
  142. data/samples/configuration/accepts_rejects_and_excludes_for_detectors.reek.yml +29 -0
  143. data/samples/configuration/accepts_rejects_and_excludes_for_directory_directives.reek.yml +30 -0
  144. data/samples/configuration/full_configuration.reek +8 -4
  145. data/samples/configuration/full_mask.reek +5 -4
  146. data/samples/{exceptions.reek → configuration/home/home.reek.yml} +0 -0
  147. data/samples/configuration/partial_mask.reek +3 -2
  148. data/samples/configuration/regular_configuration/.reek.yml +4 -0
  149. data/samples/configuration/{more_than_one_configuration_file/todo.reek → regular_configuration/empty_sub_directory/.gitignore} +0 -0
  150. data/samples/{configuration/single_configuration_file/.reek → no_config_file/.keep} +0 -0
  151. data/samples/paths.rb +5 -4
  152. data/samples/{inline.rb → smelly_source/inline.rb} +0 -0
  153. data/samples/{optparse.rb → smelly_source/optparse.rb} +0 -0
  154. data/samples/{redcloth.rb → smelly_source/redcloth.rb} +0 -0
  155. data/samples/{smelly.rb → smelly_source/smelly.rb} +0 -0
  156. data/samples/source_with_hidden_directories/.hidden/hidden.rb +1 -0
  157. data/samples/source_with_hidden_directories/not_hidden.rb +1 -0
  158. data/samples/{source_with_hidden_directories/uncommunicative_parameter_name.rb → source_with_non_ruby_files/ruby.rb} +0 -0
  159. data/spec/reek/ast/node_spec.rb +5 -5
  160. data/spec/reek/cli/application_spec.rb +18 -4
  161. data/spec/reek/cli/command/todo_list_command_spec.rb +4 -2
  162. data/spec/reek/cli/silencer_spec.rb +28 -0
  163. data/spec/reek/code_comment_spec.rb +0 -7
  164. data/spec/reek/configuration/app_configuration_spec.rb +44 -31
  165. data/spec/reek/configuration/configuration_file_finder_spec.rb +133 -49
  166. data/spec/reek/configuration/default_directive_spec.rb +1 -1
  167. data/spec/reek/configuration/directory_directives_spec.rb +3 -4
  168. data/spec/reek/configuration/excluded_paths_spec.rb +5 -5
  169. data/spec/reek/configuration/rake_task_converter_spec.rb +33 -0
  170. data/spec/reek/configuration/schema_validator_spec.rb +165 -0
  171. data/spec/reek/context/code_context_spec.rb +1 -1
  172. data/spec/reek/examiner_spec.rb +28 -1
  173. data/spec/reek/report/json_report_spec.rb +13 -46
  174. data/spec/reek/report/{formatter/location_formatter_spec.rb → location_formatter_spec.rb} +5 -5
  175. data/spec/reek/report/{formatter/progress_formatter_spec.rb → progress_formatter_spec.rb} +4 -4
  176. data/spec/reek/report/text_report_spec.rb +4 -4
  177. data/spec/reek/report/xml_report_spec.rb +1 -1
  178. data/spec/reek/report/yaml_report_spec.rb +9 -38
  179. data/spec/reek/report_spec.rb +3 -3
  180. data/spec/reek/smell_detectors/feature_envy_spec.rb +2 -2
  181. data/spec/reek/smell_detectors/{prima_donna_method_spec.rb → missing_safe_method_spec.rb} +9 -9
  182. data/spec/reek/smell_detectors/too_many_constants_spec.rb +3 -3
  183. data/spec/reek/smell_detectors/too_many_instance_variables_spec.rb +1 -1
  184. data/spec/reek/smell_detectors/uncommunicative_method_name_spec.rb +6 -6
  185. data/spec/reek/smell_detectors/uncommunicative_module_name_spec.rb +6 -4
  186. data/spec/reek/smell_detectors/uncommunicative_parameter_name_spec.rb +6 -4
  187. data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +6 -6
  188. data/spec/reek/smell_detectors/unused_private_method_spec.rb +1 -1
  189. data/spec/reek/smell_warning_spec.rb +4 -0
  190. data/spec/reek/source/source_code_spec.rb +16 -22
  191. data/spec/reek/source/source_locator_spec.rb +11 -11
  192. data/spec/reek/spec/should_reek_of_spec.rb +0 -4
  193. data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
  194. data/spec/reek/spec/should_reek_spec.rb +1 -1
  195. data/spec/reek/tree_dresser_spec.rb +2 -6
  196. data/spec/spec_helper.rb +3 -5
  197. data/tasks/configuration.rake +8 -5
  198. metadata +56 -35
  199. data/defaults.reek +0 -131
  200. data/features/configuration_files/warn_about_multiple_configuration_files.feature +0 -44
  201. data/lib/reek/report/formatter.rb +0 -33
  202. data/lib/reek/report/formatter/heading_formatter.rb +0 -52
  203. data/lib/reek/report/formatter/location_formatter.rb +0 -42
  204. data/lib/reek/report/formatter/progress_formatter.rb +0 -81
  205. data/lib/reek/report/formatter/simple_warning_formatter.rb +0 -35
  206. data/lib/reek/report/formatter/wiki_link_warning_formatter.rb +0 -23
  207. data/lib/reek/smell_detectors/syntax.rb +0 -37
  208. data/samples/configuration/non_public_modifiers_mask.reek +0 -3
  209. data/samples/smelly_with_inline_mask.rb +0 -8
  210. data/samples/smelly_with_modifiers.rb +0 -12
  211. data/samples/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb +0 -5
  212. data/samples/source_with_non_ruby_files/uncommunicative_parameter_name.rb +0 -6
  213. data/spec/reek/smell_detectors/syntax_spec.rb +0 -17
@@ -14,7 +14,7 @@ Reek::Rake::Task.new do |t|
14
14
  end
15
15
  ```
16
16
 
17
- Now the command `reek` will run Reek on your source code (and in this case, it fails if it finds any smells). For more detailed information about Reek's integration with Rake, see [Rake Task](Rake-Task.md) in this wiki.
17
+ Now the command `reek` will run Reek on your source code (and in this case, it fails if it finds any smells). For more detailed information about Reek's integration with Rake, see [Rake Task](Rake-Task.md).
18
18
 
19
19
  ## reek/spec
20
20
 
@@ -21,8 +21,8 @@ Reek's _Uncommunicative Method Name_ detector supports the
21
21
 
22
22
  | Option | Value | Effect |
23
23
  | ---------------|-------------|---------|
24
- | `reject` | array of regular expressions or strings | The set of patterns / names that Reek uses to check for bad names. Defaults to `[/^[a-z]$/, /[0-9]$/, /[A-Z]/]`. |
25
- | `accept` | array of regular expressions or strings | The set of patterns / names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
24
+ | `reject` | array of strings | The set of names that Reek uses to check for bad names. Defaults to single-letter names, names ending with a number or names containing upper case letters. |
25
+ | `accept` | array of strings | The set of names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
26
26
 
27
27
  An example configuration could look like this:
28
28
 
@@ -30,13 +30,15 @@ An example configuration could look like this:
30
30
  ---
31
31
  UncommunicativeMethodName:
32
32
  accept:
33
- - !ruby/regexp /x/
33
+ - x
34
34
  - meth1
35
35
  reject:
36
- - !ruby/regexp /helper/
36
+ - helper
37
37
  - foobar
38
38
  ```
39
39
 
40
+ Reek will convert whatever you give it as a string to the corresponding regex, so "foobar" from above will be converted to /foobar/ internally.
41
+
40
42
  Applying a configuration to a source file like this:
41
43
 
42
44
  ```Ruby
@@ -53,3 +55,40 @@ smelly.rb -- 2 warnings:
53
55
  [4]:UncommunicativeMethodName: awesome_helper has the name 'awesome_helper'
54
56
  [3]:UncommunicativeMethodName: foobar has the name 'foobar'
55
57
  ```
58
+
59
+ ## Advanced configuration
60
+
61
+ Sometimes just strings are not enough for configuration. E.g. consider this code sample:
62
+
63
+ ```Ruby
64
+ class Klass
65
+ def foo; end
66
+ def foobar; end;
67
+ end
68
+ ```
69
+
70
+ and now imagine that you want to reject the name "foo" but not "foobar". This wouldn't be possible with just using strings.
71
+ For this reason Reek has a special syntax that allows you to use regexes by using a forward slash at the beginning and the end of the string.
72
+ Everything within the forward slashes will be loaded as a regex.
73
+
74
+ A possible configuration that allows "foobar" but rejects "foo" could look like this:
75
+
76
+ ```Yaml
77
+ ---
78
+ UncommunicativeMethodName:
79
+ reject:
80
+ - "/^foo$/"
81
+ ```
82
+
83
+ ## Reek 4
84
+
85
+ In Reek 4 you could also pass regexes to `accept` or `reject`, meaning this was perfectly valid as well:
86
+
87
+ ```yaml
88
+ UncommunicativeMethodName:
89
+ accept:
90
+ - !ruby/regexp /foobar/
91
+ ```
92
+
93
+ Support for this has been scrapped with Reek 5 to make the Reek configuration more yaml standard compliant.
94
+ You can still pass in regexes, you just have to wrap them into a string. Please see "Advanced configuration" above.
@@ -19,8 +19,8 @@ Reek's _Uncommunicative Module Name_ detector supports the [Basic Smell Options]
19
19
 
20
20
  | Option | Value | Effect |
21
21
  | ---------------|-------------|---------|
22
- | `reject` | array of regular expressions or strings | The set of patterns or names that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/]`. |
23
- | `accept` | array of regular expressions or strings | The set of patterns or names that Reek will accept (and not report) even if they match one of the `reject` expressions. Empty by default.|
22
+ | `reject` | array of strings | The set of names that Reek uses to check for bad names. Defaults to single-letter names and names ending with a number. |
23
+ | `accept` | array or strings | The set of names that Reek will accept (and not report) even if they match one of the `reject` expressions. Empty by default.|
24
24
 
25
25
  An example configuration could look like this:
26
26
 
@@ -28,17 +28,19 @@ An example configuration could look like this:
28
28
  ---
29
29
  UncommunicativeModuleName:
30
30
  accept:
31
- - !ruby/regexp /lassy/
32
- - M
31
+ - lassy
32
+ - Util
33
33
  reject:
34
- - !ruby/regexp /Helper/
34
+ - Helper
35
35
  ```
36
36
 
37
+ Reek will convert whatever you give it as a string to the corresponding regex, so "Helper" from above will be converted to /Helper/ internally.
38
+
37
39
  Applying a configuration to a source file like this:
38
40
 
39
41
  ```Ruby
40
42
  class Classy1; end # Should not be reported
41
- class M; end # Should not be reported
43
+ class Util; end # Should not be reported
42
44
  class BaseHelper; end # Should be reported
43
45
  ```
44
46
 
@@ -48,3 +50,43 @@ Reek would report:
48
50
  smelly.rb -- 1 warning:
49
51
  [3]:UncommunicativeModuleName: BaseHelper has the name 'BaseHelper'
50
52
  ```
53
+
54
+ ## Advanced configuration
55
+
56
+ Sometimes just strings are not enough for configuration. E.g. consider this code sample:
57
+
58
+ ```Ruby
59
+ class Klassy
60
+ # ...
61
+ end
62
+
63
+ class KlassyModule
64
+ # ...
65
+ end
66
+ ```
67
+
68
+ and now imagine that you want to reject the name "Klassy" but not "KlassyModule". This wouldn't be possible with just using strings.
69
+ For this reason Reek has a special syntax that allows you to use regexes by using a forward slash at the beginning and the end of the string.
70
+ Everything within the forward slashes will be loaded as a regex.
71
+
72
+ A possible configuration that allows "KlassyModule" but rejects "Klassy" could look like this:
73
+
74
+ ```Yaml
75
+ ---
76
+ UncommunicativeModuleName:
77
+ reject:
78
+ - "/^Klassy$/"
79
+ ```
80
+
81
+ ## Reek 4
82
+
83
+ In Reek 4 you could also pass regexes to `accept` or `reject`, meaning this was perfectly valid as well:
84
+
85
+ ```yaml
86
+ UncommunicativeModuleName:
87
+ accept:
88
+ - !ruby/regexp /foobar/
89
+ ```
90
+
91
+ Support for this has been scrapped with Reek 5 to make the Reek configuration more yaml standard compliant.
92
+ You can still pass in regexes, you just have to wrap them into a string. Please see "Advanced configuration" above.
@@ -20,8 +20,8 @@ Reek's _Uncommunicative Parameter Name_ detector supports the [Basic Smell Optio
20
20
 
21
21
  | Option | Value | Effect |
22
22
  | ---------|-------------|---------|
23
- | `reject` | array of regular expressions or strings | The set of patterns / names that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/, /[A-Z]/, /^_/]. |
24
- | `accept` | array of regular expressions or strings | The set of patterns / names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
23
+ | `reject` | array of strings | The set of names that Reek uses to check for bad names. Defaults to single-letter names, names containing an uppercase letter, names with a number at the end and '_'. |
24
+ | `accept` | array of strings | The set of names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
25
25
 
26
26
 
27
27
  An example configuration could look like this:
@@ -30,12 +30,14 @@ An example configuration could look like this:
30
30
  ---
31
31
  UncommunicativeParameterName:
32
32
  accept:
33
- - !ruby/regexp /x/
33
+ - x
34
34
  - arg1
35
35
  reject:
36
- - !ruby/regexp /foobar/
36
+ - foobar
37
37
  ```
38
38
 
39
+ Reek will convert whatever you give it as a string to the corresponding regex, so "foobar" from above will be converted to /foobar/ internally.
40
+
39
41
  Applying a configuration to a source file like this:
40
42
 
41
43
  ```Ruby
@@ -50,3 +52,39 @@ Reek would report:
50
52
  smelly.rb -- 1 warning:
51
53
  [3]:UncommunicativeParameterName: omg has the parameter name 'foobar'
52
54
  ```
55
+
56
+ ## Advanced configuration
57
+
58
+ Sometimes just strings are not enough for configuration. E.g. consider this code sample:
59
+
60
+ ```Ruby
61
+ class Klass
62
+ def my_method(foo, foobar); end
63
+ end
64
+ ```
65
+
66
+ and now imagine that you want to reject the name "foo" but not "foobar". This wouldn't be possible with just using strings.
67
+ For this reason Reek has a special syntax that allows you to use regexes by using a forward slash at the beginning and the end of the string.
68
+ Everything within the forward slashes will be loaded as a regex.
69
+
70
+ A possible configuration that allows "foobar" but rejects "foo" could look like this:
71
+
72
+ ```Yaml
73
+ ---
74
+ UncommunicativeParameterName:
75
+ reject:
76
+ - "/^foo$/"
77
+ ```
78
+
79
+ ## Reek 4
80
+
81
+ In Reek 4 you could also pass regexes to `accept` or `reject`, meaning this was perfectly valid as well:
82
+
83
+ ```yaml
84
+ UncommunicativeParameterName:
85
+ accept:
86
+ - !ruby/regexp /foobar/
87
+ ```
88
+
89
+ Support for this has been scrapped with Reek 5 to make the Reek configuration more yaml standard compliant.
90
+ You can still pass in regexes, you just have to wrap them into a string. Please see "Advanced configuration" above.
@@ -21,5 +21,76 @@ Reek's _Uncommunicative Variable Name_ detector supports the
21
21
 
22
22
  | Option | Value | Effect |
23
23
  | ---------------|-------------|---------|
24
- | `reject` | array of regular expressions | The set of regular expressions that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/, /[A-Z]/]`. |
25
- | `accept` | array of strings or regular expressions | Name that will be accepted (not reported) even if they match one of the `reject` expressions. Defaults to `['_']`.|
24
+ | `reject` | array of strings | The set of names that Reek uses to check for bad names. Defaults to single-letter names, names ending with a number or names containing upper case letters. |
25
+ | `accept` | array of strings | Names that will be accepted (not reported) even if they match one of the `reject` expressions. Defaults to `_`.|
26
+
27
+ An example configuration could look like this:
28
+
29
+ ```Yaml
30
+ ---
31
+ UncommunicativeVariableName:
32
+ accept:
33
+ - x
34
+ - var1
35
+ reject:
36
+ - helper
37
+ - foobar
38
+ ```
39
+
40
+ Reek will convert whatever you give it as a string to the corresponding regex, so "foobar" from above will be converted to /foobar/ internally.
41
+
42
+ Applying a configuration to a source file like this:
43
+
44
+ ```Ruby
45
+ def omg
46
+ x = 5 # Should not be reported
47
+ var1 = true # Should not be reported
48
+ helper = 42 # Should be reported
49
+ foobar = false # Should be reported
50
+ end
51
+ ```
52
+
53
+ Reek would report:
54
+
55
+ ```
56
+ smelly.rb -- 2 warnings:
57
+ [5]:UncommunicativeVariableName: omg has the variable name 'foobar' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
58
+ [4]:UncommunicativeVariableName: omg has the variable name 'helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
59
+ ```
60
+
61
+ ## Advanced configuration
62
+
63
+ Sometimes just strings are not enough for configuration. E.g. consider this code sample:
64
+
65
+ ```Ruby
66
+ def omg
67
+ foo = 42
68
+ foobar = 4242
69
+ end
70
+ ```
71
+
72
+ and now imagine that you want to reject the name "foo" but not "foobar". This wouldn't be possible with just using strings.
73
+ For this reason Reek has a special syntax that allows you to use regexes by using a forward slash at the beginning and the end of the string.
74
+ Everything within the forward slashes will be loaded as a regex.
75
+
76
+ A possible configuration that allows "foobar" but rejects "foo" could look like this:
77
+
78
+ ```Yaml
79
+ ---
80
+ UncommunicativeVariableName:
81
+ reject:
82
+ - "/^foo$/"
83
+ ```
84
+
85
+ ## Reek 4
86
+
87
+ In Reek 4 you could also pass regexes to `accept` or `reject`, meaning this was perfectly valid as well:
88
+
89
+ ```yaml
90
+ UncommunicativeVariableName:
91
+ accept:
92
+ - !ruby/regexp /write/
93
+ ```
94
+
95
+ Support for this has been scrapped with Reek 5 to make the Reek configuration more yaml standard compliant.
96
+ You can still pass in regexes, you just have to wrap them into a string. Please see "Advanced configuration" above.
@@ -37,7 +37,7 @@ configuration option (which is part of the [Basic Smell Options](Basic-Smell-Opt
37
37
  for instance like this (an example from Reek's own codebase):
38
38
 
39
39
  ```Ruby
40
- # :reek:UnusedPrivateMethod { exclude: [ !ruby/regexp /process_/ ] }
40
+ # :reek:UnusedPrivateMethod { exclude: [ process_ ] }
41
41
  class ContextBuilder
42
42
  def process_begin
43
43
  # ....
@@ -0,0 +1,129 @@
1
+ ---
2
+ detectors:
3
+ Attribute:
4
+ enabled: true
5
+ exclude: []
6
+ BooleanParameter:
7
+ enabled: true
8
+ exclude: []
9
+ ClassVariable:
10
+ enabled: true
11
+ exclude: []
12
+ ControlParameter:
13
+ enabled: true
14
+ exclude: []
15
+ DataClump:
16
+ enabled: true
17
+ exclude: []
18
+ max_copies: 2
19
+ min_clump_size: 2
20
+ DuplicateMethodCall:
21
+ enabled: true
22
+ exclude: []
23
+ max_calls: 1
24
+ allow_calls: []
25
+ FeatureEnvy:
26
+ enabled: true
27
+ exclude: []
28
+ InstanceVariableAssumption:
29
+ enabled: true
30
+ exclude: []
31
+ IrresponsibleModule:
32
+ enabled: true
33
+ exclude: []
34
+ LongParameterList:
35
+ enabled: true
36
+ exclude: []
37
+ max_params: 3
38
+ overrides:
39
+ initialize:
40
+ max_params: 5
41
+ LongYieldList:
42
+ enabled: true
43
+ exclude: []
44
+ max_params: 3
45
+ ManualDispatch:
46
+ enabled: true
47
+ exclude: []
48
+ MissingSafeMethod:
49
+ enabled: true
50
+ exclude: []
51
+ ModuleInitialize:
52
+ enabled: true
53
+ exclude: []
54
+ NestedIterators:
55
+ enabled: true
56
+ exclude: []
57
+ max_allowed_nesting: 1
58
+ ignore_iterators:
59
+ - tap
60
+ NilCheck:
61
+ enabled: true
62
+ exclude: []
63
+ RepeatedConditional:
64
+ enabled: true
65
+ exclude: []
66
+ max_ifs: 2
67
+ SubclassedFromCoreClass:
68
+ enabled: true
69
+ exclude: []
70
+ TooManyConstants:
71
+ enabled: true
72
+ exclude: []
73
+ max_constants: 5
74
+ TooManyInstanceVariables:
75
+ enabled: true
76
+ exclude: []
77
+ max_instance_variables: 4
78
+ TooManyMethods:
79
+ enabled: true
80
+ exclude: []
81
+ max_methods: 15
82
+ TooManyStatements:
83
+ enabled: true
84
+ exclude:
85
+ - initialize
86
+ max_statements: 5
87
+ UncommunicativeMethodName:
88
+ enabled: true
89
+ exclude: []
90
+ reject:
91
+ - "/^[a-z]$/"
92
+ - "/[0-9]$/"
93
+ - "/[A-Z]/"
94
+ accept: []
95
+ UncommunicativeModuleName:
96
+ enabled: true
97
+ exclude: []
98
+ reject:
99
+ - "/^.$/"
100
+ - "/[0-9]$/"
101
+ accept: []
102
+ UncommunicativeParameterName:
103
+ enabled: true
104
+ exclude: []
105
+ reject:
106
+ - "/^.$/"
107
+ - "/[0-9]$/"
108
+ - "/[A-Z]/"
109
+ - "/^_/"
110
+ accept: []
111
+ UncommunicativeVariableName:
112
+ enabled: true
113
+ exclude: []
114
+ reject:
115
+ - "/^.$/"
116
+ - "/[0-9]$/"
117
+ - "/[A-Z]/"
118
+ accept:
119
+ - "/^_$/"
120
+ UnusedParameters:
121
+ enabled: true
122
+ exclude: []
123
+ UnusedPrivateMethod:
124
+ enabled: false
125
+ exclude: []
126
+ UtilityFunction:
127
+ enabled: true
128
+ exclude: []
129
+ public_methods_only: false
data/docs/yard_plugin.rb CHANGED
@@ -13,4 +13,5 @@ end
13
13
 
14
14
  YARD::Templates::Template.extra_includes << LocalLinkHelper
15
15
  YARD::Tags::Library.define_tag('Guaranteed public API', :public)
16
+ YARD::Tags::Library.define_tag('Code quality configuration', :quality)
16
17
  YARD::Templates::Engine.register_template_path File.join(File.dirname(__FILE__), 'templates')