From 3fbf0cb241e773d35b9b123c21ca77e3c247986b Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Tue, 22 Jun 2021 20:40:43 +0100 Subject: [PATCH 1/6] - Re-enable version specifier checks for the `Bundler/GemComment` cop. --- CHANGELOG.md | 3 +++ conf/rubocop_without_rspec.yml | 2 +- lib/salsify_rubocop/version.rb | 2 +- salsify_rubocop.gemspec | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b913392..545c5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # salsify_rubocop +## 1.1.0 +- Re-enable version specifier checks for the `Bundler/GemComment` cop, for limiting version specifiers only. + ## 1.0.2 - Disable version specifier checks for the `Bundler/GemComment` cop until https://github.com/rubocop/rubocop/pull/9358 is merged. diff --git a/conf/rubocop_without_rspec.yml b/conf/rubocop_without_rspec.yml index 881eb94..3d06ca5 100644 --- a/conf/rubocop_without_rspec.yml +++ b/conf/rubocop_without_rspec.yml @@ -10,10 +10,10 @@ AllCops: - 'tmp/**/*' - 'vendor/**/*' -# Don't check version_specifiers until https://github.com/rubocop/rubocop/pull/9358 merges Bundler/GemComment: Enabled: true OnlyFor: + - 'limiting_version_specifiers' - 'source' - 'git' - 'github' diff --git a/lib/salsify_rubocop/version.rb b/lib/salsify_rubocop/version.rb index 69b2d70..759bd6e 100644 --- a/lib/salsify_rubocop/version.rb +++ b/lib/salsify_rubocop/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SalsifyRubocop - VERSION = '1.0.2' + VERSION = '1.1.0' end diff --git a/salsify_rubocop.gemspec b/salsify_rubocop.gemspec index 1c441bd..c4ecd51 100644 --- a/salsify_rubocop.gemspec +++ b/salsify_rubocop.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rspec_junit_formatter' - spec.add_runtime_dependency 'rubocop', '~> 1.0.0' + spec.add_runtime_dependency 'rubocop', '~> 1.13.0' spec.add_runtime_dependency 'rubocop-performance', '~> 1.5.0' spec.add_runtime_dependency 'rubocop-rails', '~> 2.4.0' spec.add_runtime_dependency 'rubocop-rspec', '~> 2.0.0' From d97ee1736d25ad000cf213773b3d7044ffcb927d Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Tue, 22 Jun 2021 20:46:18 +0100 Subject: [PATCH 2/6] Mention rubocop upgrade in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 545c5c9..ef526c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.1.0 - Re-enable version specifier checks for the `Bundler/GemComment` cop, for limiting version specifiers only. +- Upgrade to `rubocop` v1.13.0 ## 1.0.2 - Disable version specifier checks for the `Bundler/GemComment` cop until https://github.com/rubocop/rubocop/pull/9358 From 1d96fca4baf74397028971504cf406602ddc5581 Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Tue, 22 Jun 2021 20:52:40 +0100 Subject: [PATCH 3/6] Fix option name --- conf/rubocop_without_rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/rubocop_without_rspec.yml b/conf/rubocop_without_rspec.yml index 3d06ca5..75f56d8 100644 --- a/conf/rubocop_without_rspec.yml +++ b/conf/rubocop_without_rspec.yml @@ -13,7 +13,7 @@ AllCops: Bundler/GemComment: Enabled: true OnlyFor: - - 'limiting_version_specifiers' + - 'restrictive_version_specificiers' - 'source' - 'git' - 'github' From 4708f67be672eca669d89400e0f41466a8bd1c22 Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Tue, 22 Jun 2021 21:02:10 +0100 Subject: [PATCH 4/6] Apply changes required for updating to 1.13 --- .rubocop.yml | 2 +- conf/rubocop_without_rspec.yml | 4 ++++ salsify_rubocop.gemspec | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1e03f55..129124f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: - conf/rubocop.yml AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 Layout/LineLength: Exclude: diff --git a/conf/rubocop_without_rspec.yml b/conf/rubocop_without_rspec.yml index 75f56d8..d0af7c2 100644 --- a/conf/rubocop_without_rspec.yml +++ b/conf/rubocop_without_rspec.yml @@ -1,3 +1,7 @@ +require: + - rubocop-performance + - rubocop-rails + AllCops: NewCops: disable DisplayCopNames: true diff --git a/salsify_rubocop.gemspec b/salsify_rubocop.gemspec index c4ecd51..509aeec 100644 --- a/salsify_rubocop.gemspec +++ b/salsify_rubocop.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.4' + spec.required_ruby_version = '>= 2.5' spec.add_development_dependency 'bundler', '~> 2.0' spec.add_development_dependency 'rake', '~> 13.0' From bbd011ec725313be4b328c8518aa18cd4d8341c8 Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Thu, 24 Jun 2021 21:52:59 +0100 Subject: [PATCH 5/6] Fix breaking changes detailed in https://docs.rubocop.org/rubocop/v1_upgrade_notes.html --- lib/rubocop/cop/salsify/rspec_doc_string.rb | 6 +- .../cop/salsify/rspec_string_literals.rb | 7 +- .../cop/salsify/rspec_string_literals_spec.rb | 78 ++++++++++++------- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/lib/rubocop/cop/salsify/rspec_doc_string.rb b/lib/rubocop/cop/salsify/rspec_doc_string.rb index 59eaa46..b718737 100644 --- a/lib/rubocop/cop/salsify/rspec_doc_string.rb +++ b/lib/rubocop/cop/salsify/rspec_doc_string.rb @@ -57,9 +57,9 @@ def on_send(node) def check_quotes(doc_node) return unless wrong_quotes?(doc_node) - add_offense(doc_node, - message: style == :single_quotes ? SINGLE_QUOTE_MSG : DOUBLE_QUOTE_MSG, - &StringLiteralCorrector.correct(doc_node, style)) + add_offense(doc_node, message: style == :single_quotes ? SINGLE_QUOTE_MSG : DOUBLE_QUOTE_MSG) do |corrector| + StringLiteralCorrector.correct(corrector, doc_node, style) + end end def wrong_quotes?(node) diff --git a/lib/rubocop/cop/salsify/rspec_string_literals.rb b/lib/rubocop/cop/salsify/rspec_string_literals.rb index 920ba0c..83983c6 100644 --- a/lib/rubocop/cop/salsify/rspec_string_literals.rb +++ b/lib/rubocop/cop/salsify/rspec_string_literals.rb @@ -11,7 +11,8 @@ module Salsify # Used together with Salsify/RspecDocString it allows one quote style to # be used for doc strings (`describe "foobar"`) and another style to be # used for all other strings in specs. - class RspecStringLiterals < Cop + class RspecStringLiterals < RuboCop::Cop::RSpec::Base + extend RuboCop::Cop::AutoCorrector include ConfigurableEnforcedStyle include StringLiteralsHelp @@ -22,8 +23,8 @@ class RspecStringLiterals < Cop DOUBLE_QUOTE_MSG = 'Prefer double-quoted strings unless you need ' \ 'single quotes to avoid extra backslashes for escaping.' - def autocorrect(node) - StringLiteralCorrector.correct(node, style) + def autocorrect(corrector, node) + StringLiteralCorrector.correct(corrector, node, style) end private diff --git a/spec/rubocop/cop/salsify/rspec_string_literals_spec.rb b/spec/rubocop/cop/salsify/rspec_string_literals_spec.rb index 5c6a502..7b89771 100644 --- a/spec/rubocop/cop/salsify/rspec_string_literals_spec.rb +++ b/spec/rubocop/cop/salsify/rspec_string_literals_spec.rb @@ -1,25 +1,29 @@ # frozen_string_literal: true describe RuboCop::Cop::Salsify::RspecStringLiterals, :config do - subject(:cop) { described_class.new(config) } - shared_examples_for "string quoting exceptions" do |name| it "accepts `#{name}` with a single character" do - inspect_source(["#{name} 'ignored' do", '?a', 'end'].join($RS)) - expect(cop.offenses).to be_empty + expect_no_offenses(<<~RUBY) + #{name} 'ignored' do + ?a + end + RUBY end it "accepts `#{name}` with a %q string" do - inspect_source(["#{name} 'ignored' do", '%q(doc string)', 'end'].join($RS)) - expect(cop.offenses).to be_empty + expect_no_offenses(<<~RUBY) + #{name} 'ignored' do + %q(doc string) + end + RUBY end it "accepts `#{name}` with a string the requires interpolation" do - # rubocop:disable Lint/InterpolationCheck - doc_string = '"#{\'DOC\'.downcase} string"' - # rubocop:enable Lint/InterpolationCheck - inspect_source(["#{name} 'ignored' do", doc_string, 'end'].join($RS)) - expect(cop.offenses).to be_empty + expect_no_offenses(<<~RUBY) + #{name} 'ignored' do + "\#{'DOC'.downcase} string" + end + RUBY end end @@ -29,18 +33,26 @@ described_class::DOCUMENTED_METHODS.each do |name| context "within #{name}" do it "corrects a double-quoted string" do - source = ["#{name} \"doc string\" do", '"literal"', 'end'] - inspect_source(source.join($RS)) - expect(cop.messages).to eq([described_class::SINGLE_QUOTE_MSG]) - expect(cop.highlights).to eq([source[1]]) - expect(autocorrect_source(source.join($RS))) - .to eq("#{name} \"doc string\" do\n'literal'\nend") + expect_offense(<<~RUBY) + #{name} "doc string" do + "literal" + ^^^^^^^^^ Prefer single-quoted strings unless you need interpolation or special symbols. + end + RUBY + + expect_correction(<<~RUBY) + #{name} "doc string" do + 'literal' + end + RUBY end it "accepts a single-quoted string" do - source = ["#{name} 'doc string' do", "'literal'", 'end'] - inspect_source(source.join($RS)) - expect(cop.offenses).to be_empty + expect_no_offenses(<<~RUBY) + #{name} 'doc string' do + 'literal' + end + RUBY end it_behaves_like "string quoting exceptions", name @@ -54,18 +66,26 @@ described_class::DOCUMENTED_METHODS.each do |name| context "within #{name}" do it "corrects a single-quoted string" do - source = ["#{name} 'doc string' do", "'literal'", 'end'] - inspect_source(source.join($RS)) - expect(cop.messages).to eq([described_class::DOUBLE_QUOTE_MSG]) - expect(cop.highlights).to eq([source[1]]) - expect(autocorrect_source(source.join($RS))) - .to eq("#{name} 'doc string' do\n\"literal\"\nend") + expect_offense(<<~RUBY) + #{name} 'doc string' do + 'literal' + ^^^^^^^^^ Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. + end + RUBY + + expect_correction(<<~RUBY) + #{name} 'doc string' do + "literal" + end + RUBY end it "accepts a double-quoted string" do - source = ["#{name} \"doc string\" do", '"literal"', 'end'] - inspect_source(source.join($RS)) - expect(cop.offenses).to be_empty + expect_no_offenses(<<~RUBY) + #{name} "doc string" do + "literal" + end + RUBY end it_behaves_like "string quoting exceptions", name From 75c1c6437bc7440f5273769415a7168133642d00 Mon Sep 17 00:00:00 2001 From: Ricardo Amendoeira Date: Mon, 5 Jul 2021 08:36:06 +0100 Subject: [PATCH 6/6] Bump supported version due to 2.5 going EOL --- .circleci/config.yml | 9 ++++----- .rubocop.yml | 2 +- CHANGELOG.md | 1 + salsify_rubocop.gemspec | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 191b07e..3c02608 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,14 +2,14 @@ version: 2.1 jobs: lint: docker: - - image: salsify/ruby_ci:2.5.8 + - image: salsify/ruby_ci:2.6.6 working_directory: ~/salsify_rubocop steps: - checkout - restore_cache: keys: - - v1-gems-ruby-2.5.8-{{ checksum "salsify_rubocop.gemspec" }}-{{ checksum "Gemfile" }} - - v1-gems-ruby-2.5.8- + - v1-gems-ruby-2.6.6-{{ checksum "salsify_rubocop.gemspec" }}-{{ checksum "Gemfile" }} + - v1-gems-ruby-2.6.6- - run: name: Install Gems command: | @@ -18,7 +18,7 @@ jobs: bundle clean fi - save_cache: - key: v1-gems-ruby-2.5.8-{{ checksum "salsify_rubocop.gemspec" }}-{{ checksum "Gemfile" }} + key: v1-gems-ruby-2.6.6-{{ checksum "salsify_rubocop.gemspec" }}-{{ checksum "Gemfile" }} paths: - "vendor/bundle" - "gemfiles/vendor/bundle" @@ -66,7 +66,6 @@ workflows: matrix: parameters: ruby_version: - - "2.5.8" - "2.6.6" - "2.7.2" - "3.0.0" diff --git a/.rubocop.yml b/.rubocop.yml index 129124f..d151021 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: - conf/rubocop.yml AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.6 Layout/LineLength: Exclude: diff --git a/CHANGELOG.md b/CHANGELOG.md index ef526c9..82a3eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.1.0 - Re-enable version specifier checks for the `Bundler/GemComment` cop, for limiting version specifiers only. - Upgrade to `rubocop` v1.13.0 +- Drop support for Ruby 2.5 now that's in EOL ## 1.0.2 - Disable version specifier checks for the `Bundler/GemComment` cop until https://github.com/rubocop/rubocop/pull/9358 diff --git a/salsify_rubocop.gemspec b/salsify_rubocop.gemspec index 509aeec..e51b446 100644 --- a/salsify_rubocop.gemspec +++ b/salsify_rubocop.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.5' + spec.required_ruby_version = '>= 2.6' spec.add_development_dependency 'bundler', '~> 2.0' spec.add_development_dependency 'rake', '~> 13.0'