Skip to content

Commit

Permalink
Add bin/packs lint_package_yml_files and update bin/lint_deprecated_r…
Browse files Browse the repository at this point in the history
…eferences_yml_files (#56)
  • Loading branch information
Alex Evanczuk authored Nov 18, 2022
1 parent b46acd4 commit 37455fd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
use_packwerk (0.66.0)
use_packwerk (0.67.0)
code_ownership
colorize
packwerk (>= 2.2.1)
Expand Down Expand Up @@ -124,7 +124,7 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-packs (0.0.22)
rubocop-packs (0.0.24)
activesupport
parse_packwerk
rubocop
Expand Down
16 changes: 15 additions & 1 deletion lib/use_packwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def self.get_offenses_for_files_by_package(files)
end

sig { void }
def self.lint_deprecated_references!
def self.lint_deprecated_references_yml_files!
contents_before = Private.get_deprecated_references_contents
UsePackwerk.execute(['update-deprecations'])
contents_after = Private.get_deprecated_references_contents
Expand Down Expand Up @@ -281,4 +281,18 @@ def self.lint_deprecated_references!
exit 1
end
end

sig { params(packs: T::Array[ParsePackwerk::Package]).void }
def self.lint_package_yml_files!(packs)
packs.each do |p|
new_package = ParsePackwerk::Package.new(
name: p.name,
enforce_privacy: p.enforce_privacy,
enforce_dependencies: p.enforce_dependencies,
dependencies: p.dependencies.uniq.sort,
metadata: p.metadata
)
ParsePackwerk.write_package_yml!(new_package)
end
end
end
13 changes: 10 additions & 3 deletions lib/use_packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ def move_to_parent(parent_name, pack_name)
)
end

desc 'lint_deprecated_references', 'Ensures `deprecated_references.yml` files are up to date'
desc 'lint_deprecated_references_yml_files', 'Ensures `deprecated_references.yml` files are up to date'
sig { void }
def lint_deprecated_references
UsePackwerk.lint_deprecated_references!
def lint_deprecated_references_yml_files
UsePackwerk.lint_deprecated_references_yml_files!
end

desc 'lint_package_yml_files [ packs/my_pack packs/my_other_pack ]', 'Lint `package.yml` files'
sig { params(pack_names: String).void }
def lint_package_yml_files(*pack_names)
packages = pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
UsePackwerk.lint_package_yml_files!(packages)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ class LintPackageYml
sig { override.params(prompt: TTY::Prompt).void }
def perform!(prompt)
packs = PackSelector.single_or_all_pack_multi_select(prompt, question_text: 'Please select the packs you want to lint package.yml files for')
packs.each do |p|
new_package = ParsePackwerk::Package.new(
name: p.name,
enforce_privacy: p.enforce_privacy,
enforce_dependencies: p.enforce_dependencies,
dependencies: p.dependencies.uniq.sort,
metadata: p.metadata
)
ParsePackwerk.write_package_yml!(new_package)
end
UsePackwerk.lint_package_yml_files!(packs)
end

sig { override.returns(String) }
Expand Down
10 changes: 5 additions & 5 deletions spec/use_packwerk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1292,15 +1292,15 @@ def expect_files_to_not_exist(files)
end
end

describe 'lint_deprecated_references' do
let(:args) { ['lint_deprecated_references'] }
describe 'lint_deprecated_references_yml_files' do
let(:args) { ['lint_deprecated_references_yml_files'] }

context 'no diff after running update-deprecations' do
it 'exits successfully' do
expect_any_instance_of(Packwerk::Cli).to receive(:execute_command).with(['update-deprecations'])
expect(UsePackwerk).to receive(:exit).with(0)
expect(UsePackwerk).to_not receive(:puts)
UsePackwerk.lint_deprecated_references!
UsePackwerk.lint_deprecated_references_yml_files!
end
end

Expand Down Expand Up @@ -1356,7 +1356,7 @@ def expect_files_to_not_exist(files)
EXPECTED

expect(UsePackwerk).to receive(:exit).with(1)
UsePackwerk.lint_deprecated_references!
UsePackwerk.lint_deprecated_references_yml_files!
end
end

Expand Down Expand Up @@ -1419,7 +1419,7 @@ def expect_files_to_not_exist(files)
EXPECTED

expect(UsePackwerk).to receive(:exit).with(1)
UsePackwerk.lint_deprecated_references!
UsePackwerk.lint_deprecated_references_yml_files!
expect(callback_invocation).to include('All `deprecated_references.yml` files must be up-to-date')
end
end
Expand Down
2 changes: 1 addition & 1 deletion use_packwerk.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'use_packwerk'
spec.version = '0.66.0'
spec.version = '0.67.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']

Expand Down

0 comments on commit 37455fd

Please sign in to comment.