From 2c214ea4d22d2312f7be0f4392aa0a014b536ad3 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Mon, 12 Dec 2022 17:05:14 -0500 Subject: [PATCH 1/4] Rename deprecated_references.yml throughout code --- README.md | 10 +-- lib/parse_packwerk.rb | 2 +- lib/parse_packwerk/constants.rb | 2 +- lib/parse_packwerk/deprecated_references.rb | 20 +++--- lib/parse_packwerk/package.rb | 2 +- spec/parse_packwerk_spec.rb | 68 ++++++++++----------- spec/support/have_matching_package.rb | 16 ++--- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 8ff368d..67c938c 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,15 @@ packages = ParsePackwerk.all # Get a single package with a given ame package = ParsePackwerk.find('packs/my_pack') -# Get a structured `deprecated_references.yml` object a single package -deprecated_references = ParsePackwerk::DeprecatedReferences.for(package) +# Get a structured `package_todo.yml` object a single package +package_todo = ParsePackwerk::PackageTodo.for(package) # Count violations of a particular type for a package -deprecated_references.violations.count(&:privacy?) -deprecated_references.violations.count(&:dependency?) +package_todo.violations.count(&:privacy?) +package_todo.violations.count(&:dependency?) # Get the number of files a particular constant is violated in -deprecated_references.violations.select { |v| v.class_name == 'SomeConstant' }.sum { |v| v.files.count } +package_todo.violations.select { |v| v.class_name == 'SomeConstant' }.sum { |v| v.files.count } ``` # Why does this gem exist? diff --git a/lib/parse_packwerk.rb b/lib/parse_packwerk.rb index 4ad7cfc..c72005c 100644 --- a/lib/parse_packwerk.rb +++ b/lib/parse_packwerk.rb @@ -5,7 +5,7 @@ require 'pathname' require 'parse_packwerk/constants' require 'parse_packwerk/violation' -require 'parse_packwerk/deprecated_references' +require 'parse_packwerk/package_todo' require 'parse_packwerk/package' require 'parse_packwerk/configuration' require 'parse_packwerk/package_set' diff --git a/lib/parse_packwerk/constants.rb b/lib/parse_packwerk/constants.rb index b801677..d0c6499 100644 --- a/lib/parse_packwerk/constants.rb +++ b/lib/parse_packwerk/constants.rb @@ -4,7 +4,7 @@ module ParsePackwerk ROOT_PACKAGE_NAME = T.let('.'.freeze, String) PACKAGE_YML_NAME = T.let('package.yml'.freeze, String) PACKWERK_YML_NAME = T.let('packwerk.yml'.freeze, String) - DEPRECATED_REFERENCES_YML_NAME = T.let('deprecated_references.yml'.freeze, String) + PACKAGE_TODO_YML_NAME = T.let('package_todo.yml'.freeze, String) ENFORCE_DEPENDENCIES = T.let('enforce_dependencies'.freeze, String) ENFORCE_PRIVACY = T.let('enforce_privacy'.freeze, String) PUBLIC_PATH = T.let('public_path'.freeze, String) diff --git a/lib/parse_packwerk/deprecated_references.rb b/lib/parse_packwerk/deprecated_references.rb index b563f30..b322269 100644 --- a/lib/parse_packwerk/deprecated_references.rb +++ b/lib/parse_packwerk/deprecated_references.rb @@ -1,19 +1,19 @@ # typed: strict module ParsePackwerk - class DeprecatedReferences < T::Struct + class PackageTodo < T::Struct extend T::Sig const :pathname, Pathname const :violations, T::Array[Violation] - sig { params(package: Package).returns(DeprecatedReferences) } + sig { params(package: Package).returns(PackageTodo) } def self.for(package) - deprecated_references_yml_pathname = package.directory.join(DEPRECATED_REFERENCES_YML_NAME) - DeprecatedReferences.from(deprecated_references_yml_pathname) + package_todo_yml_pathname = package.directory.join(PACKAGE_TODO_YML_NAME) + PackageTodo.from(package_todo_yml_pathname) end - sig { params(pathname: Pathname).returns(DeprecatedReferences) } + sig { params(pathname: Pathname).returns(PackageTodo) } def self.from(pathname) if !pathname.exist? new( @@ -21,13 +21,13 @@ def self.from(pathname) violations: [] ) else - deprecated_references_loaded_yml = YAML.load_file(pathname) + package_todo_loaded_yml = YAML.load_file(pathname) all_violations = [] - deprecated_references_loaded_yml&.each_key do |to_package_name| - deprecated_references_per_package = deprecated_references_loaded_yml[to_package_name] - deprecated_references_per_package.each_key do |class_name| - symbol_usage = deprecated_references_per_package[class_name] + package_todo_loaded_yml&.each_key do |to_package_name| + package_todo_per_package = package_todo_loaded_yml[to_package_name] + package_todo_per_package.each_key do |class_name| + symbol_usage = package_todo_per_package[class_name] files = symbol_usage['files'] violations = symbol_usage['violations'] if violations.include? 'dependency' diff --git a/lib/parse_packwerk/package.rb b/lib/parse_packwerk/package.rb index 044267e..2247f93 100644 --- a/lib/parse_packwerk/package.rb +++ b/lib/parse_packwerk/package.rb @@ -53,7 +53,7 @@ def enforces_privacy? sig { returns(T::Array[Violation]) } def violations - DeprecatedReferences.for(self).violations + PackageTodo.for(self).violations end end end diff --git a/spec/parse_packwerk_spec.rb b/spec/parse_packwerk_spec.rb index baf7cea..5dde93c 100644 --- a/spec/parse_packwerk_spec.rb +++ b/spec/parse_packwerk_spec.rb @@ -63,8 +63,8 @@ def hashify_violation(v) ) end - let(:expected_deprecated_references) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('deprecated_references.yml')) + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end it 'correctly finds the package YML' do @@ -75,7 +75,7 @@ def hashify_violation(v) expect(expected_package.directory).to eq Pathname.new('.') end - it { is_expected.to have_matching_package expected_package, expected_deprecated_references } + it { is_expected.to have_matching_package expected_package, expected_package_todo } end context 'in app that enforces privacy and dependencies' do @@ -119,11 +119,11 @@ def hashify_violation(v) ) end - let(:expected_root_deprecated_references) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('deprecated_references.yml')) + let(:expected_root_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end - it { is_expected.to have_matching_package expected_root_package, expected_root_deprecated_references } + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } let(:expected_domain_package) do ParsePackwerk::Package.new( @@ -135,8 +135,8 @@ def hashify_violation(v) ) end - let(:expected_domain_package_deprecated_references) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('packs/package_1/deprecated_references.yml')) + let(:expected_domain_package_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new('packs/package_1/package_todo.yml')) end it 'correctly finds the package YML' do @@ -147,7 +147,7 @@ def hashify_violation(v) expect(expected_domain_package.directory).to eq Pathname.new('packs/package_1') end - it { is_expected.to have_matching_package expected_domain_package, expected_domain_package_deprecated_references } + it { is_expected.to have_matching_package expected_domain_package, expected_domain_package_package_todo } end context 'in app that has public_path' do @@ -194,7 +194,7 @@ def hashify_violation(v) end let(:expected_root_deprecated_refereces) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('deprecated_references.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end it { is_expected.to have_matching_package expected_root_package, expected_root_deprecated_refereces } @@ -210,11 +210,11 @@ def hashify_violation(v) ) end - let(:expected_deprecated_references) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('packs/package_1/deprecated_references.yml')) + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new('packs/package_1/package_todo.yml')) end - it { is_expected.to have_matching_package expected_domain_package, expected_deprecated_references } + it { is_expected.to have_matching_package expected_domain_package, expected_package_todo } end context 'in app that has metadata' do @@ -264,7 +264,7 @@ def hashify_violation(v) end let(:expected_root_deprecated_refereces) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('deprecated_references.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end it { is_expected.to have_matching_package expected_root_package, expected_root_deprecated_refereces } @@ -284,16 +284,16 @@ def hashify_violation(v) ) end - let(:expected_deprecated_references) do - ParsePackwerk::DeprecatedReferences.from(Pathname.new('packs/package_1/deprecated_references.yml')) + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new('packs/package_1/package_todo.yml')) end - it { is_expected.to have_matching_package expected_domain_package, expected_deprecated_references } + it { is_expected.to have_matching_package expected_domain_package, expected_package_todo } end context 'in app that has violations' do before do - write_file('packs/package_2/deprecated_references.yml', <<~CONTENTS) + write_file('packs/package_2/package_todo.yml', <<~CONTENTS) # This file contains a list of dependencies that are not part of the long term plan for .. # We should generally work to reduce this list, but not at the expense of actually getting work done. # @@ -325,7 +325,7 @@ def hashify_violation(v) enforce_privacy: true CONTENTS - write_file('packs/package_1/deprecated_references.yml', <<~CONTENTS) + write_file('packs/package_1/package_todo.yml', <<~CONTENTS) # This file contains a list of dependencies that are not part of the long term plan for .. # We should generally work to reduce this list, but not at the expense of actually getting work done. # @@ -348,7 +348,7 @@ def hashify_violation(v) - packs/package_2 CONTENTS - write_file('deprecated_references.yml', <<~CONTENTS) + write_file('package_todo.yml', <<~CONTENTS) # This file contains a list of dependencies that are not part of the long term plan for .. # We should generally work to reduce this list, but not at the expense of actually getting work done. # @@ -407,9 +407,9 @@ def hashify_violation(v) ) end - let(:expected_deprecated_references) do - ParsePackwerk::DeprecatedReferences.new( - pathname: Pathname.new('deprecated_references.yml'), + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.new( + pathname: Pathname.new('package_todo.yml'), violations: [ ParsePackwerk::Violation.new( type: 'dependency', @@ -427,7 +427,7 @@ def hashify_violation(v) ) end - it { is_expected.to have_matching_package expected_root_package, expected_deprecated_references } + it { is_expected.to have_matching_package expected_root_package, expected_package_todo } let(:expected_domain_package_1) do ParsePackwerk::Package.new( @@ -439,9 +439,9 @@ def hashify_violation(v) ) end - let(:expected_deprecated_references_1) do - ParsePackwerk::DeprecatedReferences.new( - pathname: Pathname.new('packs/package_1/deprecated_references.yml'), + let(:expected_package_todo_1) do + ParsePackwerk::PackageTodo.new( + pathname: Pathname.new('packs/package_1/package_todo.yml'), violations: [ ParsePackwerk::Violation.new( type: 'privacy', @@ -453,7 +453,7 @@ def hashify_violation(v) ) end - it { is_expected.to have_matching_package expected_domain_package_1, expected_deprecated_references_1 } + it { is_expected.to have_matching_package expected_domain_package_1, expected_package_todo_1 } let(:expected_domain_package_2) do ParsePackwerk::Package.new( @@ -465,9 +465,9 @@ def hashify_violation(v) ) end - let(:expected_domain_package_deprecated_references_2) do - ParsePackwerk::DeprecatedReferences.new( - pathname: Pathname.new('packs/package_2/deprecated_references.yml'), + let(:expected_domain_package_package_todo_2) do + ParsePackwerk::PackageTodo.new( + pathname: Pathname.new('packs/package_2/package_todo.yml'), violations: [ ParsePackwerk::Violation.new( type: 'dependency', @@ -491,7 +491,7 @@ def hashify_violation(v) ) end - it { is_expected.to have_matching_package expected_domain_package_2, expected_domain_package_deprecated_references_2 } + it { is_expected.to have_matching_package expected_domain_package_2, expected_domain_package_package_todo_2 } end context 'in an app that has specified package paths' do @@ -636,7 +636,7 @@ def hashify_violation(v) enforce_privacy: true CONTENTS - write_file('packs/my_pack/deprecated_references.yml', <<~CONTENTS) + write_file('packs/my_pack/package_todo.yml', <<~CONTENTS) # This file contains a list of dependencies that are not part of the long term plan for .. # We should generally work to reduce this list, but not at the expense of actually getting work done. # @@ -881,7 +881,7 @@ def hashify_violation(v) describe 'ParsePackwerk.write_package_yml' do let(:package_dir) { Pathname.new('packs/example_pack') } let(:package_yml) { package_dir.join('package.yml') } - let(:deprecated_references_yml) { package_dir.join('deprecated_references.yml') } + let(:package_todo_yml) { package_dir.join('package_todo.yml') } def build_pack(public_path: 'app/public', dependencies: [], metadata: {}) ParsePackwerk::Package.new( diff --git a/spec/support/have_matching_package.rb b/spec/support/have_matching_package.rb index 02e8585..e8ef466 100644 --- a/spec/support/have_matching_package.rb +++ b/spec/support/have_matching_package.rb @@ -1,11 +1,11 @@ -RSpec::Matchers.define(:have_matching_package) do |expected_package, expected_deprecated_references| +RSpec::Matchers.define(:have_matching_package) do |expected_package, expected_package_todo| match do |actual_packages| @actual_packages = actual_packages @expected_package = expected_package @actual_package = actual_packages.find{|actual_package| actual_package.name == expected_package.name} - @actual_deprecated_references = @actual_package && ParsePackwerk::DeprecatedReferences.for(@actual_package) - @hashified_expected = deep_hashify_package(expected_package, expected_deprecated_references) - @hashified_actual = deep_hashify_package(@actual_package, @actual_deprecated_references) + @actual_package_todo = @actual_package && ParsePackwerk::PackageTodo.for(@actual_package) + @hashified_expected = deep_hashify_package(expected_package, expected_package_todo) + @hashified_actual = deep_hashify_package(@actual_package, @actual_package_todo) !@actual_package.nil? && @hashified_expected == @hashified_actual end @@ -13,16 +13,16 @@ "to have a package named #{expected_package.package_name.inspect} with identical attributes" end - def deep_hashify_package(package, deprecated_references) + def deep_hashify_package(package, package_todo) { name: package.name, enforce_dependencies: package.enforce_dependencies, enforce_privacy: package.enforce_privacy, metadata: package.metadata, dependencies: package.dependencies.sort, - deprecated_references: deprecated_references.nil? ? {} : { - pathname: deprecated_references.pathname.to_s, - violations: hashify_violations(deprecated_references.violations) + package_todo: package_todo.nil? ? {} : { + pathname: package_todo.pathname.to_s, + violations: hashify_violations(package_todo.violations) } } end From 37a7f0877ede73c886c1d50f47e9142e02074cb8 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Mon, 12 Dec 2022 17:05:23 -0500 Subject: [PATCH 2/4] Rename file --- lib/parse_packwerk/{deprecated_references.rb => package_todo.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/parse_packwerk/{deprecated_references.rb => package_todo.rb} (100%) diff --git a/lib/parse_packwerk/deprecated_references.rb b/lib/parse_packwerk/package_todo.rb similarity index 100% rename from lib/parse_packwerk/deprecated_references.rb rename to lib/parse_packwerk/package_todo.rb From da581bdd3a3a6a9a82ebed9107945730fa71b759 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Mon, 12 Dec 2022 17:05:44 -0500 Subject: [PATCH 3/4] fix typo --- spec/parse_packwerk_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/parse_packwerk_spec.rb b/spec/parse_packwerk_spec.rb index 5dde93c..c42c977 100644 --- a/spec/parse_packwerk_spec.rb +++ b/spec/parse_packwerk_spec.rb @@ -193,11 +193,11 @@ def hashify_violation(v) ) end - let(:expected_root_deprecated_refereces) do + let(:expected_root_package_todo) do ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end - it { is_expected.to have_matching_package expected_root_package, expected_root_deprecated_refereces } + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } let(:expected_domain_package) do ParsePackwerk::Package.new( @@ -263,11 +263,11 @@ def hashify_violation(v) ) end - let(:expected_root_deprecated_refereces) do + let(:expected_root_package_todo) do ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) end - it { is_expected.to have_matching_package expected_root_package, expected_root_deprecated_refereces } + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } let(:expected_domain_package) do ParsePackwerk::Package.new( From c4c88c8e56af98e28b67606dcce80d359910c580 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Mon, 12 Dec 2022 17:06:09 -0500 Subject: [PATCH 4/4] Bump version --- Gemfile.lock | 2 +- parse_packwerk.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index acd43c3..1474f4f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parse_packwerk (0.14.0) + parse_packwerk (0.15.0) sorbet-runtime GEM diff --git a/parse_packwerk.gemspec b/parse_packwerk.gemspec index 1db4d90..701050a 100644 --- a/parse_packwerk.gemspec +++ b/parse_packwerk.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "parse_packwerk" - spec.version = '0.14.0' + spec.version = '0.15.0' spec.authors = ['Gusto Engineers'] spec.email = ['dev@gusto.com'] spec.summary = 'A low-dependency gem for parsing and writing packwerk YML files'