From f150cca8aec7004a6ab5c5ef005c8cef5dcd7717 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 30 Nov 2026 12:59:49 -0800 Subject: [PATCH 1/2] Add rubocop-gusto Inherit the shared rubocop-gusto config, as packs, pack_stats and packwerk-extensions already do. - Add rubocop-gusto as a development dependency in the Gemfile, per the repo's `Gemspec/DevelopmentDependencies: EnforcedStyle: Gemfile` - Inherit rubocop-gusto's config/default.yml and load its plugin in place of the separate rubocop-rake and rubocop-rspec entries, which it already provides; the existing cop overrides are kept as-is - Enable `Style/StringLiterals` with double quotes (previously disabled) and convert the codebase to double-quoted strings - Apply safe autocorrections (double quotes, Sorbet sigil order and missing spec sigils, alias_method, trailing comma, argument line breaks) and record the remaining offenses in .rubocop_todo.yml --- .rubocop.yml | 22 +++++-- .rubocop_todo.yml | 53 ++++++++++++++++ Gemfile | 19 +++--- Gemfile.lock | 21 +++++++ Rakefile | 6 +- code_teams.gemspec | 36 +++++------ lib/code_teams.rb | 25 ++++---- lib/code_teams/plugin.rb | 4 +- lib/code_teams/plugins/identity.rb | 6 +- lib/code_teams/testing.rb | 11 ++-- lib/code_teams/testing/rspec_helpers.rb | 7 +-- lib/code_teams/utils.rb | 11 ++-- .../plugin_helper_integration_spec.rb | 47 +++++++------- spec/lib/code_teams/plugin_spec.rb | 29 ++++----- .../r_spec_helpers_integration_spec.rb | 13 ++-- spec/lib/code_teams/testing_spec.rb | 27 ++++---- spec/lib/code_teams/utils_spec.rb | 39 ++++++------ spec/lib/code_teams_spec.rb | 63 ++++++++++--------- spec/spec_helper.rb | 13 ++-- spec/support/io_helpers.rb | 16 +++-- 20 files changed, 282 insertions(+), 186 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index d0e91f0..efa8050 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,14 @@ +inherit_from: .rubocop_todo.yml + +inherit_mode: + merge: + - Exclude + - Include + +inherit_gem: + rubocop-gusto: + - config/default.yml + # The behavior of RuboCop can be controlled via the .rubocop.yml # configuration file. It makes it possible to enable/disable # certain cops (checks) and to alter their behavior if they accept @@ -10,11 +21,11 @@ # See https://docs.rubocop.org/rubocop/configuration plugins: - - rubocop-rake - - rubocop-rspec + - rubocop-gusto AllCops: NewCops: enable + SuggestExtensions: false Exclude: - vendor/bundle/**/** - bin/** @@ -106,9 +117,6 @@ Layout/MultilineMethodCallIndentation: Style/BlockDelimiters: Enabled: false -Style/StringLiterals: - Enabled: false - # Sometimes we like methods like `get_packages` Naming/AccessorMethodName: Enabled: false @@ -135,3 +143,7 @@ RSpec/ExampleLength: RSpec/ContextWording: Enabled: false + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..1d9fd34 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,53 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 10000` +# on 2026-11-30 21:02:27 UTC using RuboCop version 1.92.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +Gusto/NoMetaprogramming: + Exclude: + - 'lib/code_teams.rb' + - 'lib/code_teams/plugin.rb' + +# Offense count: 5 +# This cop supports unsafe autocorrection (--autocorrect-all). +Sorbet/BlockMethodDefinition: + Exclude: + - 'spec/code_teams/plugin_helper_integration_spec.rb' + - 'spec/lib/code_teams/plugin_spec.rb' + - 'spec/lib/code_teams/testing_spec.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AutocorrectToRBS. +Sorbet/ForbidTUnsafe: + Exclude: + - 'lib/code_teams/plugin.rb' + - 'lib/code_teams/testing.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Sorbet/RedundantTLetForLiteral: + Exclude: + - 'lib/code_teams/testing.rb' + +# Offense count: 4 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SuggestedStrictness. +Sorbet/StrictSigil: + Exclude: + - 'lib/code_teams/plugins/identity.rb' + - 'lib/code_teams/testing/rspec_helpers.rb' + - 'spec/spec_helper.rb' + - 'spec/support/io_helpers.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self, forbidden +Style/ModuleFunction: + Exclude: + - 'lib/code_teams/utils.rb' diff --git a/Gemfile b/Gemfile index b494ee2..a2998f5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,16 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in code_teams.gemspec gemspec -gem 'pry' -gem 'rake' -gem 'rspec', '~> 3.13' -gem 'rubocop' -gem 'rubocop-rake' -gem 'rubocop-rspec' -gem 'sorbet' -gem 'tapioca' +gem "pry" +gem "rake" +gem "rspec", "~> 3.13" +gem "rubocop" +gem "rubocop-gusto", require: false +gem "rubocop-rake" +gem "rubocop-rspec" +gem "sorbet" +gem "tapioca" diff --git a/Gemfile.lock b/Gemfile.lock index 13becab..114db08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,20 @@ GEM rubocop-ast (1.50.0) parser (>= 3.3.7.2) prism (~> 1.7) + rubocop-gusto (11.12.0) + code_teams + lint_roller + rubocop (>= 1.76) + rubocop-performance + rubocop-rake + rubocop-rspec + rubocop-sorbet (>= 0.13.0) + smart_todo + thor + rubocop-performance (1.27.0) + lint_roller (~> 1.1) + rubocop (>= 1.89.0, < 2.0) + rubocop-ast (>= 1.47.1, < 2.0) rubocop-rake (0.7.1) lint_roller (~> 1.1) rubocop (>= 1.72.1) @@ -77,10 +91,16 @@ GEM lint_roller (~> 1.1) regexp_parser (>= 2.0) rubocop (~> 1.86, >= 1.86.2) + rubocop-sorbet (0.17.2) + rbi (~> 0.4, >= 0.4.3) + rbs (>= 4.1.1) + spoom (~> 1.8) ruby-progressbar (1.13.0) rubydex (0.4.1-arm64-darwin) rubydex (0.4.1-x86_64-darwin) rubydex (0.4.1-x86_64-linux) + smart_todo (1.11.0) + prism (~> 1.0) sorbet (0.6.13593) sorbet-static (= 0.6.13593) sorbet-runtime (0.6.13593) @@ -125,6 +145,7 @@ DEPENDENCIES rake rspec (~> 3.13) rubocop + rubocop-gusto rubocop-rake rubocop-rspec sorbet diff --git a/Rakefile b/Rakefile index e8ba183..ef026d8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ -# frozen_string_literal: true # typed: ignore +# frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) diff --git a/code_teams.gemspec b/code_teams.gemspec index 33a9462..039c571 100644 --- a/code_teams.gemspec +++ b/code_teams.gemspec @@ -1,28 +1,28 @@ # frozen_string_literal: true Gem::Specification.new do |spec| - spec.name = 'code_teams' - spec.version = '1.3.1' - spec.authors = ['Gusto Engineers'] - spec.email = ['dev@gusto.com'] - spec.summary = 'A low-dependency gem for declaring and querying engineering teams' - spec.description = 'A low-dependency gem for declaring and querying engineering teams' - spec.homepage = 'https://github.com/rubyatscale/code_teams' - spec.license = 'MIT' + spec.name = "code_teams" + spec.version = "1.3.1" + spec.authors = ["Gusto Engineers"] + spec.email = ["dev@gusto.com"] + spec.summary = "A low-dependency gem for declaring and querying engineering teams" + spec.description = "A low-dependency gem for declaring and querying engineering teams" + spec.homepage = "https://github.com/rubyatscale/code_teams" + spec.license = "MIT" if spec.respond_to?(:metadata) - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/rubyatscale/code_teams' - spec.metadata['changelog_uri'] = 'https://github.com/rubyatscale/code_teams/releases' - spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/rubyatscale/code_teams" + spec.metadata["changelog_uri"] = "https://github.com/rubyatscale/code_teams/releases" + spec.metadata["allowed_push_host"] = "https://rubygems.org" else - raise 'RubyGems 2.0 or newer is required to protect against ' \ - 'public gem pushes.' + raise "RubyGems 2.0 or newer is required to protect against " \ + "public gem pushes." end - spec.files = Dir['README.md', 'lib/**/*'] - spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 3.3' + spec.files = Dir["README.md", "lib/**/*"] + spec.require_paths = ["lib"] + spec.required_ruby_version = ">= 3.3" - spec.add_dependency 'sorbet-runtime' + spec.add_dependency "sorbet-runtime" end diff --git a/lib/code_teams.rb b/lib/code_teams.rb index 5f5c1d9..90d55a4 100644 --- a/lib/code_teams.rb +++ b/lib/code_teams.rb @@ -1,13 +1,12 @@ -# frozen_string_literal: true - # typed: strict +# frozen_string_literal: true -require 'yaml' -require 'pathname' -require 'sorbet-runtime' -require 'code_teams/plugin' -require 'code_teams/plugins/identity' -require 'code_teams/utils' +require "yaml" +require "pathname" +require "sorbet-runtime" +require "code_teams/plugin" +require "code_teams/plugins/identity" +require "code_teams/utils" module CodeTeams extend T::Sig @@ -15,12 +14,12 @@ module CodeTeams class IncorrectPublicApiUsageError < StandardError; end class TeamNotFoundError < StandardError; end - UNKNOWN_TEAM_STRING = 'Unknown Team' + UNKNOWN_TEAM_STRING = "Unknown Team" @plugins_registered = T.let(false, T::Boolean) sig { returns(T::Array[Team]) } def self.all - @all ||= T.let(for_directory('config/teams'), T.nilable(T::Array[Team])) + @all ||= T.let(for_directory("config/teams"), T.nilable(T::Array[Team])) end sig { params(name: String).returns(T.nilable(Team)) } @@ -41,7 +40,7 @@ def self.for_directory(dir) @plugins_registered = true end - Pathname.new(dir).glob('**/*.yml').map do |path| + Pathname.new(dir).glob("**/*.yml").map do |path| Team.from_yml(path.to_s) rescue Psych::SyntaxError raise IncorrectPublicApiUsageError, "The YML in #{path} has a syntax error!" @@ -57,7 +56,7 @@ def self.validation_errors(teams) sig { params(string: String).returns(String) } def self.tag_value_for(string) - string.tr('&', ' ').gsub(/\s+/, '_').downcase + string.tr("&", " ").gsub(/\s+/, "_").downcase end # Generally, you should not ever need to do this, because once your ruby process loads, cached content should not change. @@ -139,7 +138,7 @@ def ==(other) end end - alias eql? == + alias_method :eql?, :== sig { returns(Integer) } def hash diff --git a/lib/code_teams/plugin.rb b/lib/code_teams/plugin.rb index 9140388..f193d7f 100644 --- a/lib/code_teams/plugin.rb +++ b/lib/code_teams/plugin.rb @@ -1,5 +1,5 @@ -# frozen_string_literal: true # typed: strict +# frozen_string_literal: true module CodeTeams # Plugins allow a client to add validation on custom keys in the team YML. @@ -66,7 +66,7 @@ def self.registry sig { params(team: Team).returns(T.attached_class) } def self.register_team(team) # We pull from the hash since `team.name` uses the registry - team_name = team.raw_hash['name'] + team_name = team.raw_hash["name"] registry[team_name] ||= {} registry_for_team = registry[team_name] || {} diff --git a/lib/code_teams/plugins/identity.rb b/lib/code_teams/plugins/identity.rb index 46ffed8..8927d49 100644 --- a/lib/code_teams/plugins/identity.rb +++ b/lib/code_teams/plugins/identity.rb @@ -1,5 +1,5 @@ -# frozen_string_literal: true # typed: true +# frozen_string_literal: true module CodeTeams module Plugins @@ -12,7 +12,7 @@ class Identity < Plugin sig { returns(IdentityStruct) } def identity IdentityStruct.new( - @team.raw_hash['name'] + @team.raw_hash["name"] ) end @@ -28,7 +28,7 @@ def self.validation_errors(teams) errors << "More than 1 definition for #{for_team.identity.name} found" end - errors << missing_key_error_message(team, 'name') if for_team.identity.name.nil? + errors << missing_key_error_message(team, "name") if for_team.identity.name.nil? end errors diff --git a/lib/code_teams/testing.rb b/lib/code_teams/testing.rb index f3ecc57..278b9bc 100644 --- a/lib/code_teams/testing.rb +++ b/lib/code_teams/testing.rb @@ -1,10 +1,9 @@ -# frozen_string_literal: true -# # typed: strict +# frozen_string_literal: true -require 'securerandom' -require 'code_teams' -require 'code_teams/testing/rspec_helpers' +require "securerandom" +require "code_teams" +require "code_teams/testing/rspec_helpers" module CodeTeams # Utilities for tests that need a controlled set of teams without writing YML @@ -46,7 +45,7 @@ def self.create_code_team(attributes) attributes[:name] ||= "Fake Team #{SecureRandom.hex(4)}" code_team = CodeTeams::Team.new( - config_yml: 'tmp/fake_config.yml', + config_yml: "tmp/fake_config.yml", raw_hash: Utils.deep_stringify_keys(attributes) ) diff --git a/lib/code_teams/testing/rspec_helpers.rb b/lib/code_teams/testing/rspec_helpers.rb index e04781b..18892c8 100644 --- a/lib/code_teams/testing/rspec_helpers.rb +++ b/lib/code_teams/testing/rspec_helpers.rb @@ -1,9 +1,8 @@ -# frozen_string_literal: true -# # typed: false +# frozen_string_literal: true -require 'securerandom' -require 'code_teams/testing' +require "securerandom" +require "code_teams/testing" module CodeTeams module Testing diff --git a/lib/code_teams/utils.rb b/lib/code_teams/utils.rb index 3d6296a..2074289 100644 --- a/lib/code_teams/utils.rb +++ b/lib/code_teams/utils.rb @@ -1,6 +1,5 @@ -# frozen_string_literal: true -# # typed: strict +# frozen_string_literal: true module CodeTeams module Utils @@ -10,16 +9,16 @@ module Utils sig { params(string: String).returns(String) } def underscore(string) - string.gsub('::', '/') - .gsub(/(?<=[A-Z])(?=[A-Z][a-z])/, '_') + string.gsub("::", "/") + .gsub(/(?<=[A-Z])(?=[A-Z][a-z])/, "_") .gsub(/([a-z\d])([A-Z])/, '\1_\2') - .tr('-', '_') + .tr("-", "_") .downcase end sig { params(string: String).returns(String) } def demodulize(string) - T.must(string.split('::').last) + T.must(string.split("::").last) end # Recursively converts symbol keys to strings. Top-level input should be a Hash. diff --git a/spec/code_teams/plugin_helper_integration_spec.rb b/spec/code_teams/plugin_helper_integration_spec.rb index 5c268bf..f738552 100644 --- a/spec/code_teams/plugin_helper_integration_spec.rb +++ b/spec/code_teams/plugin_helper_integration_spec.rb @@ -1,65 +1,66 @@ +# typed: false # frozen_string_literal: true RSpec.describe CodeTeams::Plugin do before do CodeTeams.bust_caches! - write_team_yml(extra_data: { 'foo' => 'foo', 'bar' => 'bar' }) + write_team_yml(extra_data: { "foo" => "foo", "bar" => "bar" }) end - let(:team) { CodeTeams.find('My Team') } + let(:team) { CodeTeams.find("My Team") } - describe 'helper methods' do - context 'with a single implicit method' do + describe "helper methods" do + context "with a single implicit method" do before do test_plugin_class = Class.new(described_class) do def test_plugin - data = @team.raw_hash['extra_data'] - Data.define(:foo, :bar).new(data['foo'], data['bar']) + data = @team.raw_hash["extra_data"] + Data.define(:foo, :bar).new(data["foo"], data["bar"]) end end - stub_const('TestPlugin', test_plugin_class) + stub_const("TestPlugin", test_plugin_class) end - it 'adds a helper method to the team' do - expect(team.test_plugin.foo).to eq('foo') - expect(team.test_plugin.bar).to eq('bar') + it "adds a helper method to the team" do + expect(team.test_plugin.foo).to eq("foo") + expect(team.test_plugin.bar).to eq("bar") end - it 'supports nested data' do - write_team_yml(extra_data: { 'foo' => { 'bar' => 'bar' } }) - expect(team.test_plugin.foo['bar']).to eq('bar') + it "supports nested data" do + write_team_yml(extra_data: { "foo" => { "bar" => "bar" } }) + expect(team.test_plugin.foo["bar"]).to eq("bar") end end - context 'when the data accessor name is overridden' do + context "when the data accessor name is overridden" do before do test_plugin_class = Class.new(described_class) do - data_accessor_name 'foo' + data_accessor_name "foo" def foo - Data.define(:bar).new('bar') + Data.define(:bar).new("bar") end end - stub_const('TestPlugin', test_plugin_class) + stub_const("TestPlugin", test_plugin_class) end - it 'adds the data accessor name to the team' do - expect(team.foo.bar).to eq('bar') + it "adds the data accessor name to the team" do + expect(team.foo.bar).to eq("bar") end end end - specify 'backwards compatibility' do + specify "backwards compatibility" do test_plugin_class = Class.new(described_class) do def test_plugin - Data.define(:foo).new('foo') + Data.define(:foo).new("foo") end end - stub_const('TestPlugin', test_plugin_class) + stub_const("TestPlugin", test_plugin_class) - expect(TestPlugin.for(team).test_plugin.foo).to eq('foo') + expect(TestPlugin.for(team).test_plugin.foo).to eq("foo") end end diff --git a/spec/lib/code_teams/plugin_spec.rb b/spec/lib/code_teams/plugin_spec.rb index e7e196d..bd58578 100644 --- a/spec/lib/code_teams/plugin_spec.rb +++ b/spec/lib/code_teams/plugin_spec.rb @@ -1,43 +1,44 @@ +# typed: false # frozen_string_literal: true module TestNamespace; end RSpec.describe CodeTeams::Plugin do - describe '.bust_caches!' do - it 'clears all plugins team registries ensuring cached configs are purged' do + describe ".bust_caches!" do + it "clears all plugins team registries ensuring cached configs are purged" do test_plugin_class = Class.new(described_class) do def extra_data - @team.raw_hash['extra_data'] + @team.raw_hash["extra_data"] end end - stub_const('TestNamespace::TestPlugin', test_plugin_class) + stub_const("TestNamespace::TestPlugin", test_plugin_class) CodeTeams.bust_caches! write_team_yml(extra_data: true) - team = CodeTeams.find('My Team') + team = CodeTeams.find("My Team") expect(TestNamespace::TestPlugin.for(team).extra_data).to be(true) write_team_yml(extra_data: false) CodeTeams.bust_caches! - team = CodeTeams.find('My Team') + team = CodeTeams.find("My Team") expect(TestNamespace::TestPlugin.for(team).extra_data).to be(false) end end - describe '.data_accessor_name' do - it 'returns the underscore version of the plugin name' do + describe ".data_accessor_name" do + it "returns the underscore version of the plugin name" do test_plugin_class = Class.new(described_class) - stub_const('TestNamespace::TestPlugin', test_plugin_class) + stub_const("TestNamespace::TestPlugin", test_plugin_class) - expect(TestNamespace::TestPlugin.data_accessor_name).to eq('test_plugin') + expect(TestNamespace::TestPlugin.data_accessor_name).to eq("test_plugin") end - it 'can be overridden by a subclass' do + it "can be overridden by a subclass" do test_plugin_class = Class.new(described_class) do - data_accessor_name 'foo' + data_accessor_name "foo" end - stub_const('TestNamespace::TestPlugin', test_plugin_class) + stub_const("TestNamespace::TestPlugin", test_plugin_class) - expect(TestNamespace::TestPlugin.data_accessor_name).to eq('foo') + expect(TestNamespace::TestPlugin.data_accessor_name).to eq("foo") end end end diff --git a/spec/lib/code_teams/testing/r_spec_helpers_integration_spec.rb b/spec/lib/code_teams/testing/r_spec_helpers_integration_spec.rb index 1bdbcd2..621c820 100644 --- a/spec/lib/code_teams/testing/r_spec_helpers_integration_spec.rb +++ b/spec/lib/code_teams/testing/r_spec_helpers_integration_spec.rb @@ -1,18 +1,19 @@ +# typed: false # frozen_string_literal: true -require 'code_teams/testing' +require "code_teams/testing" CodeTeams::Testing.enable! RSpec.describe CodeTeams::Testing::RSpecHelpers do - it 'exposes code_team_with_config and makes the team discoverable' do - code_team_with_config(name: 'RSpec Team') + it "exposes code_team_with_config and makes the team discoverable" do + code_team_with_config(name: "RSpec Team") - expect(CodeTeams.find('RSpec Team')).not_to be_nil + expect(CodeTeams.find("RSpec Team")).not_to be_nil end - it 'cleans up testing teams between examples' do + it "cleans up testing teams between examples" do expect(CodeTeams::Testing.code_teams).to be_empty - expect(CodeTeams.find('RSpec Team')).to be_nil + expect(CodeTeams.find("RSpec Team")).to be_nil end end diff --git a/spec/lib/code_teams/testing_spec.rb b/spec/lib/code_teams/testing_spec.rb index d0743a3..9691cb3 100644 --- a/spec/lib/code_teams/testing_spec.rb +++ b/spec/lib/code_teams/testing_spec.rb @@ -1,35 +1,36 @@ +# typed: false # frozen_string_literal: true -require 'code_teams/testing' +require "code_teams/testing" CodeTeams::Testing.enable! RSpec.describe CodeTeams::Testing do - describe '.create_code_team' do - it 'adds the team to CodeTeams.all and CodeTeams.find' do - team = described_class.create_code_team({ name: 'Temp Team', extra_data: { foo: { bar: 1 } } }) + describe ".create_code_team" do + it "adds the team to CodeTeams.all and CodeTeams.find" do + team = described_class.create_code_team({ name: "Temp Team", extra_data: { foo: { bar: 1 } } }) expect(CodeTeams.all).to include(team) - expect(CodeTeams.find('Temp Team')).to eq(team) - expect(team.raw_hash.dig('extra_data', 'foo', 'bar')).to eq(1) + expect(CodeTeams.find("Temp Team")).to eq(team) + expect(team.raw_hash.dig("extra_data", "foo", "bar")).to eq(1) end - it 'does not let a fake team inherit a real same-named team\'s cached plugin data' do + it "does not let a fake team inherit a real same-named team's cached plugin data" do test_plugin_class = Class.new(CodeTeams::Plugin) do def test_plugin - Data.define(:source).new(@team.raw_hash['extra_data']['source']) + Data.define(:source).new(@team.raw_hash["extra_data"]["source"]) end end - stub_const('TestPlugin', test_plugin_class) + stub_const("TestPlugin", test_plugin_class) CodeTeams.bust_caches! - write_team_yml(extra_data: { 'source' => 'real' }) + write_team_yml(extra_data: { "source" => "real" }) # Reading the real team caches its plugin instance under the name 'My Team'. - expect(CodeTeams.find('My Team').test_plugin.source).to eq('real') + expect(CodeTeams.find("My Team").test_plugin.source).to eq("real") - fake = described_class.create_code_team({ name: 'My Team', extra_data: { 'source' => 'fake' } }) + fake = described_class.create_code_team({ name: "My Team", extra_data: { "source" => "fake" } }) - expect(fake.test_plugin.source).to eq('fake') + expect(fake.test_plugin.source).to eq("fake") end end end diff --git a/spec/lib/code_teams/utils_spec.rb b/spec/lib/code_teams/utils_spec.rb index f0fa49b..bf6fd13 100644 --- a/spec/lib/code_teams/utils_spec.rb +++ b/spec/lib/code_teams/utils_spec.rb @@ -1,29 +1,30 @@ +# typed: false # frozen_string_literal: true RSpec.describe CodeTeams::Utils do - describe '.underscore' do + describe ".underscore" do # These cases pin the exact behavior of the acronym-splitting step so that the # linear-time zero-width rewrite stays equivalent to the original # `/([A-Z]+)([A-Z][a-z])/` pattern. { - '' => '', - 'A' => 'a', - 'Ab' => 'ab', - 'AAb' => 'a_ab', - 'AABb' => 'aa_bb', - 'ABCd' => 'ab_cd', - 'HTMLParser' => 'html_parser', - 'ALLCAPS' => 'allcaps', - 'allLower' => 'all_lower', - 'aABc' => 'a_a_bc', - 'ABCdEFg' => 'ab_cd_e_fg', - 'A1b' => 'a1b', - 'ABC1de' => 'abc1de', - 'X9Yz' => 'x9_yz', - 'HTTPResponse2XX' => 'http_response2_xx', - 'Foo::BarBaz' => 'foo/bar_baz', - 'Foo::HTMLParser::XMLNode' => 'foo/html_parser/xml_node', - 'my-Team-Name' => 'my_team_name' + "" => "", + "A" => "a", + "Ab" => "ab", + "AAb" => "a_ab", + "AABb" => "aa_bb", + "ABCd" => "ab_cd", + "HTMLParser" => "html_parser", + "ALLCAPS" => "allcaps", + "allLower" => "all_lower", + "aABc" => "a_a_bc", + "ABCdEFg" => "ab_cd_e_fg", + "A1b" => "a1b", + "ABC1de" => "abc1de", + "X9Yz" => "x9_yz", + "HTTPResponse2XX" => "http_response2_xx", + "Foo::BarBaz" => "foo/bar_baz", + "Foo::HTMLParser::XMLNode" => "foo/html_parser/xml_node", + "my-Team-Name" => "my_team_name", }.each do |input, expected| it "converts #{input.inspect} to #{expected.inspect}" do expect(described_class.underscore(input)).to eq(expected) diff --git a/spec/lib/code_teams_spec.rb b/spec/lib/code_teams_spec.rb index aa2549d..bb2ea96 100644 --- a/spec/lib/code_teams_spec.rb +++ b/spec/lib/code_teams_spec.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true RSpec.describe CodeTeams do @@ -8,21 +9,21 @@ end before do - write_file('config/teams/my_team.yml', team_yml) + write_file("config/teams/my_team.yml", team_yml) described_class.bust_caches! allow(CodeTeams::Plugin).to receive(:registry).and_return({}) end - describe '.all' do - it 'correctly parses the team files' do + describe ".all" do + it "correctly parses the team files" do expect(described_class.all.count).to eq 1 team = described_class.all.first - expect(team.name).to eq 'My Team' - expect(team.raw_hash['name']).to eq 'My Team' - expect(team.config_yml).to eq 'config/teams/my_team.yml' + expect(team.name).to eq "My Team" + expect(team.raw_hash["name"]).to eq "My Team" + expect(team.config_yml).to eq "config/teams/my_team.yml" end - context 'if team YML has syntax errors' do + context "if team YML has syntax errors" do let(:team_yml) do <<~YML.strip name =>>>asdfaf!!@#!@#@!syntax error My Team @@ -30,65 +31,65 @@ YML end - it 'spits out a helpful error message' do + it "spits out a helpful error message" do expect { described_class.all }.to raise_error do |e| expect(e).to be_a CodeTeams::IncorrectPublicApiUsageError - expect(e.message).to eq('The YML in config/teams/my_team.yml has a syntax error!') + expect(e.message).to eq("The YML in config/teams/my_team.yml has a syntax error!") end end end end - describe '.find' do - it 'returns the team when found' do - team = described_class.find('My Team') + describe ".find" do + it "returns the team when found" do + team = described_class.find("My Team") expect(team).to be_a(CodeTeams::Team) - expect(team.name).to eq('My Team') + expect(team.name).to eq("My Team") end - it 'returns nil when the team is not found' do - team = described_class.find('Nonexistent Team') + it "returns nil when the team is not found" do + team = described_class.find("Nonexistent Team") expect(team).to be_nil end end - describe '.find!' do - it 'returns the team when found' do - team = described_class.find!('My Team') + describe ".find!" do + it "returns the team when found" do + team = described_class.find!("My Team") expect(team).to be_a(CodeTeams::Team) - expect(team.name).to eq('My Team') + expect(team.name).to eq("My Team") end - it 'raises TeamNotFoundError when the team is not found' do - expect { described_class.find!('Nonexistent Team') }.to raise_error( + it "raises TeamNotFoundError when the team is not found" do + expect { described_class.find!("Nonexistent Team") }.to raise_error( CodeTeams::TeamNotFoundError, - 'No team found with name: Nonexistent Team' + "No team found with name: Nonexistent Team" ) end end - describe 'validation_errors' do + describe "validation_errors" do subject(:validation_errors) { described_class.validation_errors(described_class.all) } - context 'there is one definition for all teams' do - it 'has no errors' do + context "there is one definition for all teams" do + it "has no errors" do expect(validation_errors).to be_empty end end - context 'there are multiple definitions for the same team' do + context "there are multiple definitions for the same team" do before do - write_file('config/teams/my_other_team.yml', team_yml) + write_file("config/teams/my_other_team.yml", team_yml) end - it 'registers the team file as invalid' do - expect(validation_errors).to contain_exactly('More than 1 definition for My Team found') + it "registers the team file as invalid" do + expect(validation_errors).to contain_exactly("More than 1 definition for My Team found") end end end - describe '==' do - it 'handles nil correctly' do + describe "==" do + it "handles nil correctly" do expect(described_class.all.first == nil).to be false # rubocop:disable Style/NilComparison expect(described_class.all.first.nil?).to be false end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7825990..c120453 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,15 @@ +# typed: false # frozen_string_literal: true -require 'bundler/setup' -require 'pry' -require 'code_teams' +require "bundler/setup" +require "pry" +require "code_teams" -Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f } +Dir[File.expand_path("support/**/*.rb", __dir__)].each { |f| require f } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! @@ -18,7 +19,7 @@ end config.around do |example| - prefix = [File.basename($0), Process.pid].join('-') # rubocop:disable Style/SpecialGlobalVars + prefix = [File.basename($0), Process.pid].join("-") # rubocop:disable Style/SpecialGlobalVars tmpdir = Dir.mktmpdir(prefix) Dir.chdir(tmpdir) do example.run diff --git a/spec/support/io_helpers.rb b/spec/support/io_helpers.rb index f9f5e2c..951ef36 100644 --- a/spec/support/io_helpers.rb +++ b/spec/support/io_helpers.rb @@ -1,14 +1,20 @@ +# typed: false # frozen_string_literal: true module IOHelpers def write_team_yml(extra_data: false) - write_file('config/teams/my_team.yml', YAML.dump({ - name: 'My Team', - extra_data: extra_data - }.transform_keys(&:to_s))) + write_file( + "config/teams/my_team.yml", + YAML.dump( + { + name: "My Team", + extra_data: extra_data, + }.transform_keys(&:to_s) + ) + ) end - def write_file(path, content = '') + def write_file(path, content = "") pathname = Pathname.new(path) FileUtils.mkdir_p(pathname.dirname) pathname.write(content) From e9a389fb2e23eaf4b04f73ce9104acf0f5fc1c6b Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 30 Nov 2026 13:27:18 -0800 Subject: [PATCH 2/2] Enable RSpec/NotToNot and sort cop configurations - Enable RSpec/NotToNot, which rubocop-gusto leaves off by default - No existing spec uses `to_not`, so nothing needed correcting - Sort the cop configurations in .rubocop.yml alphabetically; a comment that introduced a group of cops is repeated on each cop in the group --- .rubocop.yml | 95 +++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index efa8050..236cb0a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,7 +19,6 @@ inherit_gem: # where the inspected file is and continue its way up to the root directory. # # See https://docs.rubocop.org/rubocop/configuration - plugins: - rubocop-gusto @@ -35,115 +34,121 @@ Gemspec/DevelopmentDependencies: Enabled: true EnforcedStyle: Gemfile -Metrics/ParameterLists: +Gemspec/RequireMFA: Enabled: false -# This cop is annoying with typed configuration -Style/TrivialAccessors: +# This leads to code that is not very readable at times (very long lines) +Layout/ArgumentAlignment: Enabled: false -# This rubocop is annoying when we use interfaces a lot -Lint/UnusedMethodArgument: +# This leads to code that is not very readable at times (very long lines) +Layout/FirstArgumentIndentation: Enabled: false -Gemspec/RequireMFA: +# Leaving length metrics to human judgment for now +Layout/LineLength: Enabled: false -Lint/DuplicateBranch: +# This leads to code that is not very readable at times (very long lines) +Layout/MultilineMethodCallIndentation: Enabled: false -# If is sometimes easier to think about than unless sometimes -Style/NegatedIf: +Lint/DuplicateBranch: Enabled: false -# It's nice to be able to read the condition first before reading the code within the condition -Style/GuardClause: +# This rubocop is annoying when we use interfaces a lot +Lint/UnusedMethodArgument: Enabled: false -# # Leaving length metrics to human judgment for now -# -Metrics/ModuleLength: +Metrics/AbcSize: Enabled: false -Layout/LineLength: +# Leaving length metrics to human judgment for now +Metrics/BlockLength: Enabled: false -Metrics/BlockLength: +# Leaving length metrics to human judgment for now +Metrics/ClassLength: Enabled: false -Metrics/MethodLength: +# This doesn't feel useful +Metrics/CyclomaticComplexity: Enabled: false -Metrics/AbcSize: +# Leaving length metrics to human judgment for now +Metrics/MethodLength: Enabled: false -Metrics/ClassLength: +# Leaving length metrics to human judgment for now +Metrics/ModuleLength: Enabled: false -# This doesn't feel useful -Metrics/CyclomaticComplexity: +Metrics/ParameterLists: Enabled: false # This doesn't feel useful Metrics/PerceivedComplexity: Enabled: false -# It's nice to be able to read the condition first before reading the code within the condition -Style/IfUnlessModifier: +# Sometimes we like methods like `get_packages` +Naming/AccessorMethodName: Enabled: false -# This leads to code that is not very readable at times (very long lines) -Style/ConditionalAssignment: +RSpec/ContextWording: Enabled: false -# For now, we prefer to lean on clean method signatures as documentation. We may change this later. -Style/Documentation: +RSpec/ExampleLength: Enabled: false -# Sometimes we leave comments in empty else statements intentionally -Style/EmptyElse: +RSpec/MultipleExpectations: Enabled: false -# Sometimes we want to more explicitly list out a condition -Style/RedundantCondition: - Enabled: false +RSpec/NotToNot: + Enabled: true -# This leads to code that is not very readable at times (very long lines) -Layout/MultilineMethodCallIndentation: +Style/AccessorGrouping: Enabled: false # Blocks across lines are okay sometimes Style/BlockDelimiters: Enabled: false -# Sometimes we like methods like `get_packages` -Naming/AccessorMethodName: +# This leads to code that is not very readable at times (very long lines) +Style/ConditionalAssignment: Enabled: false -# This leads to code that is not very readable at times (very long lines) -Layout/FirstArgumentIndentation: +# For now, we prefer to lean on clean method signatures as documentation. We may change this later. +Style/Documentation: Enabled: false -# This leads to code that is not very readable at times (very long lines) -Layout/ArgumentAlignment: +# Sometimes we leave comments in empty else statements intentionally +Style/EmptyElse: Enabled: false -Style/AccessorGrouping: +# It's nice to be able to read the condition first before reading the code within the condition +Style/GuardClause: Enabled: false Style/HashSyntax: Enabled: false -RSpec/MultipleExpectations: +# It's nice to be able to read the condition first before reading the code within the condition +Style/IfUnlessModifier: Enabled: false -RSpec/ExampleLength: +# If is sometimes easier to think about than unless sometimes +Style/NegatedIf: Enabled: false -RSpec/ContextWording: +# Sometimes we want to more explicitly list out a condition +Style/RedundantCondition: Enabled: false Style/StringLiterals: Enabled: true EnforcedStyle: double_quotes + +# This cop is annoying with typed configuration +Style/TrivialAccessors: + Enabled: false