aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2018-07-03 12:11:28 +0900
committerKoichi ITO <koic.ito@gmail.com>2018-07-26 17:48:07 +0900
commit211b10aea6313582e2f837edd297af4aeb33c8dc (patch)
tree9e5b037b2d9ae2b65182d154fd7426bed3b14a20
parent91fd679710118482f718ea710710561f1cfb0b70 (diff)
downloadrails-211b10aea6313582e2f837edd297af4aeb33c8dc.tar.gz
rails-211b10aea6313582e2f837edd297af4aeb33c8dc.tar.bz2
rails-211b10aea6313582e2f837edd297af4aeb33c8dc.zip
Bump RuboCop to 0.58.2
## Summary RuboCop 0.58.2 was released. https://github.com/rubocop-hq/rubocop/releases/tag/v0.58.2 And rubocop-0-58 channel is available in Code Climate. https://github.com/codeclimate/codeclimate/releases/tag/v0.76.0 https://github.com/codeclimate/codeclimate/commit/38f21f0 In addition, the following changes are made in this PR. - Replace Custom cops with Rails cops - Add jaro_winkler gem to Gemfile.lock ### Replace Custom cops with Rails cops These are compatible replacements. - Replace `CustomCops/AssertNot` cop with `Rails/AssertNot` cop. - Replace `CustomCops/RefuteNot` cop with `Rails/RefuteMethods` cop. With this replacement, it was decided to use cop of RuboCop itself. It removes the code related to CustomCops accordingly. ### Add jaro_winkler gem to Gemfile.lock Since RuboCop 0.57.0 depends on jaro_winkler gem, it has been added to Gemfile.lock.
-rw-r--r--.codeclimate.yml2
-rw-r--r--.rubocop.yml13
-rw-r--r--Gemfile.lock13
-rwxr-xr-xci/custom_cops/bin/test5
-rw-r--r--ci/custom_cops/lib/custom_cops.rb4
-rw-r--r--ci/custom_cops/lib/custom_cops/assert_not.rb40
-rw-r--r--ci/custom_cops/lib/custom_cops/refute_not.rb71
-rw-r--r--ci/custom_cops/test/custom_cops/assert_not_test.rb42
-rw-r--r--ci/custom_cops/test/custom_cops/refute_not_test.rb66
-rw-r--r--ci/custom_cops/test/support/cop_helper.rb47
10 files changed, 16 insertions, 287 deletions
diff --git a/.codeclimate.yml b/.codeclimate.yml
index 7d4ec1c54f..7fd35d8241 100644
--- a/.codeclimate.yml
+++ b/.codeclimate.yml
@@ -23,7 +23,7 @@ checks:
engines:
rubocop:
enabled: true
- channel: rubocop-0-54
+ channel: rubocop-0-58
ratings:
paths:
diff --git a/.rubocop.yml b/.rubocop.yml
index d1e8f03f13..9db88cbbdf 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,5 +1,3 @@
-require: './ci/custom_cops/lib/custom_cops'
-
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
@@ -11,13 +9,16 @@ AllCops:
- 'actionpack/lib/action_dispatch/journey/parser.rb'
- 'railties/test/fixtures/tmp/**/*'
-# Prefer assert_not_x over refute_x
-CustomCops/RefuteNot:
+Rails:
+ Enabled: true
+
+# Prefer assert_not over assert !
+Rails/AssertNot:
Include:
- '**/test/**/*'
-# Prefer assert_not over assert !
-CustomCops/AssertNot:
+# Prefer assert_not_x over refute_x
+Rails/RefuteMethods:
Include:
- '**/test/**/*'
diff --git a/Gemfile.lock b/Gemfile.lock
index 9c28735a0d..259221979e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -280,6 +280,8 @@ GEM
mini_magick (~> 4.0)
ruby-vips (>= 2.0.10, < 3)
io-like (0.3.0)
+ jaro_winkler (1.5.1)
+ jaro_winkler (1.5.1-java)
jdbc-mysql (5.1.46)
jdbc-postgres (42.1.4)
jdbc-sqlite3 (3.20.1)
@@ -347,13 +349,13 @@ GEM
mini_portile2 (~> 2.3.0)
os (0.9.6)
parallel (1.12.1)
- parser (2.5.1.0)
+ parser (2.5.1.2)
ast (~> 2.4.0)
path_expander (1.0.3)
pg (1.0.0)
pg (1.0.0-x64-mingw32)
pg (1.0.0-x86-mingw32)
- powerpack (0.1.1)
+ powerpack (0.1.2)
psych (3.0.2)
public_suffix (3.0.2)
puma (3.11.4)
@@ -400,9 +402,10 @@ GEM
resque (~> 1.26)
rufus-scheduler (~> 3.2)
retriable (3.1.1)
- rubocop (0.56.0)
+ rubocop (0.58.2)
+ jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
- parser (>= 2.5)
+ parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
@@ -485,7 +488,7 @@ GEM
uber (0.1.0)
uglifier (4.1.10)
execjs (>= 0.3.0, < 3)
- unicode-display_width (1.3.3)
+ unicode-display_width (1.4.0)
useragent (0.16.10)
vegas (0.1.11)
rack (>= 1.0.0)
diff --git a/ci/custom_cops/bin/test b/ci/custom_cops/bin/test
deleted file mode 100755
index 495ffec83a..0000000000
--- a/ci/custom_cops/bin/test
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-COMPONENT_ROOT = File.expand_path("..", __dir__)
-require_relative "../../../tools/test"
diff --git a/ci/custom_cops/lib/custom_cops.rb b/ci/custom_cops/lib/custom_cops.rb
deleted file mode 100644
index 157b8247e4..0000000000
--- a/ci/custom_cops/lib/custom_cops.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# frozen_string_literal: true
-
-require_relative "custom_cops/refute_not"
-require_relative "custom_cops/assert_not"
diff --git a/ci/custom_cops/lib/custom_cops/assert_not.rb b/ci/custom_cops/lib/custom_cops/assert_not.rb
deleted file mode 100644
index 8b49d3eac2..0000000000
--- a/ci/custom_cops/lib/custom_cops/assert_not.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-module CustomCops
- # Enforces the use of `assert_not` over `assert !`.
- #
- # @example
- # # bad
- # assert !x
- # assert ! x
- #
- # # good
- # assert_not x
- #
- class AssertNot < RuboCop::Cop::Cop
- MSG = "Prefer `assert_not` over `assert !`"
-
- def_node_matcher :offensive?, "(send nil? :assert (send ... :!) ...)"
-
- def on_send(node)
- add_offense(node) if offensive?(node)
- end
-
- def autocorrect(node)
- expression = node.loc.expression
-
- ->(corrector) do
- corrector.replace(
- expression,
- corrected_source(expression.source)
- )
- end
- end
-
- private
-
- def corrected_source(source)
- source.gsub(/^assert(\(| ) *! */, "assert_not\\1")
- end
- end
-end
diff --git a/ci/custom_cops/lib/custom_cops/refute_not.rb b/ci/custom_cops/lib/custom_cops/refute_not.rb
deleted file mode 100644
index 3e89e0fd32..0000000000
--- a/ci/custom_cops/lib/custom_cops/refute_not.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# frozen_string_literal: true
-
-module CustomCops
- # Enforces the use of `#assert_not` methods over `#refute` methods.
- #
- # @example
- # # bad
- # refute false
- # refute_empty [1, 2, 3]
- # refute_equal true, false
- #
- # # good
- # assert_not false
- # assert_not_empty [1, 2, 3]
- # assert_not_equal true, false
- #
- class RefuteNot < RuboCop::Cop::Cop
- MSG = "Prefer `%<assert_method>s` over `%<refute_method>s`"
-
- CORRECTIONS = {
- refute: "assert_not",
- refute_empty: "assert_not_empty",
- refute_equal: "assert_not_equal",
- refute_in_delta: "assert_not_in_delta",
- refute_in_epsilon: "assert_not_in_epsilon",
- refute_includes: "assert_not_includes",
- refute_instance_of: "assert_not_instance_of",
- refute_kind_of: "assert_not_kind_of",
- refute_nil: "assert_not_nil",
- refute_operator: "assert_not_operator",
- refute_predicate: "assert_not_predicate",
- refute_respond_to: "assert_not_respond_to",
- refute_same: "assert_not_same",
- refute_match: "assert_no_match"
- }.freeze
-
- OFFENSIVE_METHODS = CORRECTIONS.keys.freeze
-
- def_node_matcher :offensive?, "(send nil? #offensive_method? ...)"
-
- def on_send(node)
- return unless offensive?(node)
-
- message = offense_message(node.method_name)
- add_offense(node, location: :selector, message: message)
- end
-
- def autocorrect(node)
- ->(corrector) do
- corrector.replace(
- node.loc.selector,
- CORRECTIONS[node.method_name]
- )
- end
- end
-
- private
-
- def offensive_method?(method_name)
- OFFENSIVE_METHODS.include?(method_name)
- end
-
- def offense_message(method_name)
- format(
- MSG,
- refute_method: method_name,
- assert_method: CORRECTIONS[method_name]
- )
- end
- end
-end
diff --git a/ci/custom_cops/test/custom_cops/assert_not_test.rb b/ci/custom_cops/test/custom_cops/assert_not_test.rb
deleted file mode 100644
index abb151aeb4..0000000000
--- a/ci/custom_cops/test/custom_cops/assert_not_test.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# frozen_string_literal: true
-
-require "support/cop_helper"
-require_relative "../../lib/custom_cops/assert_not"
-
-class AssertNotTest < ActiveSupport::TestCase
- include CopHelper
-
- setup do
- @cop = CustomCops::AssertNot.new
- end
-
- test "rejects 'assert !'" do
- inspect_source @cop, "assert !x"
- assert_offense @cop, "^^^^^^^^^ Prefer `assert_not` over `assert !`"
- end
-
- test "rejects 'assert !' with a complex value" do
- inspect_source @cop, "assert !a.b(c)"
- assert_offense @cop, "^^^^^^^^^^^^^^ Prefer `assert_not` over `assert !`"
- end
-
- test "autocorrects `assert !`" do
- corrected = autocorrect_source(@cop, "assert !false")
- assert_equal "assert_not false", corrected
- end
-
- test "autocorrects `assert !` with extra spaces" do
- corrected = autocorrect_source(@cop, "assert ! false")
- assert_equal "assert_not false", corrected
- end
-
- test "autocorrects `assert !` with parentheses" do
- corrected = autocorrect_source(@cop, "assert(!false)")
- assert_equal "assert_not(false)", corrected
- end
-
- test "accepts `assert_not`" do
- inspect_source @cop, "assert_not x"
- assert_empty @cop.offenses
- end
-end
diff --git a/ci/custom_cops/test/custom_cops/refute_not_test.rb b/ci/custom_cops/test/custom_cops/refute_not_test.rb
deleted file mode 100644
index f0f6eaeda0..0000000000
--- a/ci/custom_cops/test/custom_cops/refute_not_test.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-# frozen_string_literal: true
-
-require "support/cop_helper"
-require_relative "../../lib/custom_cops/refute_not"
-
-class RefuteNotTest < ActiveSupport::TestCase
- include CopHelper
-
- setup do
- @cop = CustomCops::RefuteNot.new
- end
-
- {
- refute: :assert_not,
- refute_empty: :assert_not_empty,
- refute_equal: :assert_not_equal,
- refute_in_delta: :assert_not_in_delta,
- refute_in_epsilon: :assert_not_in_epsilon,
- refute_includes: :assert_not_includes,
- refute_instance_of: :assert_not_instance_of,
- refute_kind_of: :assert_not_kind_of,
- refute_nil: :assert_not_nil,
- refute_operator: :assert_not_operator,
- refute_predicate: :assert_not_predicate,
- refute_respond_to: :assert_not_respond_to,
- refute_same: :assert_not_same,
- refute_match: :assert_no_match
- }.each do |refute_method, assert_method|
- test "rejects `#{refute_method}` with a single argument" do
- inspect_source(@cop, "#{refute_method} a")
- assert_offense @cop, offense_message(refute_method, assert_method)
- end
-
- test "rejects `#{refute_method}` with multiple arguments" do
- inspect_source(@cop, "#{refute_method} a, b, c")
- assert_offense @cop, offense_message(refute_method, assert_method)
- end
-
- test "autocorrects `#{refute_method}` with a single argument" do
- corrected = autocorrect_source(@cop, "#{refute_method} a")
- assert_equal "#{assert_method} a", corrected
- end
-
- test "autocorrects `#{refute_method}` with multiple arguments" do
- corrected = autocorrect_source(@cop, "#{refute_method} a, b, c")
- assert_equal "#{assert_method} a, b, c", corrected
- end
-
- test "accepts `#{assert_method}` with a single argument" do
- inspect_source(@cop, "#{assert_method} a")
- assert_empty @cop.offenses
- end
-
- test "accepts `#{assert_method}` with multiple arguments" do
- inspect_source(@cop, "#{assert_method} a, b, c")
- assert_empty @cop.offenses
- end
- end
-
- private
-
- def offense_message(refute_method, assert_method)
- carets = "^" * refute_method.to_s.length
- "#{carets} Prefer `#{assert_method}` over `#{refute_method}`"
- end
-end
diff --git a/ci/custom_cops/test/support/cop_helper.rb b/ci/custom_cops/test/support/cop_helper.rb
deleted file mode 100644
index c2c6b969dd..0000000000
--- a/ci/custom_cops/test/support/cop_helper.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-# frozen_string_literal: true
-
-require "rubocop"
-
-module CopHelper
- def inspect_source(cop, source)
- processed_source = parse_source(source)
- raise "Error parsing example code" unless processed_source.valid_syntax?
- investigate(cop, processed_source)
- processed_source
- end
-
- def autocorrect_source(cop, source)
- cop.instance_variable_get(:@options)[:auto_correct] = true
- processed_source = inspect_source(cop, source)
- rewrite(cop, processed_source)
- end
-
- def assert_offense(cop, expected_message)
- assert_not_empty(
- cop.offenses,
- "Expected offense with message \"#{expected_message}\", but got no offense"
- )
-
- offense = cop.offenses.first
- carets = "^" * offense.column_length
-
- assert_equal expected_message, "#{carets} #{offense.message}"
- end
-
- private
- TARGET_RUBY_VERSION = 2.4
-
- def parse_source(source)
- RuboCop::ProcessedSource.new(source, TARGET_RUBY_VERSION)
- end
-
- def rewrite(cop, processed_source)
- RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
- .rewrite
- end
-
- def investigate(cop, processed_source)
- RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
- .investigate(processed_source)
- end
-end