5
0

More than 5 years have passed since last update.

Rubocop v0.46.0 の changelog

Last updated at Posted at 2016-12-02

2016/11/30 にリリースされた rubocop 0.46.0チェンジログから新機能部分についてまとめてみた。


Add new Bundler/DuplicatedGem cop. (@jmks)

class ドキュメントに書いてあるとおり、Gemfile 内の重複定義を怒ってくれる。

単なる重複は当然として、group にまたがった重複も対象になる。

#   # bad
#   group :development do
#     gem 'rubocop'
#   end
#
#   group :test do
#     gem 'rubocop'
#   end
#
#   # good
#   group :development, :test do
#     gem 'rubocop'
#   end
#
#   # good
#   gem 'rubocop', groups: [:development, :test]

Add new configuration option empty_lines_special to Style/EmptyLinesAroundClassBody and Style/EmptyLinesAroundModuleBody. (@legendetm)

既存の Cop Style/EmptyLinesAroundClassBody, Style/EmptyLinesAroundModuleBodyempty_lines_special が追加された

以下のような整形をしたいけど、できなかった。
ポイントは class のネストだという点、 module の場合はこれまでもできてる。

module Aaa
  class Bbb
    class Ccc < ApplicationRecord

      # 最内の class にだけ空行入れたい
      def hello
        p 'hello'
      end

    end
  end
end

Add new Style/EmptyMethod cop. (@drenmi)

空っぽのメソッドを compact にするか expanded にするかというもの

EnforcedStyle: compact (default)
#   @bad
#   def foo(bar)
#   end
#
#   @good
#   def foo(bar); end
#   def foo(bar)
#     # コメントあれば compact されない
#   end
EnforcedStyle: expanded
#   @bad
#   def foo(bar); end
#
#   @good
#   def foo(bar)
#   end

Style/EmptyLiteral will now auto-correct Hash.new when it is the first argument being passed to a method. The arguments will be wrapped with parenthesis. (@rrosenblum)

メソッドパラメータに Hash.new が渡された場合 auto-correct されるようになった

yadayada.map { a }.reduce Hash.new

yadayada.map { a }.reduce({})

yadayada.map { a }.reduce Hash.new, :merge

yadayada.map { a }.reduce({}, :merge)


Respect DisabledByDefault in parent configs. (@aroben)

継承元と自身の config で DisabledByDefault を定義している場合、継承元を優先する。


New cop Rails/EnumUniqueness checks for duplicate values defined in enum config. (@olliebennett)

enum 内での重複定義を怒ってくれるようになった。

#   # bad
#   enum status: [:active, :archived, :active]
#
#   # good
#   enum status: [:active, :archived]

New cop Rails/EnumUniqueness checks for duplicate values defined in enum config hash. (@olliebennett)

ひとつ↑のハッシュ版

#   # bad
#   enum status: { active: 0, archived: 0 }
#
#   # good
#   enum status: { active: 0, archived: 1 }

Add new require_parentheses_when_complex style to Style/TernaryParentheses cop. (@swcraig)

三項演算子の条件のカッコの扱いに関するオプション require_parentheses_when_complex 追加 。

これまでは、全部つける or 外すのどちらかだったが、複雑な条件の場合にカッコつけるような選択ができる。

EnforcedStyle: require_parentheses_when_complex
#   @bad
#   foo = (bar?) ? a : b
#   foo = (bar.baz?) ? a : b
#   foo = bar && baz ? a : b
#
#   @good
#   foo = bar? ? a : b
#   foo = bar.baz ? a : b
#   foo = (bar && baz) ? a : b

Add new Bundler/OrderedGems cop. (@tdeo)

Gemfile の宣言順をアルファベット順になっているかどうかを検証する Cop。

補足

  • 空行で止まる
  • -a オプションによるオートコレクトまではやってくれない
## 怒られない
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'

gem 'rubocop', '0.46.0'
## 怒られる
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'
gem 'rubocop', '0.46.0'

Add new configuration option IgnoredPatterns to Metrics/LineLength. (@jonas054)

パターン指定でのチェック対象から外せるようになった

IgnoredPatterns:
  - '^\s*test\s.*'

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0