Skip to content

Commit

Permalink
Merge branch 'master' into feature/require_order_block_pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov authored Jul 13, 2020
2 parents 739afb6 + 0c786c0 commit fe066fc
Show file tree
Hide file tree
Showing 126 changed files with 3,469 additions and 1,582 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Include the output of `rubocop -V` or `bundle exec rubocop -V` if using Bundler.

```
$ [bundle exec] rubocop -V
0.87.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)
0.87.1 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux)
```
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ TAGS

# For bundle binstubs
bin/*
!bin/rubocop-profile

# For stackprof or others
tmp/*
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,38 @@
### New features

* [#8279](https://github.com/rubocop-hq/rubocop/pull/8279): Recognise require method passed as argument in `Lint/NonDeterministicRequireOrder` cop. ([@biinari][])
* [#7333](https://github.com/rubocop-hq/rubocop/issues/7333): Add new `Style/RedundantFileExtensionInRequire` cop. ([@fatkodima][])
* [#8316](https://github.com/rubocop-hq/rubocop/pull/8316): Support autocorrect for `Lint/DisjunctiveAssignmentInConstructor` cop. ([@fatkodima][])
* [#8242](https://github.com/rubocop-hq/rubocop/pull/8242): Internal profiling available with `bin/rubocop-profile` and rake tasks. ([@marcandre][])
* [#8295](https://github.com/rubocop-hq/rubocop/pull/8295): Add new `Style/ArrayCoercion` cop. ([@fatkodima][])
* [#8293](https://github.com/rubocop-hq/rubocop/pull/8293): Add new `Lint/DuplicateElsifCondition` cop. ([@fatkodima][])
* [#7736](https://github.com/rubocop-hq/rubocop/issues/7736): Add new `Style/CaseLikeIf` cop. ([@fatkodima][])
* [#4286](https://github.com/rubocop-hq/rubocop/issues/4286): Add new `Style/HashAsLastArrayItem` cop. ([@fatkodima][])
* [#8247](https://github.com/rubocop-hq/rubocop/issues/8247): Add new `Style/HashLikeCase` cop. ([@fatkodima][])
* [#8286](https://github.com/rubocop-hq/rubocop/issues/8286): Internal method `expect_offense` allows abbreviated offense messages. ([@marcandre][])

### Bug fixes

* [#8232](https://github.com/rubocop-hq/rubocop/issues/8232): Fix a false positive for `Layout/EmptyLinesAroundAccessModifier` when `end` immediately after access modifier. ([@koic][])
* [#7777](https://github.com/rubocop-hq/rubocop/issues/7777): Fix crash for `Layout/MultilineArrayBraceLayout` when comment is present after last element. ([@shekhar-patil][])
* [#7776](https://github.com/rubocop-hq/rubocop/issues/7776): Fix crash for `Layout/MultilineMethodCallBraceLayout` when comment is present before closing braces. ([@shekhar-patil][])
* [#8282](https://github.com/rubocop-hq/rubocop/issues/8282): Fix `Style/IfUnlessModifier` bad precedence detection. ([@tejasbubane][])
* [#8289](https://github.com/rubocop-hq/rubocop/issues/8289): Fix `Style/AccessorGrouping` to not register offense for accessor with comment. ([@tejasbubane][])
* [#8310](https://github.com/rubocop-hq/rubocop/pull/8310): Handle major version requirements in `Gemspec/RequiredRubyVersion`. ([@eugeneius][])
* [#8315](https://github.com/rubocop-hq/rubocop/pull/8315): Fix crash for `Style/PercentLiteralDelimiters` when the source contains invalid characters. ([@eugeneius][])

### Changes

* [#8021](https://github.com/rubocop-hq/rubocop/issues/8021): Rewrite `Layout/SpaceAroundMethodCallOperator` cop to make it faster. ([@fatkodima][])
* [#8294](https://github.com/rubocop-hq/rubocop/pull/8294): Add `of` to `AllowedNames` of `MethodParameterName` cop. ([@AlexWayfer][])

## 0.87.1 (2020-07-07)

### Bug fixes

* [#8189](https://github.com/rubocop-hq/rubocop/issues/8189): Fix an error for `Layout/MultilineBlockLayout` where spaces for a new line where not considered. ([@knejad][])
* [#8252](https://github.com/rubocop-hq/rubocop/issues/8252): Fix a command line option name from `--safe-autocorrect` to `--safe-auto-correct`, which is compatible with RuboCop 0.86 and lower. ([@koic][])
* [#8259](https://github.com/rubocop-hq/rubocop/issues/8259): Fix false positives for `Style/BisectedAttrAccessor` when accessors have different access modifiers. ([@fatkodima][])
* [#8253](https://github.com/rubocop-hq/rubocop/issues/8253): Fix false positives for `Style/AccessorGrouping` when accessors have different access modifiers. ([@fatkodima][])
* [#8257](https://github.com/rubocop-hq/rubocop/issues/8257): Fix an error for `Style/BisectedAttrAccessor` when using `attr_reader` and `attr_writer` with splat arguments. ([@fatkodima][])
* [#8239](https://github.com/rubocop-hq/rubocop/pull/8239): Don't load `.rubocop.yml` from personal folders to check for exclusions if given a custom configuration file. ([@deivid-rodriguez][])
Expand Down Expand Up @@ -4657,3 +4685,5 @@
[@fatkodima]: https://github.com/fatkodima
[@karlwithak]: https://github.com/karlwithak
[@CamilleDrapier]: https://github.com/CamilleDrapier
[@shekhar-patil]: https://github.com/shekhar-patil
[@knejad]: https://github.com/knejad
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
gemspec

gem 'bump', require: false
gem 'memory_profiler', platform: :mri
gem 'pry'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.7'
Expand All @@ -14,6 +15,7 @@ gem 'rubocop-rspec', '~> 1.39.0'
# Stop upgrading SimpleCov until the following issue will be resolved.
# https://github.com/codeclimate/test-reporter/issues/418
gem 'simplecov', '~> 0.10', '< 0.18'
gem 'stackprof', platform: :mri
gem 'test-queue'
gem 'yard', '~> 0.9'

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
might want to use a conservative version lock in your `Gemfile`:

```rb
gem 'rubocop', '~> 0.87.0', require: false
gem 'rubocop', '~> 0.87.1', require: false
```

## Quickstart
Expand Down
31 changes: 31 additions & 0 deletions bin/rubocop-profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

if ARGV.include?('-h') || ARGV.include?('--help')
puts "Usage: same as main `rubocop` command but gathers profiling info"
puts "Additional option: `--memory` to print memory usage"
exit(0)
end
with_mem = ARGV.delete('--memory')

require 'stackprof'
if with_mem
require 'memory_profiler'
MemoryProfiler.start
end
StackProf.start
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
load "#{__dir__}/../exe/rubocop"
ensure
delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
puts "Finished in #{delta.round(1)} seconds"
StackProf.stop
if with_mem
puts "Building memory report..."
report = MemoryProfiler.stop
end
Dir.mkdir('tmp') unless File.exist?('tmp')
StackProf.results('tmp/stackprof.dump')
report&.pretty_print(scale_bytes: true)
end
63 changes: 57 additions & 6 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1397,12 +1397,18 @@ Lint/DisjunctiveAssignmentInConstructor:
Enabled: true
Safe: false
VersionAdded: '0.62'
VersionChanged: '0.88'

Lint/DuplicateCaseCondition:
Description: 'Do not repeat values in case conditionals.'
Enabled: true
VersionAdded: '0.45'

Lint/DuplicateElsifCondition:
Description: 'Do not repeat conditions used in if `elsif`.'
Enabled: 'pending'
VersionAdded: '0.88'

Lint/DuplicateHashKey:
Description: 'Check for duplicate keys in hash literals.'
Enabled: true
Expand Down Expand Up @@ -2179,17 +2185,18 @@ Naming/MethodParameterName:
AllowNamesEndingInNumbers: true
# Allowed names that will not register an offense
AllowedNames:
- io
- id
- to
- at
- by
- 'on'
- db
- id
- in
- at
- io
- ip
- db
- of
- 'on'
- os
- pp
- to
# Forbidden names that will register an offense
ForbiddenNames: []

Expand Down Expand Up @@ -2340,6 +2347,14 @@ Style/AndOr:
- always
- conditionals

Style/ArrayCoercion:
Description: >-
Use Array() instead of explicit Array check or [*var], when dealing
with a variable you want to treat as an Array, but you're not certain it's an array.
StyleGuide: '#array-coercion'
Enabled: 'pending'
VersionAdded: '0.88'

Style/ArrayJoin:
Description: 'Use Array#join instead of Array#*.'
StyleGuide: '#array-join'
Expand Down Expand Up @@ -2522,6 +2537,12 @@ Style/CaseEquality:
# String === "string"
AllowOnConstant: false

Style/CaseLikeIf:
Description: 'This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.'
StyleGuide: '#case-vs-if-else'
Enabled: 'pending'
VersionAdded: '0.88'

Style/CharacterLiteral:
Description: 'Checks for uses of character literals.'
StyleGuide: '#no-character-literals'
Expand Down Expand Up @@ -2961,13 +2982,35 @@ Style/GuardClause:
# needs to have to trigger this cop
MinBodyLength: 1

Style/HashAsLastArrayItem:
Description: >-
Checks for presence or absence of braces around hash literal as a last
array item depending on configuration.
StyleGuide: '#hash-literal-as-last-array-item'
Enabled: 'pending'
VersionAdded: '0.88'
EnforcedStyle: braces
SupportedStyles:
- braces
- no_braces

Style/HashEachMethods:
Description: 'Use Hash#each_key and Hash#each_value.'
StyleGuide: '#hash-each'
Enabled: pending
VersionAdded: '0.80'
Safe: false

Style/HashLikeCase:
Description: >-
Checks for places where `case-when` represents a simple 1:1
mapping and can be replaced with a hash lookup.
Enabled: 'pending'
VersionAdded: '0.88'
# `MinBranchesCount` defines the number of branches `case` needs to have
# to trigger this cop
MinBranchesCount: 3

Style/HashSyntax:
Description: >-
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
Expand Down Expand Up @@ -3665,6 +3708,14 @@ Style/RedundantFetchBlock:
SafeForConstants: false
VersionAdded: '0.86'

Style/RedundantFileExtensionInRequire:
Description: >-
Checks for the presence of superfluous `.rb` extension in
the filename provided to `require` and `require_relative`.
StyleGuide: '#no-explicit-rb-to-require'
Enabled: 'pending'
VersionAdded: '0.88'

Style/RedundantFreeze:
Description: "Checks usages of Object#freeze on immutable objects."
Enabled: true
Expand Down
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ In the following section you find all available cops:
* xref:cops_lint.adoc#lintdeprecatedopensslconstant[Lint/DeprecatedOpenSSLConstant]
* xref:cops_lint.adoc#lintdisjunctiveassignmentinconstructor[Lint/DisjunctiveAssignmentInConstructor]
* xref:cops_lint.adoc#lintduplicatecasecondition[Lint/DuplicateCaseCondition]
* xref:cops_lint.adoc#lintduplicateelsifcondition[Lint/DuplicateElsifCondition]
* xref:cops_lint.adoc#lintduplicatehashkey[Lint/DuplicateHashKey]
* xref:cops_lint.adoc#lintduplicatemethods[Lint/DuplicateMethods]
* xref:cops_lint.adoc#linteachwithobjectargument[Lint/EachWithObjectArgument]
Expand Down Expand Up @@ -316,6 +317,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleaccessorgrouping[Style/AccessorGrouping]
* xref:cops_style.adoc#stylealias[Style/Alias]
* xref:cops_style.adoc#styleandor[Style/AndOr]
* xref:cops_style.adoc#stylearraycoercion[Style/ArrayCoercion]
* xref:cops_style.adoc#stylearrayjoin[Style/ArrayJoin]
* xref:cops_style.adoc#styleasciicomments[Style/AsciiComments]
* xref:cops_style.adoc#styleattr[Style/Attr]
Expand All @@ -326,6 +328,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleblockcomments[Style/BlockComments]
* xref:cops_style.adoc#styleblockdelimiters[Style/BlockDelimiters]
* xref:cops_style.adoc#stylecaseequality[Style/CaseEquality]
* xref:cops_style.adoc#stylecaselikeif[Style/CaseLikeIf]
* xref:cops_style.adoc#stylecharacterliteral[Style/CharacterLiteral]
* xref:cops_style.adoc#styleclassandmodulechildren[Style/ClassAndModuleChildren]
* xref:cops_style.adoc#styleclasscheck[Style/ClassCheck]
Expand Down Expand Up @@ -369,7 +372,9 @@ In the following section you find all available cops:
* xref:cops_style.adoc#stylefrozenstringliteralcomment[Style/FrozenStringLiteralComment]
* xref:cops_style.adoc#styleglobalvars[Style/GlobalVars]
* xref:cops_style.adoc#styleguardclause[Style/GuardClause]
* xref:cops_style.adoc#stylehashaslastarrayitem[Style/HashAsLastArrayItem]
* xref:cops_style.adoc#stylehasheachmethods[Style/HashEachMethods]
* xref:cops_style.adoc#stylehashlikecase[Style/HashLikeCase]
* xref:cops_style.adoc#stylehashsyntax[Style/HashSyntax]
* xref:cops_style.adoc#stylehashtransformkeys[Style/HashTransformKeys]
* xref:cops_style.adoc#stylehashtransformvalues[Style/HashTransformValues]
Expand Down Expand Up @@ -439,6 +444,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleredundantconditional[Style/RedundantConditional]
* xref:cops_style.adoc#styleredundantexception[Style/RedundantException]
* xref:cops_style.adoc#styleredundantfetchblock[Style/RedundantFetchBlock]
* xref:cops_style.adoc#styleredundantfileextensioninrequire[Style/RedundantFileExtensionInRequire]
* xref:cops_style.adoc#styleredundantfreeze[Style/RedundantFreeze]
* xref:cops_style.adoc#styleredundantinterpolation[Style/RedundantInterpolation]
* xref:cops_style.adoc#styleredundantparentheses[Style/RedundantParentheses]
Expand Down
5 changes: 5 additions & 0 deletions docs/modules/ROOT/pages/cops_gemspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ end
Gem::Specification.new do |spec|
spec.required_ruby_version = ['>= 2.5.0', '< 2.7.0']
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 2.5'
end
----

=== Configurable attributes
Expand Down
37 changes: 35 additions & 2 deletions docs/modules/ROOT/pages/cops_lint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ OpenSSL::Digest.digest('SHA256', 'foo')

| Enabled
| No
| No
| Yes (Unsafe)
| 0.62
| -
| 0.88
|===

This cop checks constructors for disjunctive assignments that should
Expand Down Expand Up @@ -609,6 +609,39 @@ when 'second'
end
----

== Lint/DuplicateElsifCondition

|===
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Pending
| Yes
| No
| 0.88
| -
|===

This cop checks that there are no repeated conditions used in if 'elsif'.

=== Examples

[source,ruby]
----
# bad
if x == 1
do_something
elsif x == 1
do_something_else
end
# good
if x == 1
do_something
elsif x == 2
do_something_else
end
----

== Lint/DuplicateHashKey

|===
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_naming.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ end
| Boolean

| AllowedNames
| `io`, `id`, `to`, `by`, `on`, `in`, `at`, `ip`, `db`, `os`, `pp`
| `at`, `by`, `db`, `id`, `in`, `io`, `ip`, `of`, `on`, `os`, `pp`, `to`
| Array

| ForbiddenNames
Expand Down
Loading

0 comments on commit fe066fc

Please sign in to comment.