Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to rubocop 1.13.0 and re-enable Bundler/GemComment. #44

Merged
merged 6 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions .circleci/config.yml
Expand Up @@ -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: |
Expand All @@ -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"
Expand Down Expand Up @@ -66,7 +66,6 @@ workflows:
matrix:
parameters:
ruby_version:
- "2.5.8"
- "2.6.6"
- "2.7.2"
- "3.0.0"
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -2,7 +2,7 @@ inherit_from:
- conf/rubocop.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.6

Layout/LineLength:
Exclude:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# salsify_rubocop

## 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
is merged.
Expand Down
6 changes: 5 additions & 1 deletion conf/rubocop_without_rspec.yml
@@ -1,3 +1,7 @@
require:
- rubocop-performance
- rubocop-rails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need this change? If we do need it, should the rubocop-rails require go in rubocop_rails.yml?

Copy link
Contributor Author

@ric2b ric2b Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jturkel The need for this is that otherwise we get these errors:
image

As for moving require: rubocop-rails to rubocop_rails.yml, the issue is that this file has the following lines:

Rails:
Enabled: false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this gem depends on rubocop-rails even if the project isn't using Rails so this should be innocuous.


AllCops:
NewCops: disable
DisplayCopNames: true
Expand All @@ -10,10 +14,10 @@ AllCops:
- 'tmp/**/*'
- 'vendor/**/*'

# Don't check version_specifiers until https://github.com/rubocop/rubocop/pull/9358 merges
Bundler/GemComment:
Enabled: true
OnlyFor:
- 'restrictive_version_specificiers'
- 'source'
- 'git'
- 'github'
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/salsify/rspec_doc_string.rb
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/rubocop/cop/salsify/rspec_string_literals.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/salsify_rubocop/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SalsifyRubocop
VERSION = '1.0.2'
VERSION = '1.1.0'
end
4 changes: 2 additions & 2 deletions salsify_rubocop.gemspec
Expand Up @@ -30,14 +30,14 @@ 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.6'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
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'
Expand Down
78 changes: 49 additions & 29 deletions 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

Expand All @@ -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
Expand All @@ -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
Expand Down