Skip to content

Commit

Permalink
Merge pull request #6605 from jaredbeck/fix_6597
Browse files Browse the repository at this point in the history
[Fix #6597] - LineEndConcatenation is unsafe
  • Loading branch information
koic committed Jan 29, 2019
2 parents b6cf0dd + e39d0c8 commit 4d6d4b6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,10 @@
* [#6382](https://github.com/rubocop-hq/rubocop/issues/6382): Fix `Layout/IndentationWidth` with `Layout/EndAlignment` set to start_of_line. ([@dischorde][], [@siegfault][], [@mhelmetag][])
* [#6710](https://github.com/rubocop-hq/rubocop/issues/6710): Fix `Naming/MemoizedInstanceVariableName` on method starts with underscore. ([@pocke][])

### Changes

* [#6597](https://github.com/rubocop-hq/rubocop/issues/6597): `Style/LineEndConcatenation` is now known to be unsafe for auto-correct. ([@jaredbeck][])

## 0.63.1 (2019-01-22)

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Expand Up @@ -3374,7 +3374,9 @@ Style/LineEndConcatenation:
Use \ instead of + or << to concatenate two string literals at
line end.
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.18'
VersionChanged: '0.64'

Style/MethodCallWithArgsParentheses:
Description: 'Use parentheses for method calls with arguments.'
Expand Down
35 changes: 30 additions & 5 deletions manual/auto_correct.md
Expand Up @@ -16,13 +16,38 @@ Some automatic corrections that _are_ possible have not been implemented yet.
$ rubocop --safe-auto-correct
```

In RuboCop 0.60, we began to annotate cops as `Safe` or not safe.
In RuboCop 0.60, we began to annotate cops as `Safe` or not safe. Eventually,
the safety of each cop will be determined.

> - Safe (true/false) - indicates whether the cop can yield false positives (by
> - Safe (true/false) - indicates whether the cop can yield false positives (by
> design) or not.
> - SafeAutoCorrect (true/false) - indicates whether the auto-correct the cop
> - SafeAutoCorrect (true/false) - indicates whether the auto-correct the cop
> does is safe (equivalent) by design.
> https://github.com/rubocop-hq/rubocop/issues/5978#issuecomment-395958738
If a cop is annotated as "not safe", it will be omitted. As of December, not
all cops have a `Safe` annotation.
If a cop is annotated as "not safe", it will be omitted.

#### Example of Unsafe Cop

```ruby
array = []
array << 'Foo' <<
'Bar' <<
'Baz'
puts array.join('-')
```

`Style/LineEndConcatenation` will correct the above to:

```ruby
array = []
array << 'Foo' \
'Bar' \
'Baz'
puts array.join('-')
```

Therefore, in this (unusual) scenario, `Style/LineEndConcatenation` is unsafe.

(This is a contrived example. Real code would use `%w` for an array of string
literals.)
2 changes: 1 addition & 1 deletion manual/cops_style.md
Expand Up @@ -2738,7 +2738,7 @@ EnforcedStyle | `call` | `call`, `braces`

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.18 | -
Enabled | Yes | Yes (Unsafe) | 0.18 | 0.64

This cop checks for string literal concatenation at
the end of a line.
Expand Down

0 comments on commit 4d6d4b6

Please sign in to comment.