Permalink
Commits on Dec 2, 2016
Commits on Dec 1, 2016
  1. Add an `.editorconfig` file (#3748)

    More info [here](http://editorconfig.org/).
    AlexWayfer committed with Dec 1, 2016
  2. Avoid crash in `Rails/EnumUniqueness` cop

    `Rails/EnumUniqueness` cop crashes when `enum` method receives a variable.
    
    For example
    
    ```ruby
    class Foo < ApplicationRecord
      var = {status: {open: 1, closed: 2}}
      enum var
    end
    ```
    
    ```sh
    $ rubocop --rails
    An error occurred while Rails/EnumUniqueness cop was inspecting /tmp/tmp.sIFH7vguiW/app/models/foo.rb.
    
    1 error occurred:
    An error occurred while Rails/EnumUniqueness cop was inspecting /tmp/tmp.sIFH7vguiW/app/models/foo.rb.
    Errors are usually caused by RuboCop bugs.
    Please, report your problems to RuboCop's issue tracker.
    Mention the following information in the issue report:
    0.46.0 (using Parser 2.3.2.0, running on ruby 2.3.1 x86_64-linux)
    For /tmp/tmp.sIFH7vguiW: configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/config/default.yml
    Inheriting configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/config/enabled.yml
    Inheriting configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/config/disabled.yml
    Inspecting 1 file
    Scanning /tmp/tmp.sIFH7vguiW/app/models/foo.rb
    undefined method `child_nodes' for nil:NilClass
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/enum_uniqueness.rb:61:in `parse_args'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/enum_uniqueness.rb:28:in `on_send'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:41:in `block (2 levels) in on_send'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:96:in `with_cop_error_handling'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:40:in `block in on_send'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:39:in `each'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:39:in `on_send'
    (eval):2:in `block in on_begin'
    (eval):2:in `each'
    (eval):2:in `on_begin'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/ast_node/traversal.rb:88:in `on_class'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:45:in `on_class'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/ast_node/traversal.rb:12:in `walk'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/commissioner.rb:58:in `investigate'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/team.rb:120:in `investigate'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/team.rb:108:in `offenses'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/team.rb:51:in `inspect_file'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:243:in `inspect_file'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:190:in `block in do_inspection_loop'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:222:in `block in iterate_until_no_changes'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:215:in `loop'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:215:in `iterate_until_no_changes'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:186:in `do_inspection_loop'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:101:in `block in file_offenses'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:111:in `file_offense_cache'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:99:in `file_offenses'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:90:in `process_file'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:65:in `each'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:65:in `reduce'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:65:in `each_inspected_file'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:57:in `inspect_files'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:36:in `run'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cli.rb:72:in `execute_runner'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cli.rb:27:in `run'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/bin/rubocop:13:in `block in <top (required)>'
    /usr/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
    /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.46.0/bin/rubocop:12:in `<top (required)>'
    /home/pocke/.gem/ruby/2.3.0/bin/rubocop:23:in `load'
    /home/pocke/.gem/ruby/2.3.0/bin/rubocop:23:in `<main>'
    C
    
    Offenses:
    
    app/models/foo.rb:3:9: C: Style/SpaceInsideHashLiteralBraces: Space inside { missing.
      var = {status: {open: 1, closed: 2}}
            ^
    app/models/foo.rb:3:18: C: Style/SpaceInsideHashLiteralBraces: Space inside { missing.
      var = {status: {open: 1, closed: 2}}
                     ^
    app/models/foo.rb:3:37: C: Style/SpaceInsideHashLiteralBraces: Space inside } missing.
      var = {status: {open: 1, closed: 2}}
                                        ^
    app/models/foo.rb:3:38: C: Style/SpaceInsideHashLiteralBraces: Space inside } missing.
      var = {status: {open: 1, closed: 2}}
                                         ^
    
    1 file inspected, 4 offenses detected
    Finished in 0.10733168199658394 seconds
    ```
    
    I fixed the problem.
    pocke committed with Nov 30, 2016
  3. Add Auto-Correct for `Bundler/OrderedGems` cop

    See also #3657 #3600
    
    Goal
    ----
    
    Auto Correct not sorted gems.
    
    e.g.
    
    ```ruby
    gem 'b'
    gem 'd'
    gem 'c'
    gem 'a'
    
    gem 'a'
    gem 'b'
    gem 'c'
    gem 'd'
    ```
    
    Note
    -----
    
    I added `autocorrect_source_with_loop` test helper method to execute auto-correction with loop.
    This method is based on do_inspection_loop.
    https://github.com/bbatsov/rubocop/blob/ed4aeb845bfcaaff0648d365c5b46a2e725347f7/lib/rubocop/runner.rb#L179-L202
    pocke committed with Nov 30, 2016
Commits on Nov 30, 2016
  1. Cut 0.46.0

    committed Nov 30, 2016
  2. [Fix #3746] `Lint/NonLocalExitFromIterator` doesn't warn about block …

    …passed to `Object#define_singleton_method`
    
    `return`s don't cause problems in blocks passed to `define_singleton_method`.
    AlexWayfer committed with Nov 29, 2016
Commits on Nov 29, 2016
  1. Checks `min` and `max` call by `Perfomance/CompareWithBlock` cop

    Ref: #3500
    
    Problem
    ======
    
    `SortWithBlock` cop checks slow `sort` method call.
    `min` and `max` method have same performance problem.
    However, the methods is not checked by this cop.
    
    - https://ruby-doc.org/core-2.3.3/Enumerable.html#method-i-max
    - https://ruby-doc.org/core-2.3.3/Enumerable.html#method-i-min
    
    Benchmark
    =======
    
    ```ruby
    require 'benchmark'
    
    array = (1..1000000).map { rand(1000000) }
    
    Benchmark.bm(10) do |b|
      b.report("sort")    { array.sort { |a, b| a.to_s <=> b.to_s } }
      b.report("sort_by") { array.sort_by(&:to_s) }
    
      b.report("max")    { array.max { |a, b| a.to_s <=> b.to_s } }
      b.report("max_by") { array.max_by(&:to_s) }
    
      b.report("min")    { array.min { |a, b| a.to_s <=> b.to_s } }
      b.report("min_by") { array.min_by(&:to_s) }
    end
    ```
    
    ```
    $ ruby --version
    ruby 2.3.2p217 (2016-11-15 revision 56796) [x86_64-linux]
    $ ruby test.rb
                     user     system      total        real
    sort         6.660000   0.010000   6.670000 (  6.664807)
    sort_by      1.910000   0.010000   1.920000 (  1.928268)
    max          0.390000   0.000000   0.390000 (  0.385470)
    max_by       0.200000   0.000000   0.200000 (  0.203039)
    min          0.290000   0.000000   0.290000 (  0.288846)
    min_by       0.210000   0.000000   0.210000 (  0.210002)
    ```
    
    Goal
    =======
    
    I've added a check for `max` and `min` methods by `CompareWithBlock` cop.
    
    - [x] Rename `Perfomance/SortWithBlock` to `Perfomance/CompareWithBlock`
    - [x] Add test
    pocke committed with Nov 29, 2016
Commits on Nov 28, 2016
  1. Checks `binding.irb` call by `Lint/Debugger` cop

    From Ruby 2.4, `binding.irb` will be added.
    This method is like `binding.pry`.
    
    For example
    
    ```sh
    $ cat test.rb
    require 'irb'
    
    foo = 1
    binding.irb
    
    $ ruby test.rb
    irb(main):001:0> foo
    => 1
    irb(main):002:0>
    ```
    
    This PR adds detection of `binding.irb` as a debugger.
    
    For example
    
    ```sh
    $ rubocop
    Inspecting 1 file
    W
    
    Offenses:
    
    test.rb:4:1: W: Remove debugger entry point binding.irb.
    binding.irb
    ^^^^^^^^^^^
    
    1 file inspected, 1 offenses detected
    ```
    
    The check works only Ruby 2.4 or higher.
    pocke committed with Nov 18, 2016
Commits on Nov 26, 2016
  1. [Refactor] Reduce complexity in Metrics::LineLength

    Bring back the max numbers to what they were before the
    previous change.
    jonas054 committed with Nov 6, 2016
  2. [Fix #3479] Add IgnoredPatterns config option to LineLength

    A list of regular expressions. The cop ignores lines matching
    any of them. Empty list by default.
    jonas054 committed with Nov 6, 2016
Commits on Nov 25, 2016
Commits on Nov 22, 2016
  1. Merge pull request #3703 from swcraig/third-option-ternary-parens

    [Fix #3451] Add new `require_parentheses_when_complex` style to `Styl…
    committed Nov 22, 2016
  2. [Fix #3598] Disregard x.nonzero? and x != 0 in NumericPredicate

    The two expressions are not equivalent. `x != 0` returns `true`
    or `false` while `x.nonzero?` returns `self`, i.e. `x`, or `nil`.
    jonas054 committed with Nov 18, 2016
  3. Fix Rails/EnumUniqueness cop to handle array dupes

    Previously, the Rails/EnumUniqueness cop ignored enums defined
    using array syntax, and only handled the hash syntax.
    
    This update extends functionality to detect array duplicates
    such as:
    
    enum status: [:foo, :bar, :foo]
    olliebennett committed with Nov 21, 2016
Commits on Nov 21, 2016
  1. [Fix #3451] Add new `require_parentheses_when_complex` style to `Styl…

    …e/TernaryParentheses` cop
    swcraig committed Nov 5, 2016
  2. Merge pull request #3693 from Aesthetikx/allow-format-in-rails_http_p…

    …ositional_arguments
    
    Add format as an acceptable Rails/HttpPositionalArguments keyword
    committed Nov 21, 2016
  3. [Fix #3723] Add new Rails/EnumUniqueness cop

    This introduces a new cop which identifies any usage of duplicate values in hash-syntax enum definitions in Rails models.
    
    For example, the following can lead to an ambiguous "status" for the model:
    enum status: { active: 4, archived: 4 }
    
    An enum in Rails can be defined either as an array or a hash with specific integer keys defined.
    See: http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
    
    enum status: [ :active, :archived ]
    enum status: { active: 0, archived: 1 }
    
    With the latter syntax, it's possible to accidentally specify duplicate keys:
    
    enum status: { active: 4, archived: 4 }
    
    Bugs resulting from this can be hard to identify.
    olliebennett committed with Nov 16, 2016
Commits on Nov 20, 2016
  1. Avoid that uncorrected offenses are tested wrongly

    Avoid that uncorrected offenses are tested as corrected offenses with
    the the corrected expression being the same as the original one for the
    TernaryParenthesis cop.
    Ana06 committed with Nov 20, 2016
  2. Fix non-autocorrected offenses wrong tested

    Some cases in the ternary_parentheses_spec.rb are tested as
    autocorrected with the expression corrected being the same as the
    original one. This is actually because it is not corrected and it
    should be tested like an uncorrected case.
    Ana06 committed with Nov 19, 2016
  3. Add more test cases for TernaryParentheses cop

    Add tests for the TernaryParentheses cop to cover the case that was
    failing in #3687.
    It has already been fixed but there were no tests for this case.
    Ana06 committed with Nov 19, 2016
  4. [Fix #3568] Detect style while handling offense in VariableNumber

    When the variable name doesn't match the configured style, we should
    detect which style is used so that the right information is
    generated in .rubocop_todo.yml.
    jonas054 committed with Nov 19, 2016
Commits on Nov 19, 2016
  1. Respect DisabledByDefault in parent configs

    d956705 changed Config initialization
    such that Config#deprecation_check was called before resolving
    inheritance. Config#deprecation_check causes Config#for_all_cops to be
    lazily initialized to a new hash disconnected from Config's primary
    hash. Config#for_all_cops would thus not reflect any settings inherited
    from parent configs.
    
    Essentially, it's an error for Config#for_all_cops to be called before
    inheritance is resolved. Perhaps this code could be made more robust.
    For now I've just moved the deprecation check after resolving
    inheritance as it was before d956705.
    aroben committed with Nov 11, 2016
Commits on Nov 17, 2016
  1. [Fix #3687] TernaryParentheses claims to correct

    Style/TernaryParentheses cop claims to correct uncorrected offenses
    (safe assignment or unsafe autocorrection).
    Ana06 committed with Nov 11, 2016
Commits on Nov 15, 2016