From a386aa86571065aaa4979c6138897cedd64a27cd Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Wed, 5 Dec 2018 15:00:27 +0100 Subject: [PATCH] Update style based on new Shopify Rules: - For the context on why we decided to add parenthesis around all method call, you can read about it here https://medium.com/@gmalette/revoking-the-privilege-b2af90a84d84 --- ...ify-github-io-ruby-style-guide-rubocop-yml | 24 ++++++++++++++++--- .rubocop.yml | 7 +++++- Rakefile | 2 +- deprecation_toolkit.gemspec | 10 ++++---- lib/deprecation_toolkit.rb | 2 +- lib/minitest/deprecation_toolkit_plugin.rb | 2 +- .../behaviors/raise_test.rb | 4 ++-- .../behaviors/record_test.rb | 2 +- test/deprecation_toolkit/warning_test.rb | 2 +- .../deprecation_toolkit_plugin_test.rb | 12 ++++------ test/test_helper.rb | 2 +- 11 files changed, 45 insertions(+), 24 deletions(-) diff --git a/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml b/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml index 29b194b..ab449a9 100644 --- a/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +++ b/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml @@ -1,9 +1,8 @@ -# Recommended rubocop version: ~> 0.56.0 - AllCops: Exclude: - 'db/schema.rb' DisabledByDefault: true + StyleGuideBaseURL: https://shopify.github.io/ruby-style-guide/ Layout/AccessModifierIndentation: EnforcedStyle: indent @@ -102,7 +101,7 @@ Style/ClassCheck: - kind_of? Style/CommandLiteral: - EnforcedStyle: backticks + EnforcedStyle: percent_x SupportedStyles: - backticks - percent_x @@ -259,6 +258,19 @@ Style/Next: Style/NonNilCheck: IncludeSemanticChanges: false +Style/MethodCallWithArgsParentheses: + Enabled: true + IgnoreMacros: true + IgnoredMethods: + - require + - require_relative + - require_dependency + - yield + - raise + - puts + Exclude: + - Gemfile + Style/MethodDefParentheses: EnforcedStyle: require_parentheses SupportedStyles: @@ -1110,6 +1122,9 @@ Performance/RedundantMatch: Performance/RedundantSortBy: Enabled: true +Performance/RegexpMatch: + Enabled: true + Performance/ReverseEach: Enabled: true @@ -1136,6 +1151,9 @@ Rails/HttpPositionalArguments: - spec/**/* - test/**/* +Rails/InverseOf: + Enabled: true + Rails/OutputSafety: Enabled: true diff --git a/.rubocop.yml b/.rubocop.yml index 50c1cc3..5739925 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,4 +2,9 @@ inherit_from: - https://shopify.github.io/ruby-style-guide/rubocop.yml AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.5 + +Style/MethodCallWithArgsParentheses: + Exclude: + - Gemfile + - gemfiles/* diff --git a/Rakefile b/Rakefile index 0f4306b..d662d36 100644 --- a/Rakefile +++ b/Rakefile @@ -10,4 +10,4 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/*_test.rb"] end -task default: :test +task(default: :test) diff --git a/deprecation_toolkit.gemspec b/deprecation_toolkit.gemspec index e95b5b6..fbcad2e 100644 --- a/deprecation_toolkit.gemspec +++ b/deprecation_toolkit.gemspec @@ -20,14 +20,14 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.3' - spec.files = `git ls-files -z`.split("\x0").reject do |f| + spec.files = %x(git ls-files -z).split("\x0").reject do |f| f.match(%r{^(test)/}) end spec.require_paths = %w(lib) - spec.add_runtime_dependency 'activesupport', '>= 4.2' + spec.add_runtime_dependency('activesupport', '>= 4.2') - spec.add_development_dependency "bundler", "~> 1.16" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "minitest", "~> 5.0" + spec.add_development_dependency("bundler", "~> 1.16") + spec.add_development_dependency("rake", "~> 10.0") + spec.add_development_dependency("minitest", "~> 5.0") end diff --git a/lib/deprecation_toolkit.rb b/lib/deprecation_toolkit.rb index de4defa..c332f08 100644 --- a/lib/deprecation_toolkit.rb +++ b/lib/deprecation_toolkit.rb @@ -25,7 +25,7 @@ def self.attach_subscriber return if DeprecationSubscriber.already_attached? Configuration.attach_to.each do |gem_name| - DeprecationSubscriber.attach_to gem_name + DeprecationSubscriber.attach_to(gem_name) end end end diff --git a/lib/minitest/deprecation_toolkit_plugin.rb b/lib/minitest/deprecation_toolkit_plugin.rb index 9a3f70b..8111e61 100644 --- a/lib/minitest/deprecation_toolkit_plugin.rb +++ b/lib/minitest/deprecation_toolkit_plugin.rb @@ -4,7 +4,7 @@ module Minitest extend self def plugin_deprecation_toolkit_options(opts, options) - opts.on "-r", "--record-deprecations", "Record deprecations" do + opts.on("-r", "--record-deprecations", "Record deprecations") do options[:record_deprecations] = true end end diff --git a/test/deprecation_toolkit/behaviors/raise_test.rb b/test/deprecation_toolkit/behaviors/raise_test.rb index 6d16941..04ec122 100644 --- a/test/deprecation_toolkit/behaviors/raise_test.rb +++ b/test/deprecation_toolkit/behaviors/raise_test.rb @@ -71,7 +71,7 @@ def deprecation_callee old_allowed_deprecations = Configuration.allowed_deprecations Configuration.allowed_deprecations = [ - ->(_, stack) { stack.first.to_s =~ /my_file\.rb/ } + ->(_, stack) { stack.first.to_s =~ /my_file\.rb/ }, ] begin @@ -86,7 +86,7 @@ def trigger_deprecation_toolkit_behavior super flunk if defined?(@expected_exception) rescue DeprecationIntroduced, DeprecationRemoved, DeprecationMismatch => e - assert_equal @expected_exception, e.class + assert_equal(@expected_exception, e.class) end end end diff --git a/test/deprecation_toolkit/behaviors/record_test.rb b/test/deprecation_toolkit/behaviors/record_test.rb index 6453678..0ee3a0b 100644 --- a/test/deprecation_toolkit/behaviors/record_test.rb +++ b/test/deprecation_toolkit/behaviors/record_test.rb @@ -64,7 +64,7 @@ def assert_deprecations_recorded(*deprecation_triggered) recorded = YAML.load_file("#{@deprecation_path}/deprecation_toolkit/behaviors/record_test.yml").fetch(name) triggered = deprecation_triggered.map { |msg| "DEPRECATION WARNING: #{msg}" } - assert_equal recorded, triggered + assert_equal(recorded, triggered) end end end diff --git a/test/deprecation_toolkit/warning_test.rb b/test/deprecation_toolkit/warning_test.rb index e592ba5..d462f28 100644 --- a/test/deprecation_toolkit/warning_test.rb +++ b/test/deprecation_toolkit/warning_test.rb @@ -26,7 +26,7 @@ class WarningTest < ActiveSupport::TestCase Configuration.warnings_treated_as_deprecation = [/#example is deprecated/] assert_raises Behaviors::DeprecationIntroduced do - Kernel.warn '#example is deprecated' + Kernel.warn('#example is deprecated') trigger_deprecation_toolkit_behavior end diff --git a/test/minitest/deprecation_toolkit_plugin_test.rb b/test/minitest/deprecation_toolkit_plugin_test.rb index bdc2ce5..f724671 100644 --- a/test/minitest/deprecation_toolkit_plugin_test.rb +++ b/test/minitest/deprecation_toolkit_plugin_test.rb @@ -16,14 +16,12 @@ class DeprecationToolkitPluginTest < ActiveSupport::TestCase end test ".plugin_deprecation_toolkit_init set the behavior to `Record` when `record_deprecations` options is true" do - begin - previous_behavior = DeprecationToolkit::Configuration.behavior - Minitest.plugin_deprecation_toolkit_init(record_deprecations: true) + previous_behavior = DeprecationToolkit::Configuration.behavior + Minitest.plugin_deprecation_toolkit_init(record_deprecations: true) - assert_equal DeprecationToolkit::Behaviors::Record, DeprecationToolkit::Configuration.behavior - ensure - DeprecationToolkit::Configuration.behavior = previous_behavior - end + assert_equal(DeprecationToolkit::Behaviors::Record, DeprecationToolkit::Configuration.behavior) + ensure + DeprecationToolkit::Configuration.behavior = previous_behavior end test ".plugin_deprecation_toolkit_init add `notify` behavior to the deprecations behavior list" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 7ec3da7..6b628e3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +$LOAD_PATH.unshift(File.expand_path("../lib", __dir__)) require "deprecation_toolkit" require "minitest/autorun"