Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
strategy:
matrix:
ruby:
- 3.1
- 3.2
- 3.3
- 3.4
Expand All @@ -37,7 +36,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 3.3
ruby-version: 3.4
- name: Run static type checks
run: bundle exec srb tc
notify_on_failure:
Expand Down
112 changes: 67 additions & 45 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
inherit_gem:
rubocop-gusto:
- config/default.yml

plugins:
- rubocop-gusto
- rubocop-rspec
- rubocop-performance
- rubocop-rake

# 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
Expand All @@ -12,53 +22,49 @@ AllCops:
NewCops: enable
Exclude:
- vendor/bundle/**/**
TargetRubyVersion: 2.6

Metrics/ParameterLists:
Enabled: false
TargetRubyVersion: 3.2

# This cop is annoying with typed configuration
Style/TrivialAccessors:
Gemspec/RequireMFA:
Enabled: false

# This rubocop is annoying when we use interfaces a lot
Lint/UnusedMethodArgument:
# Allow extend self pattern
Style/ModuleFunction:
Enabled: false

Gemspec/RequireMFA:
# Allow expect_any_instance_of in tests for specific testing patterns
RSpec/AnyInstance:
Enabled: false

Lint/DuplicateBranch:
# Allow after(:all) for necessary cleanup
RSpec/BeforeAfterAll:
Enabled: false

# If is sometimes easier to think about than unless sometimes
Style/NegatedIf:
# This leads to code that is not very readable at times (very long lines)
Layout/ArgumentAlignment:
Enabled: false

# Disabling for now until it's clearer why we want this
Style/FrozenStringLiteralComment:
# This leads to code that is not very readable at times (very long lines)
Layout/FirstArgumentIndentation:
Enabled: false

# It's nice to be able to read the condition first before reading the code within the condition
Style/GuardClause:
Layout/LineLength:
Enabled: false

#
# Leaving length metrics to human judgment for now
#
Metrics/ModuleLength:
# This leads to code that is not very readable at times (very long lines)
Layout/MultilineMethodCallIndentation:
Enabled: false

Layout/LineLength:
Lint/DuplicateBranch:
Enabled: false

Metrics/BlockLength:
# This rubocop is annoying when we use interfaces a lot
Lint/UnusedMethodArgument:
Enabled: false

Metrics/MethodLength:
Metrics/AbcSize:
Enabled: false

Metrics/AbcSize:
Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Expand All @@ -68,12 +74,31 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Enabled: false

Metrics/MethodLength:
Enabled: false

#
# Leaving length metrics to human judgment for now
#
Metrics/ModuleLength:
Enabled: false

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

Style/AccessorGrouping:
Enabled: false

# Blocks across lines are okay sometimes
Style/BlockDelimiters:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Expand All @@ -88,36 +113,33 @@ Style/Documentation:
Style/EmptyElse:
Enabled: false

# Sometimes we want to more explicitly list out a condition
Style/RedundantCondition:
# Disabling for now until it's clearer why we want this
Style/FrozenStringLiteralComment:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/MultilineMethodCallIndentation:
# It's nice to be able to read the condition first before reading the code within the condition
Style/GuardClause:
Enabled: false

# Blocks across lines are okay sometimes
Style/BlockDelimiters:
Style/HashSyntax:
Enabled: false

# Sometimes we like methods like `get_packages`
Naming/AccessorMethodName:
# It's nice to be able to read the condition first before reading the code within the condition
Style/IfUnlessModifier:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/FirstArgumentIndentation:
# If is sometimes easier to think about than unless sometimes
Style/NegatedIf:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/ArgumentAlignment:
# Sometimes we want to more explicitly list out a condition
Style/RedundantCondition:
Enabled: false

Style/AccessorGrouping:
Enabled: false
Style/StringLiterals:
EnforcedStyle: single_quotes
Enabled: true

Style/HashSyntax:
# This cop is annoying with typed configuration
Style/TrivialAccessors:
Enabled: false

Gemspec/DevelopmentDependencies:
Enabled: true
EnforcedStyle: gemspec
Empty file added .rubocop_todo.yml
Empty file.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
source 'https://rubygems.org'

gemspec

gem 'debug'
gem 'packwerk'
gem 'railties'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-gusto', '~> 10.0'
gem 'sorbet'
gem 'tapioca'
16 changes: 16 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rubocop', 'rubocop')
16 changes: 16 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('tapioca', 'tapioca')
10 changes: 1 addition & 9 deletions code_ownership.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'code_teams', '~> 1.0'
spec.add_dependency 'packs-specification'
spec.add_dependency 'sorbet-runtime', '>= 0.5.11249'

spec.add_development_dependency 'debug'
spec.add_development_dependency 'packwerk'
spec.add_development_dependency 'railties'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'sorbet'
spec.add_development_dependency 'tapioca'
spec.add_dependency 'zeitwerk'
end
24 changes: 11 additions & 13 deletions lib/code_ownership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

# typed: strict

require 'set'
require 'code_teams'
require 'sorbet-runtime'
require 'json'
require 'packs-specification'
require 'code_ownership/mapper'
require 'code_ownership/validator'
require 'code_ownership/private'
require 'code_ownership/cli'
require 'code_ownership/configuration'
require 'zeitwerk'

loader = Zeitwerk::Loader.for_gem
loader.setup

if defined?(Packwerk)
require 'code_ownership/private/permit_pack_owner_top_level_key'
require 'code_ownership/private/pack_ownership_validator'
end

module CodeOwnership
module_function
extend self

extend T::Sig
extend T::Helpers
Expand Down Expand Up @@ -97,10 +95,10 @@ def validate!(
Private.load_configuration!

tracked_file_subset = if files
files.select { |f| Private.file_tracked?(f) }
else
Private.tracked_files
end
files.select { |f| Private.file_tracked?(f) }
else
Private.tracked_files
end

Private.validate!(files: tracked_file_subset, autocorrect: autocorrect, stage_changes: stage_changes)
end
Expand Down Expand Up @@ -162,7 +160,7 @@ def backtrace_with_ownership(backtrace)

[
CodeOwnership.for_file(file),
file
file,
]
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/code_ownership/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def self.validate!(argv)
parser.parse!(args)

files = if options[:diff]
ENV.fetch('CODEOWNERS_GIT_STAGED_FILES') { `git diff --staged --name-only` }.split("\n").select do |file|
File.exist?(file)
end
else
nil
end
ENV.fetch('CODEOWNERS_GIT_STAGED_FILES') { %x(git diff --staged --name-only) }.split("\n").select do |file|
File.exist?(file)
end
else
nil
end

CodeOwnership.validate!(
files: files,
Expand Down Expand Up @@ -107,7 +107,7 @@ def self.for_file(argv)
if options[:json]
json = {
team_name: team_name,
team_yml: team_yml
team_yml: team_yml,
}

puts json.to_json
Expand All @@ -121,7 +121,7 @@ def self.for_file(argv)

def self.for_team(argv)
parser = OptionParser.new do |opts|
opts.banner = 'Usage: bin/codeownership for_team \'Team Name\''
opts.banner = "Usage: bin/codeownership for_team 'Team Name'"

opts.on('--help', 'Shows this prompt') do
puts opts
Expand Down
3 changes: 2 additions & 1 deletion lib/code_ownership/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module CodeOwnership
class Configuration < T::Struct
extend T::Sig

DEFAULT_JS_PACKAGE_PATHS = T.let(['**/'], T::Array[String])

const :owned_globs, T::Array[String]
Expand Down Expand Up @@ -31,7 +32,7 @@ def self.fetch
skip_codeowners_validation: config_hash.fetch('skip_codeowners_validation', false),
raw_hash: config_hash,
require_github_teams: config_hash.fetch('require_github_teams', false),
codeowners_path: config_hash.fetch('codeowners_path', '.github'),
codeowners_path: config_hash.fetch('codeowners_path', '.github')
)
end

Expand Down
Loading
Loading