rubocop 0.21.0 → 0.22.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 (159) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/{rubocop-todo.yml → .rubocop_todo.yml} +5 -5
  4. data/CHANGELOG.md +41 -0
  5. data/README.md +21 -11
  6. data/config/default.yml +33 -10
  7. data/config/disabled.yml +0 -4
  8. data/config/enabled.yml +27 -1
  9. data/lib/rubocop.rb +17 -1
  10. data/lib/rubocop/config.rb +32 -27
  11. data/lib/rubocop/config_loader.rb +21 -8
  12. data/lib/rubocop/cop/cop.rb +8 -8
  13. data/lib/rubocop/cop/lint/block_alignment.rb +22 -22
  14. data/lib/rubocop/cop/lint/condition_position.rb +3 -5
  15. data/lib/rubocop/cop/lint/debugger.rb +4 -5
  16. data/lib/rubocop/cop/lint/end_alignment.rb +11 -10
  17. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -11
  18. data/lib/rubocop/cop/lint/require_parentheses.rb +7 -7
  19. data/lib/rubocop/cop/lint/rescue_exception.rb +3 -3
  20. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -7
  21. data/lib/rubocop/cop/lint/unreachable_code.rb +2 -3
  22. data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -15
  23. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -14
  24. data/lib/rubocop/cop/lint/useless_comparison.rb +4 -5
  25. data/lib/rubocop/cop/lint/void.rb +6 -8
  26. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +4 -2
  27. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +1 -3
  28. data/lib/rubocop/cop/mixin/code_length.rb +5 -5
  29. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -6
  30. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -3
  31. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -5
  32. data/lib/rubocop/cop/mixin/space_inside.rb +10 -11
  33. data/lib/rubocop/cop/mixin/unused_argument.rb +35 -0
  34. data/lib/rubocop/cop/offense.rb +1 -1
  35. data/lib/rubocop/cop/rails/action_filter.rb +6 -8
  36. data/lib/rubocop/cop/rails/default_scope.rb +2 -4
  37. data/lib/rubocop/cop/rails/delegate.rb +2 -0
  38. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -3
  39. data/lib/rubocop/cop/rails/output.rb +2 -3
  40. data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -4
  41. data/lib/rubocop/cop/rails/validation.rb +2 -3
  42. data/lib/rubocop/cop/style/alias.rb +3 -3
  43. data/lib/rubocop/cop/style/align_hash.rb +4 -4
  44. data/lib/rubocop/cop/style/align_parameters.rb +13 -1
  45. data/lib/rubocop/cop/style/and_or.rb +2 -5
  46. data/lib/rubocop/cop/style/array_join.rb +3 -4
  47. data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -3
  48. data/lib/rubocop/cop/style/block_comments.rb +2 -3
  49. data/lib/rubocop/cop/style/block_nesting.rb +2 -3
  50. data/lib/rubocop/cop/style/blocks.rb +9 -9
  51. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +5 -5
  52. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  53. data/lib/rubocop/cop/style/class_methods.rb +3 -5
  54. data/lib/rubocop/cop/style/collection_methods.rb +8 -11
  55. data/lib/rubocop/cop/style/comment_annotation.rb +9 -9
  56. data/lib/rubocop/cop/style/comment_indentation.rb +66 -0
  57. data/lib/rubocop/cop/style/constant_name.rb +3 -3
  58. data/lib/rubocop/cop/style/cyclomatic_complexity.rb +5 -5
  59. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +6 -6
  60. data/lib/rubocop/cop/style/each_with_object.rb +38 -0
  61. data/lib/rubocop/cop/style/empty_lines.rb +8 -8
  62. data/lib/rubocop/cop/style/empty_lines_around_body.rb +7 -7
  63. data/lib/rubocop/cop/style/encoding.rb +6 -7
  64. data/lib/rubocop/cop/style/end_of_line.rb +10 -10
  65. data/lib/rubocop/cop/style/file_name.rb +11 -7
  66. data/lib/rubocop/cop/style/guard_clause.rb +32 -22
  67. data/lib/rubocop/cop/style/indentation_width.rb +25 -26
  68. data/lib/rubocop/cop/style/lambda.rb +8 -9
  69. data/lib/rubocop/cop/style/leading_comment_space.rb +4 -5
  70. data/lib/rubocop/cop/style/line_end_concatenation.rb +29 -6
  71. data/lib/rubocop/cop/style/line_length.rb +9 -9
  72. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +7 -6
  73. data/lib/rubocop/cop/style/module_function.rb +3 -4
  74. data/lib/rubocop/cop/style/multiline_if_then.rb +3 -3
  75. data/lib/rubocop/cop/style/negated_if.rb +2 -0
  76. data/lib/rubocop/cop/style/next.rb +80 -0
  77. data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
  78. data/lib/rubocop/cop/style/non_nil_check.rb +15 -3
  79. data/lib/rubocop/cop/style/not.rb +4 -4
  80. data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
  81. data/lib/rubocop/cop/style/op_method.rb +3 -5
  82. data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
  83. data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -6
  84. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -5
  85. data/lib/rubocop/cop/style/predicate_name.rb +2 -4
  86. data/lib/rubocop/cop/style/redundant_self.rb +11 -12
  87. data/lib/rubocop/cop/style/self_assignment.rb +8 -13
  88. data/lib/rubocop/cop/style/semicolon.rb +16 -19
  89. data/lib/rubocop/cop/style/signal_exception.rb +10 -11
  90. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -3
  91. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  92. data/lib/rubocop/cop/style/space_after_colon.rb +9 -9
  93. data/lib/rubocop/cop/style/space_after_control_keyword.rb +3 -3
  94. data/lib/rubocop/cop/style/space_after_method_name.rb +3 -3
  95. data/lib/rubocop/cop/style/space_after_not.rb +3 -4
  96. data/lib/rubocop/cop/style/space_around_operators.rb +5 -4
  97. data/lib/rubocop/cop/style/space_before_comment.rb +29 -0
  98. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -7
  99. data/lib/rubocop/cop/style/symbol_array.rb +2 -3
  100. data/lib/rubocop/cop/style/tab.rb +8 -8
  101. data/lib/rubocop/cop/style/trailing_blank_lines.rb +10 -10
  102. data/lib/rubocop/cop/style/trailing_whitespace.rb +6 -7
  103. data/lib/rubocop/cop/style/trivial_accessors.rb +3 -4
  104. data/lib/rubocop/cop/style/unless_else.rb +2 -3
  105. data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -3
  106. data/lib/rubocop/cop/style/unneeded_percent_x.rb +26 -0
  107. data/lib/rubocop/cop/style/when_then.rb +3 -3
  108. data/lib/rubocop/cop/style/while_until_do.rb +3 -6
  109. data/lib/rubocop/cop/style/word_array.rb +8 -7
  110. data/lib/rubocop/cop/team.rb +9 -11
  111. data/lib/rubocop/cop/util.rb +2 -3
  112. data/lib/rubocop/cop/variable_force.rb +2 -3
  113. data/lib/rubocop/cop/variable_force/variable_table.rb +1 -2
  114. data/lib/rubocop/file_inspector.rb +5 -0
  115. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -4
  116. data/lib/rubocop/formatter/disabled_config_formatter.rb +6 -6
  117. data/lib/rubocop/options.rb +14 -11
  118. data/lib/rubocop/target_finder.rb +12 -1
  119. data/lib/rubocop/version.rb +1 -1
  120. data/relnotes/v0.21.0.md +11 -0
  121. data/relnotes/v0.22.0.md +77 -0
  122. data/spec/rubocop/cli_spec.rb +86 -40
  123. data/spec/rubocop/comment_config_spec.rb +1 -1
  124. data/spec/rubocop/config_loader_spec.rb +3 -3
  125. data/spec/rubocop/config_spec.rb +14 -3
  126. data/spec/rubocop/cop/force_spec.rb +1 -1
  127. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +164 -99
  128. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +195 -85
  129. data/spec/rubocop/cop/lint/void_spec.rb +8 -0
  130. data/spec/rubocop/cop/rails/delegate_spec.rb +17 -0
  131. data/spec/rubocop/cop/rails/output_spec.rb +3 -3
  132. data/spec/rubocop/cop/severity_spec.rb +5 -5
  133. data/spec/rubocop/cop/style/align_parameters_spec.rb +108 -0
  134. data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
  135. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +12 -10
  136. data/spec/rubocop/cop/style/comment_indentation_spec.rb +174 -0
  137. data/spec/rubocop/cop/style/each_with_object_spec.rb +44 -0
  138. data/spec/rubocop/cop/style/end_of_line_spec.rb +3 -5
  139. data/spec/rubocop/cop/style/guard_clause_spec.rb +135 -57
  140. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +7 -7
  141. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +75 -1
  142. data/spec/rubocop/cop/style/line_length_spec.rb +7 -7
  143. data/spec/rubocop/cop/style/negated_if_spec.rb +5 -1
  144. data/spec/rubocop/cop/style/next_spec.rb +210 -0
  145. data/spec/rubocop/cop/style/non_nil_check_spec.rb +44 -13
  146. data/spec/rubocop/cop/style/self_assignment_spec.rb +1 -1
  147. data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
  148. data/spec/rubocop/cop/style/space_before_comment_spec.rb +34 -0
  149. data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +34 -0
  150. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +2 -2
  151. data/spec/rubocop/cop/util_spec.rb +2 -2
  152. data/spec/rubocop/cop/variable_force_spec.rb +1 -1
  153. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +4 -4
  154. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +2 -2
  155. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +2 -2
  156. data/spec/rubocop/options_spec.rb +3 -0
  157. data/spec/support/shared_context.rb +1 -3
  158. data/spec/support/statement_modifier_helper.rb +2 -2
  159. metadata +20 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18bb71a6ddd6cdd142c68e789a70b0baf5704d79
4
- data.tar.gz: f239d5e80896196e17211fa6834e3d7a261cb0e7
3
+ metadata.gz: 0005c0b6b6a9b9ee4037110fd8e9c71b9d79092b
4
+ data.tar.gz: 8d5bea9be330a3728f0f08d5025affc7d564e020
5
5
  SHA512:
6
- metadata.gz: 1bac37f99223a0c20c2e7ba29c4dbbc1fc907962102962679153f6a55c5f1b1a5bdb2d482029aef3b7abf63242a31ebce47be9ea55f40ba3ccb858bf8951f69e
7
- data.tar.gz: acf9e58f556f5fcc298584233e2ed12afc8ebe7f434fc7a0ac747a5f0cb1ef1579d5d14e9e4dad065eec13c9e3d39bd103b85790d4ce455f92f6210f026d1650
6
+ metadata.gz: fb25af1b50520d4c56c98958e653b5a963444d678e31754a362ae174946112420511575936b0dc6ce1fd3fcaa4eb80af1e996f856922403f1bc219f4c1fb2b76
7
+ data.tar.gz: 6b946667153c827780d2df4c7e315c063b3a5c2b4d72417e7578c6034ee981a47065dfc941dffa5494ccf88835a24887663dd93106062a6903c8fa0ea7ad0b93
data/.rubocop.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  # This is the configuration used to check the rubocop source code.
2
2
 
3
- inherit_from: rubocop-todo.yml
3
+ inherit_from: .rubocop_todo.yml
@@ -1,20 +1,20 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2014-04-06 16:06:47 +0200 using RuboCop version 0.20.1.
2
+ # on 2014-04-29 22:57:01 +0200 using RuboCop version 0.21.0.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
- # Offense count: 8
8
+ # Offense count: 7
9
9
  # Configuration parameters: CountComments.
10
10
  ClassLength:
11
- Max: 121
11
+ Max: 119
12
12
 
13
- # Offense count: 22
13
+ # Offense count: 24
14
14
  CyclomaticComplexity:
15
15
  Max: 10
16
16
 
17
- # Offense count: 115
17
+ # Offense count: 114
18
18
  # Configuration parameters: CountComments.
19
19
  MethodLength:
20
20
  Max: 20
data/CHANGELOG.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.22.0 (20/04/2014)
6
+
7
+ ### New features
8
+
9
+ * [#974](https://github.com/bbatsov/rubocop/pull/974): New cop `CommentIndentation` checks indentation of comments. ([@jonas054][])
10
+ * Add new cop `EachWithObject` to prefer `each_with_object` over `inject` or `reduce`. ([@geniou][])
11
+ * [#1010](https://github.com/bbatsov/rubocop/issues/1010): New Cop `Next` check for conditions at the end of an interation and propose to use `next` instead. ([@geniou][])
12
+ * The `GuardClause` cop now also looks for unless and it is configurable how many lines the body of an if / unless needs to have to not be ignored. ([@geniou][])
13
+ * [#835](https://github.com/bbatsov/rubocop/issues/835): New cop `UnneededPercentX` checks for `%x` when backquotes would do. ([@jonas054][])
14
+ * Add auto-correct to `UnusedBlockArgument` and `UnusedMethodArgument` cops. ([@hannestyden][])
15
+ * [#1074](https://github.com/bbatsov/rubocop/issues/1074): New cop `SpaceBeforeComment` checks for missing space between code and a comment on the same line. ([@jonas054][])
16
+ * [#1089](https://github.com/bbatsov/rubocop/pull/1089): New option `-F`/`--fail-fast` inspects files in modification time order and stop after the first file with offenses. ([@jonas054][])
17
+
18
+ ### Changes
19
+
20
+ * `NonNilCheck` offense reporting and autocorrect are configurable to include semantic changes. ([@hannestyden][])
21
+ * The parameters `AllCops/Excludes` and `AllCops/Includes` with final `s` only give a warning and don't halt `rubocop` execution. ([@jonas054][])
22
+ * The `GuardClause` cop is no longer irgnoring a one-line body by default - see configuration. ([@geniou][])
23
+ * [#1050](https://github.com/bbatsov/rubocop/issues/1050): Rename `rubocop-todo.yml` file to `.rubocop_todo.yml`. ([@geniou][])
24
+ * [#1064](https://github.com/bbatsov/rubocop/issues/1064): Adjust default max line length to 80. ([@bbatsov][])
25
+
26
+ ### Bugs fixed
27
+
28
+ * Allow assignment in `AlignParameters` cop. ([@tommeier][])
29
+ * Fix `Void` and `SpaceAroundOperators` for short call syntax `lambda.()`. ([@biinari][])
30
+ * Fix `Delegate` for delegation with assignment or constant. ([@geniou][])
31
+ * [#1032](https://github.com/bbatsov/rubocop/issues/1032): Avoid duplicate reporting when code moves around due to `--auto-correct`. ([@jonas054][])
32
+ * [#1036](https://github.com/bbatsov/rubocop/issues/1036): Handle strings like `__FILE__` in `LineEndConcatenation`. ([@bbatsov][])
33
+ * [#1006](https://github.com/bbatsov/rubocop/issues/1006): Fix LineEndConcatenation to handle chained concatenations. ([@barunio][])
34
+ * [#1066](https://github.com/bbatsov/rubocop/issues/1066): Fix auto-correct for `NegatedIf` when the condition has parentheses around it. ([@jonas054][])
35
+ * Fix `AlignParameters` `with_fixed_indentation` for multi-line method calls. ([@molawson][])
36
+ * Fix problem that appears in some installations when reading empty YAML files. ([@jonas054][])
37
+ * [#1022](https://github.com/bbatsov/rubocop/issues/1022): A Cop will no longer auto-correct a file that's excluded through an `Exclude` setting in the cop's configuration. ([@jonas054][])
38
+ * Fix paths in `Exclude` config section not being recognized on Windows. ([@wndhydrnt][])
39
+ * [#1094](https://github.com/bbatsov/rubocop/issues/1094): Fix ClassAndModuleChildren for classes with a single method. ([@geniou][])
40
+
5
41
  ## 0.21.0 (24/04/2014)
6
42
 
7
43
  ### New features
@@ -894,4 +930,9 @@
894
930
  [@bquorning]: https://github.com/bquorning
895
931
  [@bcobb]: https://github.com/bcobb
896
932
  [@irrationalfab]: https://github.com/irrationalfab
933
+ [@tommeier]: https://github.com/tommeier
897
934
  [@sfeldon]: https://github.com/sfeldon
935
+ [@biinari]: https://github.com/biinari
936
+ [@barunio]: https://github.com/barunio
937
+ [@molawson]: https://github.com/molawson
938
+ [@wndhydrnt]: https://github.com/wndhydrnt
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- [![Gem Version](https://badge.fury.io/rb/rubocop.png)](http://badge.fury.io/rb/rubocop)
2
- [![Dependency Status](https://gemnasium.com/bbatsov/rubocop.png)](https://gemnasium.com/bbatsov/rubocop)
3
- [![Build Status](https://travis-ci.org/bbatsov/rubocop.png?branch=master)](https://travis-ci.org/bbatsov/rubocop)
1
+ [![Gem Version](https://badge.fury.io/rb/rubocop.svg)](http://badge.fury.io/rb/rubocop)
2
+ [![Dependency Status](https://gemnasium.com/bbatsov/rubocop.svg)](https://gemnasium.com/bbatsov/rubocop)
3
+ [![Build Status](https://travis-ci.org/bbatsov/rubocop.svg?branch=master)](https://travis-ci.org/bbatsov/rubocop)
4
4
  [![Coverage Status](https://coveralls.io/repos/bbatsov/rubocop/badge.png?branch=master)](https://coveralls.io/r/bbatsov/rubocop)
5
5
  [![Code Climate](https://codeclimate.com/github/bbatsov/rubocop.png)](https://codeclimate.com/github/bbatsov/rubocop)
6
- [![Inline docs](http://inch-pages.github.io/github/bbatsov/rubocop.png)](http://inch-pages.github.io/github/bbatsov/rubocop)
6
+ [![Inline docs](http://inch-pages.github.io/github/bbatsov/rubocop.svg)](http://inch-pages.github.io/github/bbatsov/rubocop)
7
7
 
8
8
  # RuboCop
9
9
 
@@ -129,6 +129,7 @@ Command flag | Description
129
129
  --------------------------|------------------------------------------------------------
130
130
  `-v/--version` | Displays the current version and exits
131
131
  `-V/--verbose-version` | Displays the current version plus the version of Parser and Ruby
132
+ `-F/--fail-fast` | Inspects in modification time order and stops after first file with offenses
132
133
  `-d/--debug` | Displays some extra debug output
133
134
  `-D/--display-cop-names` | Displays cop names in offense messages.
134
135
  `-c/--config` | Run with specified config file
@@ -315,12 +316,13 @@ CyclomaticComplexity:
315
316
 
316
317
  ### Automatically Generated Configuration
317
318
 
318
- If you have a code base with an overwhelming amount of offenses, it can be a
319
- good idea to use `rubocop --auto-gen-config` and add an `inherit_from:
320
- rubocop-todo.yml` in your `.rubocop.yml`. The generated file `rubocop-todo.yml`
321
- contains configuration to disable all cops that currently detect an offense in
322
- the code. Then you can start removing the entries in the generated file one by
323
- one as you work through all the offenses in the code.
319
+ If you have a code base with an overwhelming amount of offenses, it can
320
+ be a good idea to use `rubocop --auto-gen-config` and add an
321
+ `inherit_from: .rubocop_todo.yml` in your `.rubocop.yml`. The generated
322
+ file `.rubocop_todo.yml` contains configuration to disable all cops that
323
+ currently detect an offense in the code. Then you can start removing the
324
+ entries in the generated file one by one as you work through all the
325
+ offenses in the code.
324
326
 
325
327
  ## Disabling Cops within Source Code
326
328
 
@@ -510,7 +512,7 @@ The JSON structure is like the following example:
510
512
  "path": "lib/bar.rb",
511
513
  "offenses": [{
512
514
  "severity": "convention",
513
- "message": "Line is too long. [81/79]",
515
+ "message": "Line is too long. [81/80]",
514
516
  "cop_name": "LineLength",
515
517
  "corrected": true,
516
518
  "location": {
@@ -721,12 +723,20 @@ priority right now. Writing a new cop is a great way to dive into RuboCop!
721
723
  Of course, bug reports and suggestions for improvements are always
722
724
  welcome. GitHub pull requests are even better! :-)
723
725
 
726
+ I'm also accepting financial contributions via [gittip](https://www.gittip.com/bbatsov).
727
+
728
+ [![Support via Gittip](https://rawgithub.com/twolfson/gittip-badge/0.2.0/dist/gittip.png)](https://www.gittip.com/bbatsov)
729
+
724
730
  ## Mailing List
725
731
 
726
732
  If you're interested in everything regarding RuboCop's development,
727
733
  consider joining its
728
734
  [Google Group](https://groups.google.com/forum/?fromgroups#!forum/rubocop).
729
735
 
736
+ ## Freenode
737
+
738
+ If you're into IRC you can visit the `#rubocop` channel on Freenode.
739
+
730
740
  ## Changelog
731
741
 
732
742
  RuboCop's changelog is available [here](CHANGELOG.md).
data/config/default.yml CHANGED
@@ -12,7 +12,7 @@ AllCops:
12
12
  - '**/*.gemspec'
13
13
  - '**/Rakefile'
14
14
  Exclude:
15
- - 'vendor/**'
15
+ - 'vendor/**/*'
16
16
  # By default, the rails cops are not run. Override in project or home
17
17
  # directory .rubocop.yml files, or by giving the -R/--rails option.
18
18
  RunRailsCops: false
@@ -54,7 +54,7 @@ AlignHash:
54
54
  # inspected? Valid values are:
55
55
  #
56
56
  # always_inspect - Inspect both implicit and explicit hashes.
57
- # Registers and offence for:
57
+ # Registers an offence for:
58
58
  # function(a: 1,
59
59
  # b: 2)
60
60
  # Registers an offence for:
@@ -67,14 +67,14 @@ AlignHash:
67
67
  # Accepts:
68
68
  # function({a: 1,
69
69
  # b: 2})
70
- # ignore_implicit - Ingore only implicit hashes.
70
+ # ignore_implicit - Ignore only implicit hashes.
71
71
  # Accepts:
72
72
  # function(a: 1,
73
73
  # b: 2)
74
74
  # Registers an offence for:
75
75
  # function({a: 1,
76
76
  # b: 2})
77
- # ignore_explicit - Ingore only explicit hashes.
77
+ # ignore_explicit - Ignore only explicit hashes.
78
78
  # Accepts:
79
79
  # function({a: 1,
80
80
  # b: 2})
@@ -97,8 +97,8 @@ AlignParameters:
97
97
  # method_call(a,
98
98
  # b)
99
99
  #
100
- # The `with_fixed_indentation` style alignes the following lines with one
101
- # level of indenation relative to the start of the line with the method call.
100
+ # The `with_fixed_indentation` style aligns the following lines with one
101
+ # level of indentation relative to the start of the line with the method call.
102
102
  #
103
103
  # method_call(a,
104
104
  # b)
@@ -133,7 +133,7 @@ ClassAndModuleChildren:
133
133
  #
134
134
  # Basically there are two different styles:
135
135
  #
136
- # `nested` - have each child on a separat line
136
+ # `nested` - have each child on a separate line
137
137
  # class Foo
138
138
  # class Bar
139
139
  # end
@@ -238,6 +238,11 @@ FormatString:
238
238
  GlobalVars:
239
239
  AllowedVariables: []
240
240
 
241
+ # `MinBodyLength` defines the number of lines of the a body of an if / unless
242
+ # needs to have to trigger this cop
243
+ GuardClause:
244
+ MinBodyLength: 1
245
+
241
246
  HashSyntax:
242
247
  EnforcedStyle: ruby19
243
248
  SupportedStyles:
@@ -245,7 +250,7 @@ HashSyntax:
245
250
  - hash_rockets
246
251
 
247
252
  IfUnlessModifier:
248
- MaxLineLength: 79
253
+ MaxLineLength: 80
249
254
 
250
255
  # Checks the indentation of the first key in a hash literal.
251
256
  IndentHash:
@@ -268,7 +273,25 @@ LambdaCall:
268
273
  - braces
269
274
 
270
275
  LineLength:
271
- Max: 79
276
+ Max: 80
277
+
278
+ Next:
279
+ # With `always` all conditions at the end of an iteration needs to be
280
+ # replace by next - with `skip_modifier_ifs` the modifier if like this one
281
+ # are ignored: [1, 2].each { |a| return 'yes' if a == 1 }
282
+ EnforcedStyle: skip_modifier_ifs
283
+ SupportedStyles:
284
+ - skip_modifier_ifs
285
+ - always
286
+
287
+ NonNilCheck:
288
+ # With `IncludeSemanticChanges` set to `true`, this cop reports offences for
289
+ # `!x.nil?` and autocorrects that and `x != nil` to solely `x`, which is
290
+ # **usually** OK, but might change behavior.
291
+ #
292
+ # With `IncludeSemanticChanges` set to `false`, this cop does not report
293
+ # offences for `!x.nil?` and does no changes that might change behavior.
294
+ IncludeSemanticChanges: false
272
295
 
273
296
  MethodDefParentheses:
274
297
  EnforcedStyle: require_parentheses
@@ -442,7 +465,7 @@ VariableName:
442
465
  - camelCase
443
466
 
444
467
  WhileUntilModifier:
445
- MaxLineLength: 79
468
+ MaxLineLength: 80
446
469
 
447
470
  WordArray:
448
471
  MinSize: 0
data/config/disabled.yml CHANGED
@@ -1,9 +1,5 @@
1
1
  # These are all the cops that are disabled in the default configuration.
2
2
 
3
- GuardClause:
4
- Description: 'Check for conditionals that can be replaced with guard clauses'
5
- Enabled: false
6
-
7
3
  MethodCalledOnDoEndBlock:
8
4
  Description: 'Avoid chaining a method call on a do...end block.'
9
5
  Enabled: false
data/config/enabled.yml CHANGED
@@ -119,6 +119,10 @@ CommentAnnotation:
119
119
  (TODO, FIXME, OPTIMIZE, HACK, REVIEW).
120
120
  Enabled: true
121
121
 
122
+ CommentIndentation:
123
+ Description: 'Indentation of comments.'
124
+ Enabled: true
125
+
122
126
  ConstantName:
123
127
  Description: 'Constants should use SCREAMING_SNAKE_CASE.'
124
128
  Enabled: true
@@ -151,6 +155,10 @@ DoubleNegation:
151
155
  Description: 'Checks for uses of double negation (!!).'
152
156
  Enabled: true
153
157
 
158
+ EachWithObject:
159
+ Description: 'Prefer `each_with_object` over `inject` or `reduce`.'
160
+ Enabled: true
161
+
154
162
  EmptyLineBetweenDefs:
155
163
  Description: 'Use empty lines between defs.'
156
164
  Enabled: true
@@ -260,7 +268,7 @@ LineEndConcatenation:
260
268
  Enabled: true
261
269
 
262
270
  LineLength:
263
- Description: 'Limit lines to 79 characters.'
271
+ Description: 'Limit lines to 80 characters.'
264
272
  Enabled: true
265
273
 
266
274
  MethodCallParentheses:
@@ -313,6 +321,10 @@ NestedTernaryOperator:
313
321
  Description: 'Use one expression per branch in a ternary operator.'
314
322
  Enabled: true
315
323
 
324
+ Next:
325
+ Description: 'Use `next` to skip iteration instead of a condition at the end.'
326
+ Enabled: true
327
+
316
328
  NilComparison:
317
329
  Description: 'Prefer x.nil? to x == nil.'
318
330
  Enabled: true
@@ -457,6 +469,12 @@ SpaceBeforeBlockBraces:
457
469
  before it.
458
470
  Enabled: true
459
471
 
472
+ SpaceBeforeComment:
473
+ Description: >-
474
+ Checks for missing space between code and a comment on the
475
+ same line.
476
+ Enabled: true
477
+
460
478
  SpaceInsideBlockBraces:
461
479
  Description: >-
462
480
  Checks that block braces have or don't have surrounding space.
@@ -529,6 +547,10 @@ UnneededCapitalW:
529
547
  Description: 'Checks for %W when interpolation is not needed.'
530
548
  Enabled: true
531
549
 
550
+ UnneededPercentX:
551
+ Description: 'Checks for %x when `` would do.'
552
+ Enabled: true
553
+
532
554
  VariableInterpolation:
533
555
  Description: >-
534
556
  Don't interpolate global, instance and class variables
@@ -620,6 +642,10 @@ Eval:
620
642
  Description: 'The use of eval represents a serious security risk.'
621
643
  Enabled: true
622
644
 
645
+ GuardClause:
646
+ Description: 'Check for conditionals that can be replaced with guard clauses'
647
+ Enabled: true
648
+
623
649
  HandleExceptions:
624
650
  Description: "Don't suppress exception."
625
651
  Enabled: true
data/lib/rubocop.rb CHANGED
@@ -1,6 +1,16 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'parser/current'
3
+ # Try to load the latest parser and fall back to the latest supported version,
4
+ # if parser does not yet support the current Ruby version.
5
+ # This should only be problem when using development Ruby builds.
6
+ begin
7
+ require 'parser/current'
8
+ rescue NotImplementedError => error
9
+ warn "Falling back to Ruby 2.1 parser: #{error.message}"
10
+ require 'parser/ruby21'
11
+ Parser::CurrentRuby = Parser::Ruby21
12
+ end
13
+
4
14
  require 'rainbow'
5
15
  # Rainbow 2.0 does not load the monkey-patch for String by default.
6
16
  require 'rainbow/ext/string' unless String.method_defined?(:color)
@@ -56,6 +66,7 @@ require 'rubocop/cop/mixin/space_inside'
56
66
  require 'rubocop/cop/mixin/space_after_punctuation'
57
67
  require 'rubocop/cop/mixin/statement_modifier'
58
68
  require 'rubocop/cop/mixin/string_help'
69
+ require 'rubocop/cop/mixin/unused_argument'
59
70
 
60
71
  require 'rubocop/cop/lint/ambiguous_operator'
61
72
  require 'rubocop/cop/lint/ambiguous_regexp_literal'
@@ -121,6 +132,7 @@ require 'rubocop/cop/style/class_vars'
121
132
  require 'rubocop/cop/style/collection_methods'
122
133
  require 'rubocop/cop/style/colon_method_call'
123
134
  require 'rubocop/cop/style/comment_annotation'
135
+ require 'rubocop/cop/style/comment_indentation'
124
136
  require 'rubocop/cop/style/constant_name'
125
137
  require 'rubocop/cop/style/cyclomatic_complexity'
126
138
  require 'rubocop/cop/style/def_with_parentheses'
@@ -128,6 +140,7 @@ require 'rubocop/cop/style/deprecated_hash_methods'
128
140
  require 'rubocop/cop/style/documentation'
129
141
  require 'rubocop/cop/style/dot_position'
130
142
  require 'rubocop/cop/style/double_negation'
143
+ require 'rubocop/cop/style/each_with_object'
131
144
  require 'rubocop/cop/style/empty_line_between_defs'
132
145
  require 'rubocop/cop/style/empty_lines'
133
146
  require 'rubocop/cop/style/empty_lines_around_access_modifier'
@@ -167,6 +180,7 @@ require 'rubocop/cop/style/multiline_ternary_operator'
167
180
  require 'rubocop/cop/style/negated_if'
168
181
  require 'rubocop/cop/style/negated_while'
169
182
  require 'rubocop/cop/style/nested_ternary_operator'
183
+ require 'rubocop/cop/style/next'
170
184
  require 'rubocop/cop/style/nil_comparison'
171
185
  require 'rubocop/cop/style/non_nil_check'
172
186
  require 'rubocop/cop/style/not'
@@ -201,6 +215,7 @@ require 'rubocop/cop/style/space_after_semicolon'
201
215
  require 'rubocop/cop/style/space_around_equals_in_parameter_default'
202
216
  require 'rubocop/cop/style/space_around_operators'
203
217
  require 'rubocop/cop/style/space_before_block_braces'
218
+ require 'rubocop/cop/style/space_before_comment'
204
219
  require 'rubocop/cop/style/space_before_modifier_keyword'
205
220
  require 'rubocop/cop/style/space_inside_block_braces'
206
221
  require 'rubocop/cop/style/space_inside_brackets'
@@ -216,6 +231,7 @@ require 'rubocop/cop/style/trailing_whitespace'
216
231
  require 'rubocop/cop/style/trivial_accessors'
217
232
  require 'rubocop/cop/style/unless_else'
218
233
  require 'rubocop/cop/style/unneeded_capital_w'
234
+ require 'rubocop/cop/style/unneeded_percent_x'
219
235
  require 'rubocop/cop/style/variable_interpolation'
220
236
  require 'rubocop/cop/style/variable_name'
221
237
  require 'rubocop/cop/style/when_then'
@@ -25,36 +25,42 @@ module Rubocop
25
25
  end
26
26
 
27
27
  def make_excludes_absolute
28
- if self['AllCops'] && self['AllCops']['Exclude']
29
- self['AllCops']['Exclude'].map! do |exclude_elem|
30
- if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
31
- File.join(base_dir_for_path_parameters, exclude_elem)
32
- else
33
- exclude_elem
34
- end
28
+ return unless self['AllCops'] && self['AllCops']['Exclude']
29
+
30
+ self['AllCops']['Exclude'].map! do |exclude_elem|
31
+ if exclude_elem.is_a?(String) && !exclude_elem.start_with?('/')
32
+ File.join(base_dir_for_path_parameters, exclude_elem)
33
+ else
34
+ exclude_elem
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
39
  def add_excludes_from_higher_level(highest_config)
40
- if highest_config['AllCops'] && highest_config['AllCops']['Exclude']
41
- self['AllCops'] ||= {}
42
- excludes = self['AllCops']['Exclude'] ||= []
43
- highest_config['AllCops']['Exclude'].each do |path|
44
- unless path.is_a?(Regexp) || path.start_with?('/')
45
- path = File.join(File.dirname(highest_config.loaded_path), path)
46
- end
47
- excludes << path unless excludes.include?(path)
40
+ return unless highest_config['AllCops'] &&
41
+ highest_config['AllCops']['Exclude']
42
+
43
+ self['AllCops'] ||= {}
44
+ excludes = self['AllCops']['Exclude'] ||= []
45
+ highest_config['AllCops']['Exclude'].each do |path|
46
+ unless path.is_a?(Regexp) || path.start_with?('/')
47
+ path = File.join(File.dirname(highest_config.loaded_path), path)
48
48
  end
49
+ excludes << path unless excludes.include?(path)
49
50
  end
50
51
  end
51
52
 
52
53
  def deprecation_check
53
- return unless self['AllCops']
54
- if self['AllCops']['Excludes']
55
- yield 'AllCops/Excludes was renamed to AllCops/Exclude'
56
- elsif self['AllCops']['Includes']
57
- yield 'AllCops/Includes was renamed to AllCops/Include'
54
+ all_cops = self['AllCops']
55
+ return unless all_cops
56
+
57
+ %w(Exclude Include).each do |key|
58
+ plural = "#{key}s"
59
+ next unless all_cops[plural]
60
+
61
+ all_cops[key] = all_cops[plural] # Stay backwards compatible.
62
+ all_cops.delete(plural)
63
+ yield "AllCops/#{plural} was renamed to AllCops/#{key}"
58
64
  end
59
65
  end
60
66
 
@@ -91,12 +97,12 @@ module Rubocop
91
97
 
92
98
  valid_cop_names.each do |name|
93
99
  @hash[name].each_key do |param|
94
- unless COMMON_PARAMS.include?(param) ||
95
- default_config[name].key?(param)
96
- fail ValidationError,
97
- "unrecognized parameter #{name}:#{param} found " \
98
- "in #{loaded_path || self}"
99
- end
100
+ next if COMMON_PARAMS.include?(param) ||
101
+ default_config[name].key?(param)
102
+
103
+ fail ValidationError,
104
+ "unrecognized parameter #{name}:#{param} found " \
105
+ "in #{loaded_path || self}"
100
106
  end
101
107
  end
102
108
  end
@@ -109,7 +115,6 @@ module Rubocop
109
115
  end
110
116
 
111
117
  def file_to_exclude?(file)
112
- file = File.join(Dir.pwd, file) unless file.start_with?('/')
113
118
  file = File.expand_path(file)
114
119
  patterns_to_exclude.any? do |pattern|
115
120
  match_path?(pattern, file, loaded_path)