Skip to content

Commit

Permalink
RuboCop corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 30, 2024
1 parent db6227f commit ebe1c26
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 44 deletions.
14 changes: 8 additions & 6 deletions gem/exe/repo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module RBICentral
LOG
end

if checks.none?
unless checks.any? # rubocop:disable Style/InvertibleUnlessCondition
log("No change detected. Run with `--all` to run all checks.")
return
end
Expand Down Expand Up @@ -168,14 +168,16 @@ module RBICentral
end

class Main < Thor
extend T::Sig

desc "check", "Check repo validity"
subcommand "check", RBICentral::CLI::Check

sig { returns(T::Boolean) }
def self.exit_on_failure?
true
class << self
extend T::Sig

sig { returns(T::Boolean) }
def exit_on_failure?
true
end
end
end
end
Expand Down
14 changes: 9 additions & 5 deletions gem/lib/rbi-central.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ module RBICentral

class Error < StandardError; end

sig { params(string: String).returns(String) }
def self.filter_parser_warning(string)
string
.gsub(/warning:.*\n/, "")
.gsub(/Please.*\n/, "")
class << self
extend T::Sig

sig { params(string: String).returns(String) }
def filter_parser_warning(string)
string
.gsub(/warning:.*\n/, "")
.gsub(/Please.*\n/, "")
end
end
end

Expand Down
24 changes: 14 additions & 10 deletions gem/lib/rbi-central/cli/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,20 @@ class ChecksSelection < T::Struct
prop :runtime, T::Boolean
prop :static, T::Boolean

sig { params(options: T::Hash[Symbol, T.untyped]).returns(ChecksSelection) }
def self.from_options(options)
ChecksSelection.new(
gem_tests: options[:gem],
index: options[:index],
rubocop: options[:rubocop],
rubygems: options[:rubygems],
runtime: options[:runtime],
static: options[:static],
)
class << self
extend T::Sig

sig { params(options: T::Hash[Symbol, T.untyped]).returns(ChecksSelection) }
def from_options(options)
ChecksSelection.new(
gem_tests: options[:gem],
index: options[:index],
rubocop: options[:rubocop],
rubygems: options[:rubygems],
runtime: options[:runtime],
static: options[:static],
)
end
end

sig { returns(T::Boolean) }
Expand Down
21 changes: 12 additions & 9 deletions gem/lib/rbi-central/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class Error < RBICentral::Error; end
const :dependencies, T::Array[String], default: []
const :requires, T::Array[String], default: []

sig { params(name: String, object: T::Hash[String, T.untyped]).returns(Gem) }
def self.from_object(name, object = {})
Gem.new(
name: name,
path: object["path"],
source: object["source"],
dependencies: object["dependencies"] || [],
requires: object["requires"] || [],
)
class << self
extend T::Sig
sig { params(name: String, object: T::Hash[String, T.untyped]).returns(Gem) }
def from_object(name, object = {})
Gem.new(
name: name,
path: object["path"],
source: object["source"],
dependencies: object["dependencies"] || [],
requires: object["requires"] || [],
)
end
end

sig { params(_args: T.untyped).returns(T::Hash[String, T.untyped]) }
Expand Down
30 changes: 17 additions & 13 deletions gem/lib/rbi-central/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ class Index < T::Struct

class Error < RBICentral::Error; end

sig { params(object: T::Hash[String, T.untyped]).returns(Index) }
def self.from_object(object)
Index.new(gems: object.map { |name, gem_object| [name, Gem.from_object(name, gem_object)] }.to_h)
end
class << self
extend T::Sig

sig { params(before: Index, after: Index).returns(ChangeSet) }
def self.compare(before:, after:)
ChangeSet.new(
before: before,
after: after,
added: after.gems.values.select { |gem| !before.gem?(gem.name) },
removed: before.gems.values.select { |gem| !after.gem?(gem.name) },
updated: before.gems.values.select { |gem| after.gem?(gem.name) && after[gem.name] != gem },
)
sig { params(object: T::Hash[String, T.untyped]).returns(Index) }
def from_object(object)
Index.new(gems: object.map { |name, gem_object| [name, Gem.from_object(name, gem_object)] }.to_h)
end

sig { params(before: Index, after: Index).returns(ChangeSet) }
def compare(before:, after:)
ChangeSet.new(
before: before,
after: after,
added: after.gems.values.select { |gem| !before.gem?(gem.name) },
removed: before.gems.values.select { |gem| !after.gem?(gem.name) },
updated: before.gems.values.select { |gem| after.gem?(gem.name) && after[gem.name] != gem },
)
end
end

sig { params(name: String).returns(Gem) }
Expand Down
2 changes: 1 addition & 1 deletion gem/test/rbi-central/repo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_check_unexpected_annotations_files

assert_messages(
[
"Unexpected RBI annotations file `rbi/annotations/dir/file4.rbi` (must be in `rbi/annotations` root directory)",
"Unexpected RBI annotations file `rbi/annotations/dir/file4.rbi` (must be in `rbi/annotations` root directory)", # rubocop:disable Layout/LineLength
"Unexpected RBI annotations file `rbi/annotations/file1` (should have `.rbi` extension)",
"Unexpected RBI annotations file `rbi/annotations/file2.rb` (should have `.rbi` extension)",
"Unexpected RBI annotations file `rbi/annotations/file3.RBI` (should have `.rbi` extension)",
Expand Down

0 comments on commit ebe1c26

Please sign in to comment.