From ebe1c2682185d8ec1a25529e0554ea12293f183a Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Tue, 30 Jan 2024 12:22:47 -0500 Subject: [PATCH] RuboCop corrections --- gem/exe/repo | 14 ++++++++------ gem/lib/rbi-central.rb | 14 +++++++++----- gem/lib/rbi-central/cli/helper.rb | 24 ++++++++++++++---------- gem/lib/rbi-central/gem.rb | 21 ++++++++++++--------- gem/lib/rbi-central/index.rb | 30 +++++++++++++++++------------- gem/test/rbi-central/repo_test.rb | 2 +- 6 files changed, 61 insertions(+), 44 deletions(-) diff --git a/gem/exe/repo b/gem/exe/repo index 09d7ca96..451ca5d3 100755 --- a/gem/exe/repo +++ b/gem/exe/repo @@ -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 @@ -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 diff --git a/gem/lib/rbi-central.rb b/gem/lib/rbi-central.rb index 453a19f3..1c3edf00 100644 --- a/gem/lib/rbi-central.rb +++ b/gem/lib/rbi-central.rb @@ -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 diff --git a/gem/lib/rbi-central/cli/helper.rb b/gem/lib/rbi-central/cli/helper.rb index f8a1b13b..603dec83 100644 --- a/gem/lib/rbi-central/cli/helper.rb +++ b/gem/lib/rbi-central/cli/helper.rb @@ -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) } diff --git a/gem/lib/rbi-central/gem.rb b/gem/lib/rbi-central/gem.rb index c9851697..d0ee97b3 100644 --- a/gem/lib/rbi-central/gem.rb +++ b/gem/lib/rbi-central/gem.rb @@ -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]) } diff --git a/gem/lib/rbi-central/index.rb b/gem/lib/rbi-central/index.rb index 9e57db9a..4acc1122 100644 --- a/gem/lib/rbi-central/index.rb +++ b/gem/lib/rbi-central/index.rb @@ -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) } diff --git a/gem/test/rbi-central/repo_test.rb b/gem/test/rbi-central/repo_test.rb index 748c744f..39bbb41d 100644 --- a/gem/test/rbi-central/repo_test.rb +++ b/gem/test/rbi-central/repo_test.rb @@ -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)",