rubocop 0.27.1 → 0.28.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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -4
  3. data/Gemfile +1 -1
  4. data/README.md +16 -1
  5. data/config/default.yml +15 -1
  6. data/config/disabled.yml +5 -0
  7. data/config/enabled.yml +10 -2
  8. data/lib/rubocop.rb +3 -0
  9. data/lib/rubocop/config.rb +1 -1
  10. data/lib/rubocop/cop/mixin/access_modifier_node.rb +2 -2
  11. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +10 -26
  12. data/lib/rubocop/cop/mixin/on_method_def.rb +1 -1
  13. data/lib/rubocop/cop/mixin/string_help.rb +10 -1
  14. data/lib/rubocop/cop/style/align_hash.rb +2 -2
  15. data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
  16. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +21 -19
  17. data/lib/rubocop/cop/style/else_alignment.rb +29 -16
  18. data/lib/rubocop/cop/style/empty_else.rb +47 -0
  19. data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +38 -0
  20. data/lib/rubocop/cop/style/extra_spacing.rb +35 -0
  21. data/lib/rubocop/cop/style/indentation_width.rb +1 -1
  22. data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
  23. data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -1
  24. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +20 -4
  25. data/lib/rubocop/cop/style/negated_while.rb +3 -1
  26. data/lib/rubocop/cop/style/perl_backrefs.rb +8 -3
  27. data/lib/rubocop/cop/style/single_line_block_params.rb +7 -1
  28. data/lib/rubocop/cop/style/special_global_vars.rb +8 -3
  29. data/lib/rubocop/cop/style/string_literals.rb +4 -11
  30. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +2 -7
  31. data/lib/rubocop/cop/style/symbol_proc.rb +14 -6
  32. data/lib/rubocop/cop/style/unneeded_capital_w.rb +2 -1
  33. data/lib/rubocop/cop/util.rb +1 -1
  34. data/lib/rubocop/cop/variable_force.rb +3 -3
  35. data/lib/rubocop/cop/variable_force/scope.rb +1 -1
  36. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  37. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  38. data/lib/rubocop/options.rb +13 -6
  39. data/lib/rubocop/rake_task.rb +0 -1
  40. data/lib/rubocop/runner.rb +19 -6
  41. data/lib/rubocop/target_finder.rb +32 -1
  42. data/lib/rubocop/version.rb +1 -1
  43. data/relnotes/v0.28.0.md +90 -0
  44. data/spec/project_spec.rb +1 -0
  45. data/spec/rubocop/cli_spec.rb +115 -24
  46. data/spec/rubocop/comment_config_spec.rb +1 -1
  47. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +0 -1
  48. data/spec/rubocop/cop/lint/block_alignment_spec.rb +4 -4
  49. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +1 -1
  50. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +2 -3
  51. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +1 -1
  52. data/spec/rubocop/cop/lint/void_spec.rb +0 -1
  53. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +2 -2
  54. data/spec/rubocop/cop/style/blocks_spec.rb +8 -0
  55. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +196 -215
  56. data/spec/rubocop/cop/style/case_indentation_spec.rb +4 -4
  57. data/spec/rubocop/cop/style/documentation_spec.rb +0 -1
  58. data/spec/rubocop/cop/style/else_alignment_spec.rb +63 -4
  59. data/spec/rubocop/cop/style/empty_else_spec.rb +100 -0
  60. data/spec/rubocop/cop/style/empty_lines_around_block_body_spec.rb +103 -0
  61. data/spec/rubocop/cop/style/empty_lines_around_method_body_spec.rb +1 -1
  62. data/spec/rubocop/cop/style/end_of_line_spec.rb +2 -2
  63. data/spec/rubocop/cop/style/extra_spacing_spec.rb +68 -0
  64. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +5 -0
  65. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +8 -0
  66. data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +35 -2
  67. data/spec/rubocop/cop/style/negated_if_spec.rb +1 -1
  68. data/spec/rubocop/cop/style/negated_while_spec.rb +5 -3
  69. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +1 -1
  70. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +5 -0
  71. data/spec/rubocop/cop/style/signal_exception_spec.rb +0 -1
  72. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +13 -1
  73. data/spec/rubocop/cop/style/special_global_vars_spec.rb +5 -0
  74. data/spec/rubocop/cop/style/string_literals_spec.rb +11 -1
  75. data/spec/rubocop/cop/style/symbol_proc_spec.rb +20 -1
  76. data/spec/rubocop/cop/style/tab_spec.rb +2 -2
  77. data/spec/rubocop/cop/style/trailing_comma_spec.rb +1 -1
  78. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +5 -0
  79. data/spec/rubocop/cop/team_spec.rb +2 -2
  80. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +0 -1
  81. data/spec/rubocop/options_spec.rb +2 -0
  82. data/spec/rubocop/target_finder_spec.rb +23 -2
  83. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31c46dfc62c89c6d6c760fca39e95d4ddbc6d86a
4
- data.tar.gz: a341a023513b18cf578c889b4f563e656ce0d762
3
+ metadata.gz: 5d09cfe000191e9a91719f1f3a75d401d97dcec7
4
+ data.tar.gz: a4528c98896b1d0330be5138b4509ccabb0bf0cc
5
5
  SHA512:
6
- metadata.gz: d924beb2cc52e477d0a9283cb23ffd269e64236c3ed454e29069c7f6eac037ecf512b8a670732c6dbb8335323f3c0aa527e169fc4b2abc24ec444f804689c628
7
- data.tar.gz: 3494d55e372c564d29f33cfe6fe6af6d6071262ba5bd80298a735d7963f1accd84c769716c688b21489bf47325e804b0e1a8a2c3b4afc34f3263b7107a4da0a3
6
+ metadata.gz: b51f275c969f27f455f3f14e260452a7f52b8142cb0389020dddb1391ae61dd22f320658fdb20f041210dec8aa9513113981fd1a8913dcc90b91b65d32e8a5a2
7
+ data.tar.gz: 06784538ec77970b8f0fdd76c037d0bd6d4aa70a26f5181705f413d245e5364abf2d4d7644c769286c9f5e735f71712bfeba9e6a4b4bd5681431050dba16df71
@@ -2,6 +2,39 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.28.0 (10/12/2014)
6
+
7
+ ### New features
8
+
9
+ * New cop `ExtraSpacing` points out unnecessary spacing in files. ([@blainesch][])
10
+ * New cop `EmptyLinesAroundBlockBody` provides same functionality as the EmptyLinesAround(Class|Method|Module)Body but for blocks. ([@jcarbo][])
11
+ * New cop `Style/EmptyElse` checks for empty `else`-clauses. ([@Koronen][])
12
+ * [#1454](https://github.com/bbatsov/rubocop/issues/1454): New `--only-guide-cops` and `AllCops/StyleGuideCopsOnly` options that will only enforce cops that link to a style guide. ([@marxarelli][])
13
+
14
+ ### Changes
15
+
16
+ * [#801](https://github.com/bbatsov/rubocop/issues/801): New style `context_dependent` for `Style/BracesAroundHashParameters` looks at preceding parameter to determine if braces should be used for final parameter. ([@jonas054][])
17
+ * [#1427](https://github.com/bbatsov/rubocop/issues/1427): Excluding directories on the top level is now done earlier, so that these file trees are not searched, thus saving time when inspecting projects with many excluded files. ([@jonas054][])
18
+ * [#1325](https://github.com/bbatsov/rubocop/issues/1325): When running with `--auto-correct`, only offenses *that can not be corrected* will result in a non-zero exit code. ([@jonas054][])
19
+ * [#1445](https://github.com/bbatsov/rubocop/issues/1445): Allow sprockets directive comments (starting with `#=`) in `Style/LeadingCommentSpace`. ([@bbatsov][])
20
+
21
+ ### Bugs fixed
22
+
23
+ * Fix `%W[]` auto corrected to `%w(]`. ([@toy][])
24
+ * Fix Style/ElseAlignment Cop to find the right parent on def/rescue/else/ensure/end. ([@oneamtu][])
25
+ * [#1181](https://github.com/bbatsov/rubocop/issues/1181): *(fix again)* `Style/StringLiterals` cop stays away from strings inside interpolated expressions. ([@jonas054][])
26
+ * [#1441](https://github.com/bbatsov/rubocop/issues/1441): Correct the logic used by `Style/Blocks` and other cops to determine if an auto-correction would alter the meaning of the code. ([@jonas054][])
27
+ * [#1449](https://github.com/bbatsov/rubocop/issues/1449): Handle the case in `MultilineOperationIndentation` where instances of both correct style and unrecognized (plain wrong) style are detected during an `--auto-gen-config` run. ([@jonas054][])
28
+ * [#1456](https://github.com/bbatsov/rubocop/pull/1456): Fix autocorrect in `SymbolProc` when there are multiple offenses on the same line. ([@jcarbo][])
29
+ * [#1459](https://github.com/bbatsov/rubocop/issues/1459): Handle parenthesis around the condition in `--auto-correct` for `NegatedWhile`. ([@jonas054][])
30
+ * [#1465](https://github.com/bbatsov/rubocop/issues/1465): Fix autocorrect of code like `#$1` in `PerlBackrefs`. ([@bbatsov][])
31
+ * Fix autocorrect of code like `#$:` in `SpecialGlobalVars`. ([@bbatsov][])
32
+ * [#1466](https://github.com/bbatsov/rubocop/issues/1466): Allow leading underscore for unused parameters in `SingleLineBlockParams`. ([@jonas054][])
33
+ * [#1470](https://github.com/bbatsov/rubocop/issues/1470): Handle `elsif` + `else` in `ElseAlignment`. ([@jonas054][])
34
+ * [#1474](https://github.com/bbatsov/rubocop/issues/1474): Multiline string with both `<<` and `\` caught by `Style/LineEndConcatenation` cop. ([@katieschilling][])
35
+ * [#1485](https://github.com/bbatsov/rubocop/issues/1485): Ignore procs in `SymbolProc`. ([@bbatsov][])
36
+ * [#1473](https://github.com/bbatsov/rubocop/issues/1473): `Style/MultilineOperationIndentation` doesn't recognize assignment to array/hash element. ([@jonas054][])
37
+
5
38
  ## 0.27.1 (08/11/2014)
6
39
 
7
40
  ### Changes
@@ -97,7 +130,7 @@
97
130
  * [#1232](https://github.com/bbatsov/rubocop/issues/1232): Add EnforcedStyle option to cop `AndOr` to restrict it to conditionals. ([@vrthra][])
98
131
  * [#835](https://github.com/bbatsov/rubocop/issues/835): New cop `PercentQLiterals` checks if use of `%Q` and `%q` matches configuration. ([@jonas054][])
99
132
  * [#835](https://github.com/bbatsov/rubocop/issues/835): New cop `BarePercentLiterals` checks if usage of `%()` or `%Q()` matches configuration. ([@jonas054][])
100
- * [#1079](https://github.com/bbatsov/rubocop/pull/1079): New cop `MultilineBlockLayout` checks if a multiline block has an extpression on the same line as the start of the block. ([@barunio][])
133
+ * [#1079](https://github.com/bbatsov/rubocop/pull/1079): New cop `MultilineBlockLayout` checks if a multiline block has an expression on the same line as the start of the block. ([@barunio][])
101
134
  * [#1217](https://github.com/bbatsov/rubocop/pull/1217): `Style::EmptyLinesAroundAccessModifier` cop does auto-correction. ([@tamird][])
102
135
  * [#1220](https://github.com/bbatsov/rubocop/issues/1220): New cop `PerceivedComplexity` is similar to `CyclomaticComplexity`, but reports when methods have a high complexity for a human reader. ([@jonas054][])
103
136
  * `Debugger` cop now checks for `binding.pry_remote`. ([@yous][])
@@ -145,7 +178,7 @@
145
178
 
146
179
  * [#639](https://github.com/bbatsov/rubocop/issues/639): Support square bracket setters in `UselessSetterCall`. ([@yujinakayama][])
147
180
  * [#835](https://github.com/bbatsov/rubocop/issues/835): `UnneededCapitalW` cop does auto-correction. ([@sfeldon][])
148
- * [#1092](https://github.com/bbatsov/rubocop/issues/1092): New cop `DefEndAlignment` takes over responsibility for checkng alignment of method definition `end`s from `EndAlignment`, and is configurable. ([@jonas054][])
181
+ * [#1092](https://github.com/bbatsov/rubocop/issues/1092): New cop `DefEndAlignment` takes over responsibility for checking alignment of method definition `end`s from `EndAlignment`, and is configurable. ([@jonas054][])
149
182
  * [#1145](https://github.com/bbatsov/rubocop/issues/1145): New cop `ClassCheck` enforces consistent use of `is_a?` or `kind_of?`. ([@bbatsov][])
150
183
  * [#1161](https://github.com/bbatsov/rubocop/pull/1161): New cop `SpaceBeforeComma` detects spaces before a comma. ([@agrimm][])
151
184
  * [#1161](https://github.com/bbatsov/rubocop/pull/1161): New cop `SpaceBeforeSemicolon` detects spaces before a semicolon. ([@agrimm][])
@@ -208,7 +241,7 @@
208
241
 
209
242
  * [#974](https://github.com/bbatsov/rubocop/pull/974): New cop `CommentIndentation` checks indentation of comments. ([@jonas054][])
210
243
  * Add new cop `EachWithObject` to prefer `each_with_object` over `inject` or `reduce`. ([@geniou][])
211
- * [#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][])
244
+ * [#1010](https://github.com/bbatsov/rubocop/issues/1010): New Cop `Next` check for conditions at the end of an iteration and propose to use `next` instead. ([@geniou][])
212
245
  * 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][])
213
246
  * [#835](https://github.com/bbatsov/rubocop/issues/835): New cop `UnneededPercentX` checks for `%x` when backquotes would do. ([@jonas054][])
214
247
  * Add auto-correct to `UnusedBlockArgument` and `UnusedMethodArgument` cops. ([@hannestyden][])
@@ -220,7 +253,7 @@
220
253
 
221
254
  * `NonNilCheck` offense reporting and autocorrect are configurable to include semantic changes. ([@hannestyden][])
222
255
  * The parameters `AllCops/Excludes` and `AllCops/Includes` with final `s` only give a warning and don't halt `rubocop` execution. ([@jonas054][])
223
- * The `GuardClause` cop is no longer irgnoring a one-line body by default - see configuration. ([@geniou][])
256
+ * The `GuardClause` cop is no longer ignoring a one-line body by default - see configuration. ([@geniou][])
224
257
  * [#1050](https://github.com/bbatsov/rubocop/issues/1050): Rename `rubocop-todo.yml` file to `.rubocop_todo.yml`. ([@geniou][])
225
258
  * [#1064](https://github.com/bbatsov/rubocop/issues/1064): Adjust default max line length to 80. ([@bbatsov][])
226
259
 
@@ -1150,3 +1183,10 @@
1150
1183
  [@mvz]: https://github.com/mvz
1151
1184
  [@jfelchner]: https://github.com/jfelchner
1152
1185
  [@janraasch]: https://github.com/janraasch
1186
+ [@jcarbo]: https://github.com/jcarbo
1187
+ [@oneamtu]: https://github.com/oneamtu
1188
+ [@toy]: https://github.com/toy
1189
+ [@Koronen]: https://github.com/Koronen
1190
+ [@blainesch]: https://github.com/blainesch
1191
+ [@marxarelli]: https://github.com/marxarelli
1192
+ [@katieschilling]: https://github.com/katieschilling
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- source 'http://rubygems.org'
3
+ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
data/README.md CHANGED
@@ -55,6 +55,7 @@ release.**
55
55
  - [File List Formatter](#file-list-formatter)
56
56
  - [JSON Formatter](#json-formatter)
57
57
  - [Offense Count Formatter](#offense-count-formatter)
58
+ - [HTML Formatter](#html-formatter)
58
59
  - [Compatibility](#compatibility)
59
60
  - [Editor integration](#editor-integration)
60
61
  - [Emacs](#emacs)
@@ -64,6 +65,7 @@ release.**
64
65
  - [TextMate2](#textmate2)
65
66
  - [Atom](#atom)
66
67
  - [LightTable](#lighttable)
68
+ - [RubyMine](#rubymine)
67
69
  - [Other Editors](#other-editors)
68
70
  - [Guard integration](#guard-integration)
69
71
  - [Rake integration](#rake-integration)
@@ -612,6 +614,14 @@ $ rubocop --format offenses
612
614
  134 Total
613
615
  ```
614
616
 
617
+ ### HTML Formatter
618
+
619
+ Useful for CI environments. It will create an HTML report like [this](http://f.cl.ly/items/0M3029412x3O091a1X1R/expected.html).
620
+
621
+ ```
622
+ $ rubocop --format html -o rubocop.html
623
+ ```
624
+
615
625
  ## Compatibility
616
626
 
617
627
  RuboCop supports the following Ruby implementations:
@@ -672,6 +682,11 @@ plugin for Atom's [linter](https://github.com/AtomLinter/Linter).
672
682
  The [lt-rubocop](https://github.com/seancaffery/lt-rubocop) plugin
673
683
  provides LightTable integration.
674
684
 
685
+ ### RubyMine
686
+
687
+ The [rubocop-for-rubymine](https://github.com/sirlantis/rubocop-for-rubymine) plugin
688
+ provides basic RuboCop integration for RubyMine/IntelliJ IDEA.
689
+
675
690
  ### Other Editors
676
691
 
677
692
  Here's one great opportunity to contribute to RuboCop - implement
@@ -727,7 +742,7 @@ require:
727
742
  - rubocop-extension
728
743
  ```
729
744
 
730
- Note: The pathes are directly passed to `Kernel.require`. If your
745
+ Note: The paths are directly passed to `Kernel.require`. If your
731
746
  extension file is not in `$LOAD_PATH`, you need to specify the path as
732
747
  relative path prefixed with `./` explicitly, or absolute path.
733
748
 
@@ -139,8 +139,16 @@ Style/BarePercentLiterals:
139
139
  Style/BracesAroundHashParameters:
140
140
  EnforcedStyle: no_braces
141
141
  SupportedStyles:
142
+ # The `braces` style enforces braces around all method parameters that are
143
+ # hashes.
142
144
  - braces
145
+ # The `no_braces` style checks that the last parameter doesn't have braces
146
+ # around it.
143
147
  - no_braces
148
+ # The `context_dependent` style checks that the last parameter doesn't have
149
+ # braces around it, but requires braces if the second to last parameter is
150
+ # also a hash literal.
151
+ - context_dependent
144
152
 
145
153
  # Indentation of `when`.
146
154
  Style/CaseIndentation:
@@ -214,6 +222,12 @@ Style/EmptyLineBetweenDefs:
214
222
  # need an empty line between them.
215
223
  AllowAdjacentOneLineDefs: false
216
224
 
225
+ Style/EmptyLinesAroundBlockBody:
226
+ EnforcedStyle: no_empty_lines
227
+ SupportedStyles:
228
+ - empty_lines
229
+ - no_empty_lines
230
+
217
231
  Style/EmptyLinesAroundClassBody:
218
232
  EnforcedStyle: no_empty_lines
219
233
  SupportedStyles:
@@ -605,7 +619,7 @@ Rails/Output:
605
619
  - config/**/*.rb
606
620
  - db/**/*.rb
607
621
  - lib/**/*.rb
608
-
622
+
609
623
  Rails/ReadWriteAttribute:
610
624
  Include:
611
625
  - app/models/**/*.rb
@@ -23,3 +23,8 @@ Style/SymbolArray:
23
23
  Description: 'Use %i or %I for arrays of symbols.'
24
24
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-i'
25
25
  Enabled: false
26
+
27
+ Style/ExtraSpacing:
28
+ Description: 'Do not use unnecessary spacing.'
29
+ Enabled: false
30
+
@@ -87,7 +87,7 @@ Style/Blocks:
87
87
  Enabled: true
88
88
 
89
89
  Style/BracesAroundHashParameters:
90
- Description: 'Enforce braces style inside hash parameters.'
90
+ Description: 'Enforce braces style around hash parameters.'
91
91
  Enabled: true
92
92
 
93
93
  Style/CaseEquality:
@@ -181,6 +181,10 @@ Style/ElseAlignment:
181
181
  Description: 'Align elses and elsifs correctly.'
182
182
  Enabled: true
183
183
 
184
+ Style/EmptyElse:
185
+ Description: 'Avoid empty else-clauses.'
186
+ Enabled: true
187
+
184
188
  Style/EmptyLineBetweenDefs:
185
189
  Description: 'Use empty lines between defs.'
186
190
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods'
@@ -194,6 +198,10 @@ Style/EmptyLinesAroundAccessModifier:
194
198
  Description: "Keep blank lines around access modifiers."
195
199
  Enabled: true
196
200
 
201
+ Style/EmptyLinesAroundBlockBody:
202
+ Description: "Keeps track of empty lines around block bodies."
203
+ Enabled: true
204
+
197
205
  Style/EmptyLinesAroundClassBody:
198
206
  Description: "Keeps track of empty lines around class bodies."
199
207
  Enabled: true
@@ -742,7 +750,7 @@ Metrics/ClassLength:
742
750
 
743
751
  Metrics/CyclomaticComplexity:
744
752
  Description: >-
745
- A complexity metric that is strongy correlated to the number
753
+ A complexity metric that is strongly correlated to the number
746
754
  of test cases needed to validate a method.
747
755
  Enabled: true
748
756
 
@@ -149,9 +149,11 @@ require 'rubocop/cop/style/dot_position'
149
149
  require 'rubocop/cop/style/double_negation'
150
150
  require 'rubocop/cop/style/each_with_object'
151
151
  require 'rubocop/cop/style/else_alignment'
152
+ require 'rubocop/cop/style/empty_else'
152
153
  require 'rubocop/cop/style/empty_line_between_defs'
153
154
  require 'rubocop/cop/style/empty_lines'
154
155
  require 'rubocop/cop/style/empty_lines_around_access_modifier'
156
+ require 'rubocop/cop/style/empty_lines_around_block_body'
155
157
  require 'rubocop/cop/style/empty_lines_around_class_body'
156
158
  require 'rubocop/cop/style/empty_lines_around_method_body'
157
159
  require 'rubocop/cop/style/empty_lines_around_module_body'
@@ -160,6 +162,7 @@ require 'rubocop/cop/style/encoding'
160
162
  require 'rubocop/cop/style/end_block'
161
163
  require 'rubocop/cop/style/end_of_line'
162
164
  require 'rubocop/cop/style/even_odd'
165
+ require 'rubocop/cop/style/extra_spacing'
163
166
  require 'rubocop/cop/style/file_name'
164
167
  require 'rubocop/cop/style/flip_flop'
165
168
  require 'rubocop/cop/style/for'
@@ -92,7 +92,7 @@ module RuboCop
92
92
 
93
93
  # TODO: This should be a private method
94
94
  def validate
95
- # Don't validate RuboCop's own files. Avoids inifinite recursion.
95
+ # Don't validate RuboCop's own files. Avoids infinite recursion.
96
96
  return if loaded_path.start_with?(File.join(ConfigLoader::RUBOCOP_HOME,
97
97
  'config'))
98
98
 
@@ -9,13 +9,13 @@ module RuboCop
9
9
  PRIVATE_NODE = s(:send, nil, :private)
10
10
  PROTECTED_NODE = s(:send, nil, :protected)
11
11
  PUBLIC_NODE = s(:send, nil, :public)
12
- MODUDULE_FUNCTION_NODE = s(:send, nil, :module_function)
12
+ MODULE_FUNCTION_NODE = s(:send, nil, :module_function)
13
13
 
14
14
  def modifier_node?(node)
15
15
  [PRIVATE_NODE,
16
16
  PROTECTED_NODE,
17
17
  PUBLIC_NODE,
18
- MODUDULE_FUNCTION_NODE].include?(node)
18
+ MODULE_FUNCTION_NODE].include?(node)
19
19
  end
20
20
  end
21
21
  end
@@ -7,16 +7,14 @@ module RuboCop
7
7
  # abstract syntax tree, it is not done.
8
8
  module AutocorrectUnlessChangingAST
9
9
  def autocorrect(node)
10
- new_source = rewrite_node(node)
11
-
12
- # Make the correction only if it doesn't change the AST. Regenerate the
13
- # AST for `node` so we get it without context. Otherwise the comparison
14
- # could be misleading.
15
- if ast_for(node.loc.expression.source) != ast_for(new_source)
16
- fail CorrectionNotPossible
17
- end
10
+ current_buffer_src = processed_source.buffer.source
11
+ replaced_range = node.loc.expression
12
+ pre = current_buffer_src[0...replaced_range.begin_pos]
13
+ post = current_buffer_src[replaced_range.end_pos..-1]
14
+ new_buffer_src = pre + rewrite_node(node) + post
18
15
 
19
- if syntax_error?(node.loc.expression, new_source)
16
+ # Make the correction only if it doesn't change the AST for the buffer.
17
+ if processed_source.ast != ProcessedSource.new(new_buffer_src).ast
20
18
  fail CorrectionNotPossible
21
19
  end
22
20
 
@@ -25,24 +23,10 @@ module RuboCop
25
23
 
26
24
  private
27
25
 
28
- def ast_for(source)
29
- ProcessedSource.new(source).ast
30
- end
31
-
32
26
  def rewrite_node(node)
33
- processed_source = ProcessedSource.new(node.loc.expression.source)
34
- c = correction(processed_source.ast)
35
- Corrector.new(processed_source.buffer, [c]).rewrite
36
- end
37
-
38
- # Return true if the change would introduce a syntax error in the buffer
39
- # source.
40
- def syntax_error?(replaced_range, new_source)
41
- current_buffer_src = processed_source.buffer.source
42
- pre = current_buffer_src[0...replaced_range.begin_pos]
43
- post = current_buffer_src[replaced_range.end_pos..-1]
44
- new_buffer_src = pre + new_source + post
45
- !ProcessedSource.new(new_buffer_src).valid_syntax?
27
+ ps = ProcessedSource.new(node.loc.expression.source)
28
+ c = correction(ps.ast)
29
+ Corrector.new(ps.buffer, [c]).rewrite
46
30
  end
47
31
  end
48
32
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- # Common functionality for checking instance methods and singeton methods.
5
+ # Common functionality for checking instance methods and singleton methods.
6
6
  module OnMethodDef
7
7
  def on_def(node)
8
8
  method_name, args, body = *node
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # nodes.
9
9
  module StringHelp
10
10
  # Regex matches IF there is a ' or there is a \\ in the string that is
11
- # not preceeded/followed by another \\ (e.g. "\\x34") but not "\\\\".
11
+ # not preceded/followed by another \\ (e.g. "\\x34") but not "\\\\".
12
12
  ESCAPED_CHAR_REGEXP = /(?<! \\) \\{2}* \\ (?! \\)/x
13
13
 
14
14
  def on_str(node)
@@ -27,6 +27,15 @@ module RuboCop
27
27
  def on_regexp(node)
28
28
  ignore_node(node)
29
29
  end
30
+
31
+ def inside_interpolation?(node)
32
+ # A :begin node inside a :dstr node is an interpolation.
33
+ begin_found = false
34
+ node.each_ancestor.find do |a|
35
+ begin_found = true if a.type == :begin
36
+ begin_found && a.type == :dstr
37
+ end
38
+ end
30
39
  end
31
40
  end
32
41
  end
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # values are aligned.
33
33
  class AlignmentOfValues
34
34
  def checkable_layout(node)
35
- !any_pairs_on_the_same_line?(node) && all_have_same_sparator?(node)
35
+ !any_pairs_on_the_same_line?(node) && all_have_same_separator?(node)
36
36
  end
37
37
 
38
38
  def deltas(first_pair, _prev_pair, current_pair)
@@ -64,7 +64,7 @@ module RuboCop
64
64
  lines_of_the_children.uniq.size < lines_of_the_children.size
65
65
  end
66
66
 
67
- def all_have_same_sparator?(node)
67
+ def all_have_same_separator?(node)
68
68
  first_separator = node.children.first.loc.operator.source
69
69
  node.children[1..-1].all? do |pair|
70
70
  pair.loc.operator.is?(first_separator)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # This cop checks for non-ascii characters in indentifier names.
6
+ # This cop checks for non-ascii characters in identifier names.
7
7
  class AsciiIdentifiers < Cop
8
8
  MSG = 'Use only ascii symbols in identifiers.'
9
9
 
@@ -3,10 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # This cop checks for braces in method calls with hash parameters.
6
+ # This cop checks for braces around the last parameter in a method call
7
+ # if the last parameter is a hash.
7
8
  class BracesAroundHashParameters < Cop
8
9
  include ConfigurableEnforcedStyle
9
10
 
11
+ MSG = '%s curly braces around a hash parameter.'
12
+
10
13
  def on_send(node)
11
14
  _receiver, method_name, *args = *node
12
15
 
@@ -24,29 +27,32 @@ module RuboCop
24
27
  private
25
28
 
26
29
  def check(arg, args)
27
- if style == :no_braces
28
- if !braces?(arg) || all_hashes?(args)
29
- correct_style_detected
30
- else
31
- offense(arg, 'Redundant curly braces around a hash parameter.')
32
- end
33
- elsif braces?(arg)
34
- correct_style_detected
35
- else
36
- offense(arg, 'Missing curly braces around a hash parameter.')
30
+ if style == :braces && !braces?(arg)
31
+ add_offense(arg, :expression, format(MSG, 'Missing'))
32
+ elsif style == :no_braces && braces?(arg)
33
+ add_offense(arg, :expression, format(MSG, 'Redundant'))
34
+ elsif style == :context_dependent
35
+ check_context_dependent(arg, args)
37
36
  end
38
37
  end
39
38
 
40
- def offense(arg, msg)
41
- add_offense(arg, :expression, msg) { opposite_style_detected }
39
+ def check_context_dependent(arg, args)
40
+ braces_around_2nd_from_end = args.length > 1 && args[-2].type == :hash
41
+ if braces?(arg)
42
+ unless braces_around_2nd_from_end
43
+ add_offense(arg, :expression, format(MSG, 'Redundant'))
44
+ end
45
+ elsif braces_around_2nd_from_end
46
+ add_offense(arg, :expression, format(MSG, 'Missing'))
47
+ end
42
48
  end
43
49
 
44
50
  def autocorrect(node)
45
51
  @corrections << lambda do |corrector|
46
- if style == :no_braces
52
+ if braces?(node)
47
53
  corrector.remove(node.loc.begin)
48
54
  corrector.remove(node.loc.end)
49
- elsif style == :braces
55
+ else
50
56
  corrector.insert_before(node.loc.expression, '{')
51
57
  corrector.insert_after(node.loc.expression, '}')
52
58
  end
@@ -60,10 +66,6 @@ module RuboCop
60
66
  def braces?(arg)
61
67
  arg.loc.begin
62
68
  end
63
-
64
- def all_hashes?(args)
65
- args.length > 1 && args.all? { |a| a.type == :hash }
66
- end
67
69
  end
68
70
  end
69
71
  end