Skip to content

Commit

Permalink
Merge remote-tracking branch 'bbatsov/master'
Browse files Browse the repository at this point in the history
* bbatsov/master: (80 commits)
  [Fix rubocop#3540] Make `Style/GuardClause` register offense for instance & singleton methods
  [Fix rubocop#3436] issue related to Rails/SaveBang when returning non-bang call from the parent method
  Allow `#to_yml` to produce single-quoted strings
  Add support for StyleGuideBaseURL and update rules
  Add spec for the existing style guide URL implementation
  Fix the changelog
  Edited regular expression for normal case to fix issues rubocop#3514 and rubocop#3516 (rubocop#3524)
  Add a rake task for generation a new cop (rubocop#3533)
  [Fix rubocop#3510] Various bug fixes for SafeNavigation (rubocop#3517)
  [Fix rubocop#3512] Change error message of `Lint/UnneededSplatExpansion` for array (rubocop#3526)
  Fix false positive in `Lint/AssignmentInCondition` (rubocop#3520) (rubocop#3529)
  Rename a mismatched filename (rubocop#3523)
  Fix a broken changelog entry
  [Fix rubocop#3511] Style/TernaryParentheses false positive (rubocop#3513)
  Fix the release notes for 0.43
  Cut 0.43.0
  [Fix rubocop#3462] Don't flag single-line methods
  Fix false negatives in `Rails/NotNullColumn` cop (rubocop#3508)
  Remove unused doubled methods (rubocop#3509)
  [Fix rubocop#3485] Make OneLineConditional cop ignore empty else (rubocop#3487)
  ...
  • Loading branch information
mikezter committed Sep 28, 2016
2 parents bdecffe + 2e64123 commit ddf05ec
Show file tree
Hide file tree
Showing 108 changed files with 3,349 additions and 651 deletions.
6 changes: 5 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ rule with your own words.*

## Expected behavior

Describe here how you expected RuboCop to behave in this particular situation.

## Actual behavior

Describe here what actually happened.

## Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

## RuboCop version

Include the output of `rubocop -V`:
Include the output of `rubocop -V`. Here's an example:

```
$ rubocop -V
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AllCops:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
TargetRubyVersion: 1.9
TargetRubyVersion: 2.0

Style/Encoding:
EnforcedStyle: always
Expand Down
12 changes: 6 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-08-29 10:38:53 +0300 using RuboCop version 0.42.0.
# on 2016-09-07 17:08:09 +0300 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 90
# Offense count: 75
Metrics/AbcSize:
Max: 20
Max: 19

# Offense count: 32
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 168

# Offense count: 27
# Offense count: 28
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 155
# Offense count: 143
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 15
Max: 14

# Offense count: 11
# Configuration parameters: CountComments.
Expand Down
53 changes: 52 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,44 @@

### New features

* [#3510](https://github.com/bbatsov/rubocop/issues/3510): Add a configuration option, `ConvertCodeThatCanStartToReturnNil`, to `Style/SafeNavigation` to check for code that could start returning `nil` if safe navigation is used. ([@rrosenblum][])
* Add a new `AllCops/StyleGuideBaseURL` setting that allows the use of relative paths and/or fragments within each cop's `StyleGuide` setting, to make forking of custom style guides easier. ([@scottmatthewman][])

### Bug fixes

* [#3513](https://github.com/bbatsov/rubocop/pull/3513): Fix false positive in `Style/TernaryParentheses` for a ternary with ranges. ([@dreyks][])
* [#3520](https://github.com/bbatsov/rubocop/issues/3520): Fix regression causing `Lint/AssignmentInCondition` false positive. ([@savef][])
* [#3514](https://github.com/bbatsov/rubocop/issues/3514): Make `Style/VariableNumber` cop not register an offense when valid normal case variable names have an integer after the first `_`. ([@b-t-g][])
* [#3516](https://github.com/bbatsov/rubocop/issues/3516): Make `Style/VariableNumber` cop not register an offense when valid normal case variable names have an integer in the middle. ([@b-t-g][])
* [#3436](https://github.com/bbatsov/rubocop/issues/3436): Make `Rails/SaveBang` cop not register an offense when return value of a non-bang method is returned by the parent method. ([@coorasse][])
* [#3540](https://github.com/bbatsov/rubocop/issues/3540): Fix `Style/GuardClause` to register offense for instance and singleton methods. ([@tejasbubane][])

### Changes

* [#3512](https://github.com/bbatsov/rubocop/issues/3512): Change error message of `Lint/UnneededSplatExpansion` for array in method parameters. ([@tejasbubane][])
* [#3510](https://github.com/bbatsov/rubocop/issues/3510): Fix some issues with `Style/SafeNavigation`. Fix auto-correct of multiline if expressions, and do not register an offense for scenarios using `||` and ternary expression. ([@rrosenblum][])

## 0.43.0 (2016-09-19)

### New features

* [#3379](https://github.com/bbatsov/rubocop/issues/3379): Add table of contents at the beginning of HTML formatted output. ([@hedgesky][])
* [#2968](https://github.com/bbatsov/rubocop/issues/2968): Add new `Style/DocumentationMethod` cop. ([@sooyang][])
* [#3360](https://github.com/bbatsov/rubocop/issues/3360): Add `RequireForNonPublicMethods` configuration option to `Style/DocumentationMethod` cop. ([@drenmi][])
* Add new `Rails/SafeNavigation` cop to convert `try!` to `&.`. ([@rrosenblum][])
* [#3415](https://github.com/bbatsov/rubocop/pull/3415): Add new `Rails/NotNullColumn` cop. ([@pocke][])
* [#3167](https://github.com/bbatsov/rubocop/issues/3167): Add new `Style/VariableNumber` cop. ([@sooyang][])
* Add new style `no_mixed_keys` to `Style/HashSyntax` to only check for hashes with mixed keys. ([@daviddavis][])
* Allow including multiple configuration files from a single gem. ([@tjwallace][])
* Add check for `persisted?` method call when using a create method in `Rails/SaveBang`. ([@QuinnHarris][])
* Add new `Style/SafeNavigation` cop to convert method calls safeguarded by a non `nil` check for the object to `&.`. ([@rrosenblum][])
* Add new `Performance/SortWithBlock` cop to use `sort_by(&:foo)` instead of `sort_by { |a, b| a.foo <=> b.foo }`. ([@koic][])
* [#3492](https://github.com/bbatsov/rubocop/pull/3492): Add new `UnifiedInteger` cop. ([@pocke][])

### Bug fixes

* [#3383](https://github.com/bbatsov/rubocop/issues/3383): Fix the local variable reset issue with `Style/RedundantSelf` cop. ([@bankair][])
* [#3445](https://github.com/bbatsov/rubocop/issues/3445): Fix bad autocorrect for `Style/AndOr` cop. ([@mikezter][])
* [#3349](https://github.com/bbatsov/rubocop/issues/3349): Fix bad autocorrect for `Style/Lambda` cop. ([@metcalf][])
* [#3351](https://github.com/bbatsov/rubocop/issues/3351): Fix bad auto-correct for `Performance/RedundantMatch` cop. ([@annaswims][])
* [#3347](https://github.com/bbatsov/rubocop/issues/3347): Prevent infinite loop in `Style/TernaryParentheses` cop when used together with `Style/RedundantParentheses`. ([@drenmi][])
Expand All @@ -27,13 +57,24 @@
* [#3425](https://github.com/bbatsov/rubocop/pull/3425): Fix bug for invalid bytes in UTF-8 in `Lint/PercentStringArray` cop. ([@pocke][])
* [#3374](https://github.com/bbatsov/rubocop/issues/3374): Make `SpaceInsideBlockBraces` and `SpaceBeforeBlockBraces` not depend on `BlockDelimiters` configuration. ([@jonas054][])
* Fix error in `Lint/ShadowedException` cop for higher number of rescue groups. ([@groddeck][])
[@groddeck]: https://github.com/groddeck
* [#3456](https://github.com/bbatsov/rubocop/pull/3456): Don't crash on a multiline empty brace in `Style/MultilineMethodCallBraceLayout`. ([@pocke][])
* [#3423](https://github.com/bbatsov/rubocop/issues/3423): Checks if .rubocop is a file before parsing. ([@joejuzl][])
* [#3439](https://github.com/bbatsov/rubocop/issues/3439): Fix variable assignment check not working properly when a block is used in `Rails/SaveBang`. ([@QuinnHarris][])
* [#3401](https://github.com/bbatsov/rubocop/issues/3401): Read file contents in binary mode so `Style/EndOfLine` works on Windows. ([@jonas054][])
* [#3450](https://github.com/bbatsov/rubocop/issues/3450): Prevent `Style/TernaryParentheses` cop from making unsafe corrections. ([@drenmi][])
* [#3460](https://github.com/bbatsov/rubocop/issues/3460): Fix false positives in `Style/InlineComment` cop. ([@drenmi][])
* [#3485](https://github.com/bbatsov/rubocop/issues/3485): Make OneLineConditional cop not register offense for empty else. ([@tejasbubane][])
* [#3508](https://github.com/bbatsov/rubocop/pull/3508): Fix false negatives in `Rails/NotNullColumn`. ([@pocke][])
* [#3462](https://github.com/bbatsov/rubocop/issues/3462): Don't create MultilineMethodCallBraceLayout offenses for single-line method calls when receiver spans multiple lines. ([@maxjacobson][])

### Changes

* [#3341](https://github.com/bbatsov/rubocop/issues/3341): Exclude RSpec tests from inspection by `Style/NumericPredicate` cop. ([@drenmi][])
* Rename `Lint/UselessArraySplat` to `Lint/UnneededSplatExpansion`, and add functionality to check for unnecessary expansion of other literals. ([@rrosenblum][])
* No longer register an offense for splat expansion of an array literal in `Performance/CaseWhenSplat`. `Lint/UnneededSplatExpansion` now handles this behavior. ([@rrosenblum][])
* `Lint/InheritException` restricts inheriting from standard library subclasses of `Exception`. ([@metcalf][])
* No longer register an offense if the first line of code starts with `#\` in `Style/LeadingCommentSpace`. `config.ru` files consider such lines as options. ([@scottohara][])
* [#3292](https://github.com/bbatsov/rubocop/issues/3292): Remove `Performance/PushSplat` as it can produce code that is slower or even cause failure. ([@jonas054][])

## 0.42.0 (2016-07-25)

Expand Down Expand Up @@ -2334,3 +2375,13 @@
[@annaswims]: https://github.com/annaswims
[@soutaro]: https://github.com/soutaro
[@nicklamuro]: https://github.com/nicklamuro
[@mikezter]: https://github.com/mikezter
[@joejuzl]: https://github.com/joejuzl
[@hedgesky]: https://github.com/hedgesky
[@tjwallace]: https://github.com/tjwallace
[@scottohara]: https://github.com/scottohara
[@koic]: https://github.com/koic
[@groddeck]: https://github.com/groddeck
[@b-t-g]: https://github.com/b-t-g
[@coorasse]: https://github.com/coorasse
[@scottmatthewman]: https://github.com/scottmatthewman
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
might want to use a conservative version locking in your `Gemfile`:

```rb
gem 'rubocop', '~> 0.42.0', require: false
gem 'rubocop', '~> 0.43.0', require: false
```

## Quickstart
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require 'rspec/core'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

Dir['tasks/**/*.rake'].each { |t| load t }

RSpec::Core::RakeTask.new(:spec)

RSpec::Core::RakeTask.new(:ascii_spec) do |t|
Expand Down
31 changes: 21 additions & 10 deletions assets/output.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@
line-height: 2.2rem;
margin: 0 0 0.5em;
}
.information .infobox ul {
list-style: none;
margin: 0;
padding: 0;
}
.information .infobox ul li {
.information .offenses-list li {
line-height: 1.8rem
}
.information .offenses-list {
padding-left: 20px;
margin-bottom: 0;
}

#offenses .offense-box {
border-radius: 4px;
Expand Down Expand Up @@ -191,7 +190,7 @@
idx,
scrollY = window.scrollY;
for (i = 0; i < boxPositions.length; i++) {
if (scrollY <= boxPositions[i]) {
if (scrollY <= boxPositions[i] - 1) {
idx = i;
break;
}
Expand All @@ -214,14 +213,26 @@
</div>
<div class="information">
<div class="infobox">
<%= pluralize(files.count, 'file') %> inspected,
<%= pluralize(summary.offense_count, 'offense', no_for_zero: true) %> detected
<div class="total">
<%= pluralize(files.count, 'file') %> inspected,
<%= pluralize(summary.offense_count, 'offense', no_for_zero: true) %> detected:
</div>
<ul class="offenses-list">
<% files.each do |file| %>
<% next if file.offenses.none? %>
<li>
<a href="#offense_<%= relative_path(file.path) %>">
<%= relative_path(file.path) %> - <%= pluralize(file.offenses.count, 'offense') %>
</a>
</li>
<% end %>
</ul>
</div>
</div>
<div id="offenses">
<% files.each do |file| %>
<% if file.offenses.any? %>
<div class="offense-box">
<div class="offense-box" id="offense_<%= relative_path(file.path) %>">
<div class="box-title-placeholder"><h3>&nbsp;</h3></div>
<div class="box-title"><h3><%= relative_path(file.path) %> - <%= pluralize(file.offenses.count, 'offense') %></h3></div>
<div class="offense-reports">
Expand Down
17 changes: 15 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ AllCops:
# behavior by overriding DisplayStyleGuide, or by giving the
# -S/--display-style-guide option.
DisplayStyleGuide: false
# When specifying style guide URLs, any paths and/or fragments will be
# evaluated relative to the base URL.
StyleGuideBaseURL: https://github.com/bbatsov/ruby-style-guide
# Extra details are not displayed in offense messages by default. Change
# behavior by overriding ExtraDetails, or by giving the
# -E/--extra-details option.
Expand Down Expand Up @@ -535,9 +538,14 @@ Style/GuardClause:
Style/HashSyntax:
EnforcedStyle: ruby19
SupportedStyles:
# checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
- ruby19
- ruby19_no_mixed_keys
# checks for hash rocket syntax for all hashes
- hash_rockets
# forbids mixed key syntaxes (e.g. {a: 1, :b => 2})
- no_mixed_keys
# enforces both ruby19 and no_mixed_keys styles
- ruby19_no_mixed_keys
# Force hashes that have a symbol value to use hash rockets
UseHashRocketsWithSymbolValues: false
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
Expand Down Expand Up @@ -836,6 +844,11 @@ Style/RegexpLiteral:
# are found in the regexp string.
AllowInnerSlashes: false

Style/SafeNavigation:
# Safe navigation may cause a statement to start returning `nil` in addition
# to whatever it used to return.
ConvertCodeThatCanStartToReturnNil: false

Style/Semicolon:
# Allow ; to separate several expressions on the same line.
AllowAsExpressionSeparator: false
Expand Down Expand Up @@ -1076,7 +1089,7 @@ Style/WordArray:
##################### Metrics ##################################

Metrics/AbcSize:
# The ABC size is a calculated magnitude, so this number can be a Fixnum or
# The ABC size is a calculated magnitude, so this number can be an Integer or
# a Float.
Max: 15

Expand Down
14 changes: 7 additions & 7 deletions config/disabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Style/AutoResourceCleanup:

Style/CollectionMethods:
Description: 'Preferred collection methods.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size'
StyleGuide: '#map-find-select-reduce-size'
Enabled: false

Style/Copyright:
Expand All @@ -32,7 +32,7 @@ Style/DocumentationMethod:

Style/Encoding:
Description: 'Use UTF-8 as the source file encoding.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#utf-8'
StyleGuide: '#utf-8'
Enabled: false

Style/FirstArrayElementLineBreak:
Expand Down Expand Up @@ -66,12 +66,12 @@ Style/ImplicitRuntimeError:
Enabled: false

Style/InlineComment:
Description: 'Avoid inline comments.'
Description: 'Avoid trailing inline comments.'
Enabled: false

Style/MethodCalledOnDoEndBlock:
Description: 'Avoid chaining a method call on a do...end block.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
StyleGuide: '#single-line-blocks'
Enabled: false

Style/MissingElse:
Expand All @@ -93,7 +93,7 @@ Style/MissingElse:

Style/MultilineAssignmentLayout:
Description: 'Check for a newline after the assignment operator in multi-line assignments.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#indent-conditional-assignment'
StyleGuide: '#indent-conditional-assignment'
Enabled: false

Style/OptionHash:
Expand All @@ -102,7 +102,7 @@ Style/OptionHash:

Style/Send:
Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#prefer-public-send'
StyleGuide: '#prefer-public-send'
Enabled: false

Style/StringMethods:
Expand All @@ -111,5 +111,5 @@ Style/StringMethods:

Style/SymbolArray:
Description: 'Use %i or %I for arrays of symbols.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-i'
StyleGuide: '#percent-i'
Enabled: false
Loading

0 comments on commit ddf05ec

Please sign in to comment.