Skip to content

Commit

Permalink
Fix Rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgiles committed Mar 11, 2023
1 parent 5ec1a94 commit 0e5baea
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 157 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ inherit_gem:
rubocop-shopify: rubocop.yml
require: rubocop-rspec

AllCops:
NewCops: disable

RSpec/LeakyConstantDeclaration:
Enabled: false

Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'rspec/sorbet'
require "bundler/setup"
require "rspec/sorbet"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require 'rspec/sorbet'
# require "pry"
# Pry.start

require 'irb'
require "irb"
IRB.start(__FILE__)
6 changes: 4 additions & 2 deletions bin/tapioca
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
"../../Gemfile",
Pathname.new(__FILE__).realpath,
)

bundle_binstub = File.expand_path("../bundle", __FILE__)

Expand Down
20 changes: 10 additions & 10 deletions generate_require_files.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# typed: true
# frozen_string_literal: true

BASE_FOLDER_PATH = 'rspec'
BASE_FOLDER_PATH = "rspec"

def directories_in(root)
Dir.entries(root).sort.select do |entry|
fully_qualified_entry = File.join(root, entry)
File.directory?(fully_qualified_entry) && !['.', '..'].include?(entry.to_s)
File.directory?(fully_qualified_entry) && ![".", ".."].include?(entry.to_s)
end
end

def files_in(root)
Dir.entries(root).sort.reject do |entry|
fully_qualified_entry = File.join(root, entry)
File.directory?(fully_qualified_entry) || entry.to_s == 'all.rb' || entry[-3..-1] != '.rb'
File.directory?(fully_qualified_entry) || entry.to_s == "all.rb" || entry[-3..-1] != ".rb"
end
end

def recursive_files_in(root)
full_paths = Dir.glob(File.join(root, '**', '*')).sort.reject do |entry|
full_paths = Dir.glob(File.join(root, "**", "*")).sort.reject do |entry|
fully_qualified_entry = File.join(root, entry)
File.directory?(fully_qualified_entry) || entry[-7..-1] == '/all.rb' || entry[-3..-1] != '.rb'
File.directory?(fully_qualified_entry) || entry[-7..-1] == "/all.rb" || entry[-3..-1] != ".rb"
end

remove_path = root.split('/')[0..-2].join('/') + '/'
full_paths.map { |full_path| full_path.gsub(remove_path, '') }
remove_path = root.split("/")[0..-2].join("/") + "/"
full_paths.map { |full_path| full_path.gsub(remove_path, "") }
end

def write_require_file(root, require_directories, require_files)
require_file_path = File.join(root, 'all.rb')
File.open(require_file_path, 'w') do |file|
require_file_path = File.join(root, "all.rb")
File.open(require_file_path, "w") do |file|
file.write("# frozen_string_literal: true\n\n")
file.write("# THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED\n\n")
require_directories.each do |require_directory|
Expand All @@ -40,7 +40,7 @@ def write_require_file(root, require_directories, require_files)
end
end

root = File.join(__dir__, 'lib', BASE_FOLDER_PATH)
root = File.join(__dir__, "lib", BASE_FOLDER_PATH)
directories = directories_in(root)
write_require_file(root, directories, files_in(root))
directories.each do |directory|
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

# THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED

require 'rspec/sorbet/all'
require "rspec/sorbet/all"

require 'rspec/sorbet'
require "rspec/sorbet"
2 changes: 1 addition & 1 deletion lib/rspec/sorbet.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: strict
# frozen_string_literal: true

require 'rspec/sorbet/doubles'
require "rspec/sorbet/doubles"

module RSpec
module Sorbet
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/sorbet/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

# THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED

require 'rspec/sorbet/doubles'
require 'rspec/sorbet/version'
require "rspec/sorbet/doubles"
require "rspec/sorbet/version"
18 changes: 10 additions & 8 deletions lib/rspec/sorbet/doubles.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: false
# frozen_string_literal: true

require 'sorbet-runtime'
require "sorbet-runtime"

module RSpec
module Sorbet
Expand All @@ -22,12 +22,13 @@ def allow_doubles!

private

# rubocop:disable Layout/LineLength
INLINE_DOUBLE_REGEX =
/T.(?:let|cast): Expected type (?:T.(?<t_method>any|nilable|class_of)\()*(?<expected_types>[a-zA-Z0-9:: ,]*)(\))*, got (?:type .* with value )?#<(?<double_type>Instance|Class|Object)?Double([\(]|[ ])(?<doubled_type>[a-zA-Z0-9:: ,]*)(\))?/.freeze

# rubocop:enable Layout/LineLength

def handle_call_validation_error(signature, opts)
raise TypeError, opts[:pretty_message] unless @existing_handler
raise TypeError, opts[:pretty_message] unless @existing_handler

@existing_handler.call(signature, opts)
end
Expand All @@ -41,15 +42,16 @@ def inline_type_error_handler(error)
raise error unless (match = message.match(INLINE_DOUBLE_REGEX))

t_method = match[:t_method]
expected_types = match[:expected_types].split(',').map do |expected_type|
expected_types = match[:expected_types].split(",").map do |expected_type|
Object.const_get(expected_type.strip)
end
double_type = match[:double_type]
return if double_type.nil?

doubled_type = Object.const_get(match[:doubled_type])

if double_type == 'Class'
raise error if t_method != 'class_of'
if double_type == "Class"
raise error if t_method != "class_of"

valid = expected_types.any? do |expected_type|
doubled_type <= expected_type
Expand All @@ -75,7 +77,7 @@ def unable_to_check_type_for_message?(message)
/(RSpec::Mocks::(Instance|Class|Object)VerifyingDouble|(Instance|Class|Object)?Double)/.freeze

def double_message_with_ellipsis?(message)
message.include?('...') && message.match?(VERIFYING_DOUBLE_OR_DOUBLE)
message.include?("...") && message.match?(VERIFYING_DOUBLE_OR_DOUBLE)
end

TYPED_ARRAY_MESSAGE = /got T::Array/.freeze
Expand All @@ -87,7 +89,7 @@ def typed_array_message?(message)
def call_validation_error_handler(signature, opts)
should_raise = true

message = opts.fetch(:pretty_message, opts.fetch(:message, ''))
message = opts.fetch(:pretty_message, opts.fetch(:message, ""))
if message.match?(VERIFYING_DOUBLE_OR_DOUBLE)
typing = opts[:type]
value = opts[:value].is_a?(Array) ? opts[:value].first : opts[:value]
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sorbet/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

module RSpec
module Sorbet
VERSION = '1.9.1'
VERSION = "1.9.1"
end
end
36 changes: 19 additions & 17 deletions rspec-sorbet.gemspec
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
lib = File.expand_path('lib', __dir__)
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'rspec/sorbet/version'
require "rspec/sorbet/version"

Gem::Specification.new do |spec|
spec.name = 'rspec-sorbet'
spec.name = "rspec-sorbet"
spec.version = RSpec::Sorbet::VERSION
spec.authors = ['Samuel Giles']
spec.email = ['[email protected]']
spec.authors = ["Samuel Giles"]
spec.email = ["[email protected]"]

spec.summary = 'A small gem consisting of helpers for using Sorbet & RSpec together.'
spec.homepage = 'https://github.com/tricycle/rspec-sorbet'
spec.license = 'MIT'
spec.summary = "A small gem consisting of helpers for using Sorbet & RSpec together."
spec.homepage = "https://github.com/tricycle/rspec-sorbet"
spec.license = "MIT"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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{^(sorbet|spec)/}) && !f.match(%r{^spec/support/factories/})
end
spec.bindir = 'exe'
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_dependency 'sorbet-runtime'
spec.add_dependency("sorbet-runtime")

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake', '>= 13.0'
spec.add_development_dependency 'rspec', '>= 3.0'
spec.add_development_dependency 'sorbet'
spec.add_development_dependency("bundler")
spec.add_development_dependency("pry")
spec.add_development_dependency("rake", ">= 13.0")
spec.add_development_dependency("rspec", ">= 3.0")
spec.add_development_dependency("sorbet")
end
6 changes: 3 additions & 3 deletions spec/lib/rspec/sorbet/version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# typed: false
# frozen_string_literal: true

require 'rspec/sorbet/version'
require "rspec/sorbet/version"

module RSpec
describe Sorbet do
it 'has a version number' do
expect(described_class::VERSION).not_to be nil
it "has a version number" do
expect(described_class::VERSION).not_to(be(nil))
end
end
end
Loading

0 comments on commit 0e5baea

Please sign in to comment.