diff --git a/.rubocop.yml b/.rubocop.yml index 30ac7aa..fee2f1e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,17 @@ +inherit_from: .rubocop_todo.yml + +inherit_mode: + merge: + - Exclude + - Include + +inherit_gem: + rubocop-gusto: + - config/default.yml + +plugins: + - rubocop-gusto + # 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,66 +24,85 @@ # See https://docs.rubocop.org/rubocop/configuration AllCops: NewCops: enable + SuggestExtensions: false Exclude: + - bin/**/* - vendor/bundle/**/** TargetRubyVersion: 3.3 -Metrics/ParameterLists: +Gemspec/DevelopmentDependencies: + Enabled: true + EnforcedStyle: gemspec + +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 + +# This leads to code that is not very readable at times (very long lines) +Layout/MultilineMethodCallIndentation: Enabled: false Lint/DuplicateBranch: Enabled: false -# If is sometimes easier to think about than unless sometimes -Style/NegatedIf: +# This rubocop is annoying when we use interfaces a lot +Lint/UnusedMethodArgument: Enabled: false -# It's nice to be able to read the condition first before reading the code within the condition -Style/GuardClause: +# Leaving length metrics to human judgment for now +Metrics/AbcSize: Enabled: false -# # Leaving length metrics to human judgment for now -# -Metrics/ModuleLength: +Metrics/BlockLength: Enabled: false -Layout/LineLength: +# Leaving length metrics to human judgment for now +Metrics/ClassLength: Enabled: false -Metrics/BlockLength: +# This doesn't feel useful +Metrics/CyclomaticComplexity: Enabled: false +# Leaving length metrics to human judgment for now Metrics/MethodLength: Enabled: false -Metrics/AbcSize: +# Leaving length metrics to human judgment for now +Metrics/ModuleLength: Enabled: false -Metrics/ClassLength: +Metrics/ParameterLists: Enabled: false # This doesn't feel useful -Metrics/CyclomaticComplexity: +Metrics/PerceivedComplexity: Enabled: false -# This doesn't feel useful -Metrics/PerceivedComplexity: +# Sometimes we like methods like `get_packages` +Naming/AccessorMethodName: Enabled: false -# It's nice to be able to read the condition first before reading the code within the condition -Style/IfUnlessModifier: +RSpec/NotToNot: + Enabled: true + +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) @@ -84,36 +117,29 @@ Style/Documentation: Style/EmptyElse: Enabled: false -# Sometimes we want to more explicitly list out a condition -Style/RedundantCondition: - 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: + Enabled: true + EnforcedStyle: double_quotes -Style/HashSyntax: +# This cop is annoying with typed configuration +Style/TrivialAccessors: Enabled: false - -Gemspec/DevelopmentDependencies: - Enabled: true - EnforcedStyle: gemspec diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..40e5105 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,65 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 10000` +# on 2026-11-30 21:04:54 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: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: PerExampleGroup, Cascade, LocalContextIncludes. +Gusto/UnreferencedLet: + Exclude: + - 'spec/parse_packwerk_spec.rb' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'lib/parse_packwerk.rb' + +# Offense count: 35 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/parse_packwerk_spec.rb' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +Sorbet/BlockMethodDefinition: + Exclude: + - 'spec/parse_packwerk_spec.rb' + - 'spec/support/have_matching_package.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AutocorrectToRBS. +Sorbet/ForbidTUnsafe: + Exclude: + - 'lib/parse_packwerk.rb' + - 'lib/parse_packwerk/package_set.rb' + +# Offense count: 16 +# This cop supports unsafe autocorrection (--autocorrect-all). +Sorbet/RedundantTLetForLiteral: + Exclude: + - 'lib/parse_packwerk/constants.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SuggestedStrictness. +Sorbet/StrictSigil: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/support/have_matching_package.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, Recursive. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/parse_packwerk/constants.rb' diff --git a/Gemfile b/Gemfile index 0961f6e..b60c38e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in modularization_tools.gemspec gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 578e601..1388cf4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,8 @@ GEM awesome_print (1.9.2) benchmark (0.5.0) bigdecimal (4.1.3) + code_teams (1.3.1) + sorbet-runtime coderay (1.1.3) diff-lcs (1.6.2) erubi (1.13.1) @@ -74,10 +76,36 @@ 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) + rubocop-rspec (3.11.0) + lint_roller (~> 1.1) + rubocop (~> 1.92) + 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 +153,7 @@ DEPENDENCIES rake rspec (~> 3.0) rubocop + rubocop-gusto sorbet tapioca diff --git a/Rakefile b/Rakefile index 088722c..ef026d8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ # 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/lib/parse_packwerk.rb b/lib/parse_packwerk.rb index 47e759c..2565361 100644 --- a/lib/parse_packwerk.rb +++ b/lib/parse_packwerk.rb @@ -1,21 +1,21 @@ # typed: strict # frozen_string_literal: true -require 'sorbet-runtime' -require 'yaml' -require 'pathname' +require "sorbet-runtime" +require "yaml" +require "pathname" # fileutils is loaded by a development gem dependency, but requiring here so clients # do not get `uninitialized constant ParsePackwerk::FileUtils` -require 'fileutils' +require "fileutils" -require 'parse_packwerk/constants' -require 'parse_packwerk/violation' -require 'parse_packwerk/package_todo' -require 'parse_packwerk/package' -require 'parse_packwerk/configuration' -require 'parse_packwerk/package_set' -require 'parse_packwerk/extensions' +require "parse_packwerk/constants" +require "parse_packwerk/violation" +require "parse_packwerk/package_todo" +require "parse_packwerk/package" +require "parse_packwerk/configuration" +require "parse_packwerk/package_set" +require "parse_packwerk/extensions" module ParsePackwerk class PackageParseError < StandardError @@ -67,47 +67,49 @@ def self.package_from_path(file_path) path_string = file_path.to_s @package_from_path = T.let(@package_from_path, T.nilable(T::Hash[String, Package])) @package_from_path ||= {} - @package_from_path[path_string] ||= T.must(begin - matching_package = all.find { |package| path_string.start_with?("#{package.name}/") || path_string == package.name } - matching_package || find(ROOT_PACKAGE_NAME) - end) + @package_from_path[path_string] ||= T.must( + begin + matching_package = all.find { |package| path_string.start_with?("#{package.name}/") || path_string == package.name } + matching_package || find(ROOT_PACKAGE_NAME) + end + ) end sig { params(package: ParsePackwerk::Package).void } def self.write_package_yml!(package) FileUtils.mkdir_p(package.directory) - File.open(package.yml, 'w') do |file| + File.open(package.yml, "w") do |file| merged_config = package.config - merged_config.merge!('enforce_dependencies' => package.enforce_dependencies) + merged_config.merge!("enforce_dependencies" => package.enforce_dependencies) if Extensions.privacy_extension_installed? - merged_config.merge!('enforce_privacy' => package.enforce_privacy) + merged_config.merge!("enforce_privacy" => package.enforce_privacy) end if Extensions.layer_extension_installed? - merged_config.merge!('enforce_layers' => package.enforce_layers) + merged_config.merge!("enforce_layers" => package.enforce_layers) end unless package.public_path == DEFAULT_PUBLIC_PATH - merged_config.merge!('public_path' => package.public_path) + merged_config.merge!("public_path" => package.public_path) end if package.dependencies.nil? || package.dependencies.none? - merged_config.delete('dependencies') + merged_config.delete("dependencies") else - merged_config.merge!('dependencies' => package.dependencies) + merged_config.merge!("dependencies" => package.dependencies) end if package.metadata.any? - merged_config.merge!('metadata' => package.metadata) + merged_config.merge!("metadata" => package.metadata) end merged_config = sort_keys(merged_config, package.original_key_order) raw_yaml = YAML.dump(merged_config) - stylized_yaml = raw_yaml.gsub("---\n", '') + stylized_yaml = raw_yaml.gsub("---\n", "") file.write(stylized_yaml) end end @@ -131,7 +133,7 @@ def self.sort_keys(config, original_key_order) sig { returns(T::Array[String]) } def self.key_sort_order - %w[ + %w( enforce_dependencies enforce_privacy enforce_visibility @@ -143,21 +145,23 @@ def self.key_sort_order ignored_dependencies visible_to metadata - ] + ) end # We memoize packages_by_name for fast lookup. # Since Graph is an immutable value object, we can create indexes and general caching mechanisms safely. sig { returns(T::Hash[String, Package]) } def self.packages_by_name - @packages_by_name = T.let(@packages_by_name, T.nilable(T::Hash[String, Package])) - @packages_by_name ||= begin - all_packages = PackageSet.from(package_pathspec: yml.package_paths, exclude_pathspec: yml.exclude) - # We want to match more specific paths first - # Packwerk does this too and is necessary for package_from_path to work correctly. - sorted_packages = all_packages.sort_by { |package| -package.name.length } - sorted_packages.to_h { |p| [p.name, p] } - end + @packages_by_name ||= T.let( + begin + all_packages = PackageSet.from(package_pathspec: yml.package_paths, exclude_pathspec: yml.exclude) + # We want to match more specific paths first + # Packwerk does this too and is necessary for package_from_path to work correctly. + sorted_packages = all_packages.sort_by { |package| -package.name.length } + sorted_packages.to_h { |p| [p.name, p] } + end, + T.nilable(T::Hash[String, Package]) + ) end sig { void } diff --git a/lib/parse_packwerk/configuration.rb b/lib/parse_packwerk/configuration.rb index 4c0d922..14a4811 100644 --- a/lib/parse_packwerk/configuration.rb +++ b/lib/parse_packwerk/configuration.rb @@ -24,22 +24,22 @@ def self.fetch Configuration.new( exclude: excludes(raw_packwerk_config), package_paths: package_paths(raw_packwerk_config), - requires: raw_packwerk_config['require'] || [], + requires: raw_packwerk_config["require"] || [], raw: raw_packwerk_config ) end sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[String]) } def self.excludes(config_hash) - specified_exclude = config_hash['exclude'] + specified_exclude = config_hash["exclude"] excludes = if specified_exclude.nil? - DEFAULT_EXCLUDE_GLOBS.dup - else - Array(specified_exclude) - end + DEFAULT_EXCLUDE_GLOBS.dup + else + Array(specified_exclude) + end begin - excludes.push Bundler.bundle_path.join('**').to_s + excludes.push Bundler.bundle_path.join("**").to_s rescue Bundler::GemfileNotFound # Optionally, add bundle to the path. Skip when there isn't a Gemfile. end @@ -49,15 +49,15 @@ def self.excludes(config_hash) sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[String]) } def self.package_paths(config_hash) - specified_package_paths = config_hash['package_paths'] + specified_package_paths = config_hash["package_paths"] package_paths = if specified_package_paths.nil? - DEFAULT_PACKAGE_PATHS.dup - else - Array(specified_package_paths) - end + DEFAULT_PACKAGE_PATHS.dup + else + Array(specified_package_paths) + end # We add the root package path always - package_paths.push '.' + package_paths.push "." end end end diff --git a/lib/parse_packwerk/constants.rb b/lib/parse_packwerk/constants.rb index 867269f..e5989ad 100644 --- a/lib/parse_packwerk/constants.rb +++ b/lib/parse_packwerk/constants.rb @@ -2,19 +2,19 @@ # frozen_string_literal: true module ParsePackwerk - ROOT_PACKAGE_NAME = T.let('.', String) - PACKAGE_YML_NAME = T.let('package.yml', String) - PACKWERK_YML_NAME = T.let('packwerk.yml', String) - PACKAGE_TODO_YML_NAME = T.let('package_todo.yml', String) - ENFORCE_DEPENDENCIES = T.let('enforce_dependencies', String) - ENFORCE_PRIVACY = T.let('enforce_privacy', String) - ENFORCE_LAYERS = T.let('enforce_layers', String) - DEPENDENCY_VIOLATION_TYPE = T.let('dependency', String) - PRIVACY_VIOLATION_TYPE = T.let('privacy', String) - PUBLIC_PATH = T.let('public_path', String) - OWNER = T.let('owner', String) - METADATA = T.let('metadata', String) - DEPENDENCIES = T.let('dependencies', String) + ROOT_PACKAGE_NAME = T.let(".", String) + PACKAGE_YML_NAME = T.let("package.yml", String) + PACKWERK_YML_NAME = T.let("packwerk.yml", String) + PACKAGE_TODO_YML_NAME = T.let("package_todo.yml", String) + ENFORCE_DEPENDENCIES = T.let("enforce_dependencies", String) + ENFORCE_PRIVACY = T.let("enforce_privacy", String) + ENFORCE_LAYERS = T.let("enforce_layers", String) + DEPENDENCY_VIOLATION_TYPE = T.let("dependency", String) + PRIVACY_VIOLATION_TYPE = T.let("privacy", String) + PUBLIC_PATH = T.let("public_path", String) + OWNER = T.let("owner", String) + METADATA = T.let("metadata", String) + DEPENDENCIES = T.let("dependencies", String) # Since this metadata is unstructured YAML, it could be any type. We leave it to clients of `ParsePackwerk::Package` # to add types based on their known usage of metadata. @@ -22,7 +22,7 @@ module ParsePackwerk T::Hash[T.untyped, T.untyped] end - DEFAULT_EXCLUDE_GLOBS = T.let(['{bin,node_modules,script,tmp,vendor}/**/*'], T::Array[String]) - DEFAULT_PACKAGE_PATHS = T.let(['**/'], T::Array[String]) - DEFAULT_PUBLIC_PATH = T.let('app/public', String) + DEFAULT_EXCLUDE_GLOBS = T.let(["{bin,node_modules,script,tmp,vendor}/**/*"], T::Array[String]) + DEFAULT_PACKAGE_PATHS = T.let(["**/"], T::Array[String]) + DEFAULT_PUBLIC_PATH = T.let("app/public", String) end diff --git a/lib/parse_packwerk/extensions.rb b/lib/parse_packwerk/extensions.rb index 4c8c4fc..1d18e89 100644 --- a/lib/parse_packwerk/extensions.rb +++ b/lib/parse_packwerk/extensions.rb @@ -7,17 +7,17 @@ module Extensions sig { returns(T::Boolean) } def self.all_extensions_installed? - ParsePackwerk.yml.requires.include?('packwerk-extensions') + ParsePackwerk.yml.requires.include?("packwerk-extensions") end sig { returns(T::Boolean) } def self.privacy_extension_installed? - all_extensions_installed? || ParsePackwerk.yml.requires.include?('packwerk/privacy/checker') + all_extensions_installed? || ParsePackwerk.yml.requires.include?("packwerk/privacy/checker") end sig { returns(T::Boolean) } def self.layer_extension_installed? - all_extensions_installed? || ParsePackwerk.yml.requires.include?('packwerk/layer/checker') + all_extensions_installed? || ParsePackwerk.yml.requires.include?("packwerk/layer/checker") end end diff --git a/lib/parse_packwerk/package_set.rb b/lib/parse_packwerk/package_set.rb index 9b814cf..262f626 100644 --- a/lib/parse_packwerk/package_set.rb +++ b/lib/parse_packwerk/package_set.rb @@ -1,8 +1,8 @@ # typed: strict # frozen_string_literal: true -require 'pathname' -require 'bundler' +require "pathname" +require "bundler" module ParsePackwerk class PackageSet diff --git a/lib/parse_packwerk/package_todo.rb b/lib/parse_packwerk/package_todo.rb index b70ae72..5e9b860 100644 --- a/lib/parse_packwerk/package_todo.rb +++ b/lib/parse_packwerk/package_todo.rb @@ -23,8 +23,8 @@ def self.from(pathname) 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'] + files = symbol_usage["files"] + violations = symbol_usage["violations"] violations.uniq.each do |violation_type| all_violations << Violation.new(type: violation_type, to_package_name: to_package_name, class_name: class_name, files: files) end diff --git a/lib/parse_packwerk/violation.rb b/lib/parse_packwerk/violation.rb index 57a8965..a471026 100644 --- a/lib/parse_packwerk/violation.rb +++ b/lib/parse_packwerk/violation.rb @@ -12,12 +12,12 @@ class Violation < T::Struct sig { returns(T::Boolean) } def dependency? - type == 'dependency' + type == "dependency" end sig { returns(T::Boolean) } def privacy? - type == 'privacy' + type == "privacy" end end end diff --git a/parse_packwerk.gemspec b/parse_packwerk.gemspec index 808de61..14d8cd5 100644 --- a/parse_packwerk.gemspec +++ b/parse_packwerk.gemspec @@ -1,40 +1,41 @@ # frozen_string_literal: true Gem::Specification.new do |spec| - spec.name = 'parse_packwerk' - spec.version = '0.28.0' - spec.authors = ['Gusto Engineers'] - spec.email = ['dev@gusto.com'] - spec.summary = 'A low-dependency gem for parsing and writing packwerk YML files' - spec.description = 'A low-dependency gem for parsing and writing packwerk YML files' - spec.homepage = 'https://github.com/rubyatscale/parse_packwerk' - spec.license = 'MIT' + spec.name = "parse_packwerk" + spec.version = "0.28.0" + spec.authors = ["Gusto Engineers"] + spec.email = ["dev@gusto.com"] + spec.summary = "A low-dependency gem for parsing and writing packwerk YML files" + spec.description = "A low-dependency gem for parsing and writing packwerk YML files" + spec.homepage = "https://github.com/rubyatscale/parse_packwerk" + spec.license = "MIT" if spec.respond_to?(:metadata) - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/rubyatscale/parse_packwerk' - spec.metadata['changelog_uri'] = 'https://github.com/rubyatscale/parse_packwerk/releases' - spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/rubyatscale/parse_packwerk" + spec.metadata["changelog_uri"] = "https://github.com/rubyatscale/parse_packwerk/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 # Specify which files should be added to the gem when it is released. - 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 'bigdecimal' - spec.add_dependency 'sorbet-runtime' + spec.add_dependency "bigdecimal" + spec.add_dependency "sorbet-runtime" - spec.add_development_dependency 'awesome_print' - spec.add_development_dependency 'bundler', '~> 2.2' - spec.add_development_dependency 'hashdiff' - spec.add_development_dependency 'pry' - 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_development_dependency "awesome_print" + spec.add_development_dependency "bundler", "~> 2.2" + spec.add_development_dependency "hashdiff" + spec.add_development_dependency "pry" + spec.add_development_dependency "rake" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "rubocop" + spec.add_development_dependency "rubocop-gusto" + spec.add_development_dependency "sorbet" + spec.add_development_dependency "tapioca" end diff --git a/spec/parse_packwerk_spec.rb b/spec/parse_packwerk_spec.rb index f2b5536..d06b3ea 100644 --- a/spec/parse_packwerk_spec.rb +++ b/spec/parse_packwerk_spec.rb @@ -1,30 +1,31 @@ +# typed: false # frozen_string_literal: true RSpec.describe ParsePackwerk do + subject(:all_packages) do + ParsePackwerk.all + end + before do write_packwerk_yml ParsePackwerk.bust_cache! end let(:write_packwerk_yml) do - write_file('packwerk.yml', <<~YML) + write_file("packwerk.yml", <<~YML) require: - packwerk-extensions YML end - subject(:all_packages) do - ParsePackwerk.all - end - - describe '.all' do - context 'in empty app' do + describe ".all" do + context "in empty app" do it { is_expected.to be_empty } end - context 'in app with a trivial root package' do + context "in app with a trivial root package" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # This file represents the root package of the application # Please validate the configuration using `bin/packwerk validate` (for Rails applications) or running the auto generated # test case (for non-Rails projects). You can then use `packwerk check` to check your code. @@ -50,7 +51,7 @@ let(:expected_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, dependencies: [], @@ -61,28 +62,28 @@ end let(:expected_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new("package_todo.yml")) end - it 'correctly finds the package YML' do - expect(expected_package.yml).to eq Pathname.new('package.yml') + it "correctly finds the package YML" do + expect(expected_package.yml).to eq Pathname.new("package.yml") end - it 'correctly finds the package directory' do - expect(expected_package.directory).to eq Pathname.new('.') + it "correctly finds the package directory" do + expect(expected_package.directory).to eq Pathname.new(".") end it { is_expected.to have_matching_package expected_package, expected_package_todo } end - context 'in app that enforces privacy and dependencies' do + context "in app that enforces privacy and dependencies" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # This file represents the root package of the application # Please validate the configuration using `bin/packwerk validate` (for Rails applications) or running the auto generated # test case (for non-Rails projects). You can then use `packwerk check` to check your code. @@ -108,7 +109,7 @@ let(:expected_root_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, dependencies: [], @@ -119,14 +120,16 @@ end let(:expected_root_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new("package_todo.yml")) end - it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } + let(:expected_domain_package_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new("packs/package1/package_todo.yml")) + end let(:expected_domain_package) do ParsePackwerk::Package.new( - name: 'packs/package1', + name: "packs/package1", enforce_dependencies: true, enforce_privacy: true, dependencies: [], @@ -136,30 +139,28 @@ ) end - let(:expected_domain_package_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('packs/package1/package_todo.yml')) - end + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } - it 'correctly finds the package YML' do - expect(expected_domain_package.yml).to eq Pathname.new('packs/package1/package.yml') + it "correctly finds the package YML" do + expect(expected_domain_package.yml).to eq Pathname.new("packs/package1/package.yml") end - it 'correctly finds the package directory' do - expect(expected_domain_package.directory).to eq Pathname.new('packs/package1') + it "correctly finds the package directory" do + expect(expected_domain_package.directory).to eq Pathname.new("packs/package1") end it { is_expected.to have_matching_package expected_domain_package, expected_domain_package_package_todo } end - context 'in app that has public_path' do + context "in app that has public_path" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true public_path: other/path CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # This file represents the root package of the application # Please validate the configuration using `bin/packwerk validate` (for Rails applications) or running the auto generated # test case (for non-Rails projects). You can then use `packwerk check` to check your code. @@ -185,10 +186,10 @@ let(:expected_root_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", dependencies: [], metadata: {}, config: {}, @@ -197,17 +198,19 @@ end let(:expected_root_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new("package_todo.yml")) end - it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new("packs/package1/package_todo.yml")) + end let(:expected_domain_package) do ParsePackwerk::Package.new( - name: 'packs/package1', + name: "packs/package1", enforce_dependencies: true, enforce_privacy: true, - public_path: 'other/path', + public_path: "other/path", dependencies: [], metadata: {}, config: {}, @@ -215,16 +218,14 @@ ) end - let(:expected_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('packs/package1/package_todo.yml')) - end + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } it { is_expected.to have_matching_package expected_domain_package, expected_package_todo } end - context 'package does not declare enforce_dependencies' do + context "package does not declare enforce_dependencies" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # A list of this package's dependencies # Note that packages in this list require their own `package.yml` file @@ -233,17 +234,17 @@ end let(:valid_package) { - ParsePackwerk::Package.from(Pathname.new('package.yml')) + ParsePackwerk::Package.from(Pathname.new("package.yml")) } - it 'should be valid' do - expect { valid_package }.to_not raise_error + it "should be valid" do + expect { valid_package }.not_to raise_error end end - context 'in app that has metadata' do + context "in app that has metadata" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true metadata: @@ -253,7 +254,7 @@ numeric_key: 123 CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # This file represents the root package of the application # Please validate the configuration using `bin/packwerk validate` (for Rails applications) or running the auto generated # test case (for non-Rails projects). You can then use `packwerk check` to check your code. @@ -279,7 +280,7 @@ let(:expected_root_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, dependencies: [], @@ -290,92 +291,92 @@ end let(:expected_root_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new("package_todo.yml")) end - it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } + let(:expected_package_todo) do + ParsePackwerk::PackageTodo.from(Pathname.new("packs/package1/package_todo.yml")) + end let(:expected_domain_package) do ParsePackwerk::Package.new( - name: 'packs/package1', + name: "packs/package1", enforce_dependencies: true, enforce_privacy: true, dependencies: [], metadata: { - 'string_key' => 'this_is_a_string', - 'obviously_a_boolean_key' => false, - 'not_obviously_a_boolean_key' => false, - 'numeric_key' => 123 + "string_key" => "this_is_a_string", + "obviously_a_boolean_key" => false, + "not_obviously_a_boolean_key" => false, + "numeric_key" => 123, }, config: {}, violations: [] ) end - let(:expected_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('packs/package1/package_todo.yml')) - end + it { is_expected.to have_matching_package expected_root_package, expected_root_package_todo } it { is_expected.to have_matching_package expected_domain_package, expected_package_todo } end - context 'in app that has a top-level owner' do + context "in app that has a top-level owner" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true owner: Mission > Team metadata: owner: Legacy Team CONTENTS - write_file('packs/package2/package.yml', <<~CONTENTS) + write_file("packs/package2/package.yml", <<~CONTENTS) enforce_dependencies: true CONTENTS end - it 'reads the top-level owner, separately from metadata' do - package = ParsePackwerk.find('packs/package1') + it "reads the top-level owner, separately from metadata" do + package = ParsePackwerk.find("packs/package1") - expect(package.owner).to eq 'Mission > Team' - expect(package.metadata).to eq('owner' => 'Legacy Team') + expect(package.owner).to eq "Mission > Team" + expect(package.metadata).to eq("owner" => "Legacy Team") end - it 'is nil for a package without one' do - expect(ParsePackwerk.find('packs/package2').owner).to be_nil + it "is nil for a package without one" do + expect(ParsePackwerk.find("packs/package2").owner).to be_nil end - it 'does not fall back to metadata.owner' do - write_file('packs/package2/package.yml', <<~CONTENTS) + it "does not fall back to metadata.owner" do + write_file("packs/package2/package.yml", <<~CONTENTS) enforce_dependencies: true metadata: owner: Legacy Team CONTENTS - expect(ParsePackwerk.find('packs/package2').owner).to be_nil + expect(ParsePackwerk.find("packs/package2").owner).to be_nil end - context 'when the owner is not a string' do + context "when the owner is not a string" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true owner: 123 CONTENTS end - it 'still loads the package, with a nil owner, and writes the value back unchanged' do - package = ParsePackwerk.find('packs/package1') + it "still loads the package, with a nil owner, and writes the value back unchanged" do + package = ParsePackwerk.find("packs/package1") expect(package.owner).to be_nil ParsePackwerk.write_package_yml!(package) - expect(YAML.load_file('packs/package1/package.yml')['owner']).to eq 123 + expect(YAML.load_file("packs/package1/package.yml")["owner"]).to eq 123 end end end - context 'in app that has violations' do + context "in app that has violations" do before do - write_file('packs/package2/package_todo.yml', <<~CONTENTS) + write_file("packs/package2/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. # @@ -402,12 +403,12 @@ - root_file.rb CONTENTS - write_file('packs/package2/package.yml', <<~CONTENTS) + write_file("packs/package2/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true CONTENTS - write_file('packs/package1/package_todo.yml', <<~CONTENTS) + write_file("packs/package1/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. # @@ -423,14 +424,14 @@ - packs/package2/lib/some_other_file.rb CONTENTS - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true dependencies: - packs/package2 CONTENTS - write_file('package_todo.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. # @@ -454,7 +455,7 @@ - extended/path/to/file.rb CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) # This file represents the root package of the application # Please validate the configuration using `bin/packwerk validate` (for Rails applications) or running the auto generated # test case (for non-Rails projects). You can then use `packwerk check` to check your code. @@ -481,10 +482,10 @@ let(:expected_root_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: true, enforce_privacy: false, - dependencies: ['packs/package2'], + dependencies: ["packs/package2"], metadata: {}, config: {}, violations: [] @@ -493,32 +494,56 @@ let(:expected_package_todo) do ParsePackwerk::PackageTodo.new( - pathname: Pathname.new('package_todo.yml'), + pathname: Pathname.new("package_todo.yml"), violations: [ ParsePackwerk::Violation.new( - type: 'dependency', - to_package_name: 'packs/package1', - class_name: 'SomeConstant', - files: ['some_file.rb'] + type: "dependency", + to_package_name: "packs/package1", + class_name: "SomeConstant", + files: ["some_file.rb"] ), ParsePackwerk::Violation.new( - type: 'privacy', - to_package_name: 'packs/package2', - class_name: 'SomePrivateConstant', - files: ['some_other_file.rb', 'path/to/file.rb', 'extended/path/to/file.rb'] - ) + type: "privacy", + to_package_name: "packs/package2", + class_name: "SomePrivateConstant", + files: ["some_other_file.rb", "path/to/file.rb", "extended/path/to/file.rb"] + ), ] ) end - it { is_expected.to have_matching_package expected_root_package, expected_package_todo } + let(:expected_domain_package_package_todo2) do + ParsePackwerk::PackageTodo.new( + pathname: Pathname.new("packs/package2/package_todo.yml"), + violations: [ + ParsePackwerk::Violation.new( + type: "dependency", + to_package_name: "packs/package1", + class_name: "SomeConstant", + files: ["packs/package1/lib/some_file.rb"] + ), + ParsePackwerk::Violation.new( + type: "dependency", + to_package_name: ".", + class_name: "SomeRootConstant", + files: ["root_file.rb"] + ), + ParsePackwerk::Violation.new( + type: "dependency", + to_package_name: ".", + class_name: "SomeOtherRootConstant", + files: ["root_file.rb"] + ), + ] + ) + end - let(:expected_domain_package1) do + let(:expected_domain_package2) do ParsePackwerk::Package.new( - name: 'packs/package1', + name: "packs/package2", enforce_dependencies: true, enforce_privacy: true, - dependencies: ['packs/package2'], + dependencies: [], metadata: {}, config: {}, violations: [] @@ -527,186 +552,162 @@ let(:expected_package_todo1) do ParsePackwerk::PackageTodo.new( - pathname: Pathname.new('packs/package1/package_todo.yml'), + pathname: Pathname.new("packs/package1/package_todo.yml"), violations: [ ParsePackwerk::Violation.new( - type: 'privacy', - to_package_name: 'packs/package2', - class_name: 'SomePrivateConstant', - files: ['packs/package2/lib/some_other_file.rb'] - ) + type: "privacy", + to_package_name: "packs/package2", + class_name: "SomePrivateConstant", + files: ["packs/package2/lib/some_other_file.rb"] + ), ] ) end - it { is_expected.to have_matching_package expected_domain_package1, expected_package_todo1 } - - let(:expected_domain_package2) do + let(:expected_domain_package1) do ParsePackwerk::Package.new( - name: 'packs/package2', + name: "packs/package1", enforce_dependencies: true, enforce_privacy: true, - dependencies: [], + dependencies: ["packs/package2"], metadata: {}, config: {}, violations: [] ) end - let(:expected_domain_package_package_todo2) do - ParsePackwerk::PackageTodo.new( - pathname: Pathname.new('packs/package2/package_todo.yml'), - violations: [ - ParsePackwerk::Violation.new( - type: 'dependency', - to_package_name: 'packs/package1', - class_name: 'SomeConstant', - files: ['packs/package1/lib/some_file.rb'] - ), - ParsePackwerk::Violation.new( - type: 'dependency', - to_package_name: '.', - class_name: 'SomeRootConstant', - files: ['root_file.rb'] - ), - ParsePackwerk::Violation.new( - type: 'dependency', - to_package_name: '.', - class_name: 'SomeOtherRootConstant', - files: ['root_file.rb'] - ) - ] - ) - end + it { is_expected.to have_matching_package expected_root_package, expected_package_todo } + + it { is_expected.to have_matching_package expected_domain_package1, expected_package_todo1 } it { is_expected.to have_matching_package expected_domain_package2, expected_domain_package_package_todo2 } end - context 'in an app that has specified package paths' do - context 'app has specified packs in a specific folder' do + context "in an app that has specified package paths" do + context "app has specified packs in a specific folder" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) package_paths: - 'packs/*' CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('app/services/my_non_package_location/package.yml', <<~CONTENTS) + write_file("app/services/my_non_package_location/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS end - it 'includes the correct set of packages' do + it "includes the correct set of packages" do expect(all_packages.count).to eq 2 - expect(all_packages.find { |p| p.name == '.' }).to_not be_nil - expect(all_packages.find { |p| p.name == 'packs/my_pack' }).to_not be_nil + expect(all_packages.find { |p| p.name == "." }).not_to be_nil + expect(all_packages.find { |p| p.name == "packs/my_pack" }).not_to be_nil end end - context 'app has excluded packs in a specific folder' do + context "app has excluded packs in a specific folder" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) package_paths: - 'packs/*' exclude: - 'packs/pack_to_ignore/*' CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/pack_to_ignore/package.yml', <<~CONTENTS) + write_file("packs/pack_to_ignore/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('app/services/my_non_package_location/package.yml', <<~CONTENTS) + write_file("app/services/my_non_package_location/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS end - it 'includes the correct set of packages' do + it "includes the correct set of packages" do expect(all_packages.count).to eq 2 - expect(all_packages.find { |p| p.name == '.' }).to_not be_nil - expect(all_packages.find { |p| p.name == 'packs/my_pack' }).to_not be_nil + expect(all_packages.find { |p| p.name == "." }).not_to be_nil + expect(all_packages.find { |p| p.name == "packs/my_pack" }).not_to be_nil end end end - context 'in an app with no root package' do + context "in an app with no root package" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS end - it 'includes the correct set of packages' do + it "includes the correct set of packages" do expect(all_packages.count).to eq 2 - expect(all_packages.find { |p| p.name == '.' }).to_not be_nil - expect(all_packages.find { |p| p.name == 'packs/my_pack' }).to_not be_nil + expect(all_packages.find { |p| p.name == "." }).not_to be_nil + expect(all_packages.find { |p| p.name == "packs/my_pack" }).not_to be_nil end end - context 'in an app with nested packs' do + context "in an app with nested packs" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/subpack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/subpack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS end - it 'includes the correct set of packages' do + it "includes the correct set of packages" do expect(all_packages.count).to eq 3 - expect(all_packages.find { |p| p.name == '.' }).to_not be_nil - expect(all_packages.find { |p| p.name == 'packs/my_pack' }).to_not be_nil - expect(all_packages.find { |p| p.name == 'packs/my_pack/subpack' }).to_not be_nil + expect(all_packages.find { |p| p.name == "." }).not_to be_nil + expect(all_packages.find { |p| p.name == "packs/my_pack" }).not_to be_nil + expect(all_packages.find { |p| p.name == "packs/my_pack/subpack" }).not_to be_nil end end - context 'in an app that does not use privacy checker' do + context "in an app that does not use privacy checker" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false CONTENTS end let(:expected_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, dependencies: [], @@ -717,24 +718,24 @@ end let(:expected_package_todo) do - ParsePackwerk::PackageTodo.from(Pathname.new('package_todo.yml')) + ParsePackwerk::PackageTodo.from(Pathname.new("package_todo.yml")) end - it 'correctly finds the package YML' do - expect(expected_package.yml).to eq Pathname.new('package.yml') + it "correctly finds the package YML" do + expect(expected_package.yml).to eq Pathname.new("package.yml") end - it 'correctly finds the package directory' do - expect(expected_package.directory).to eq Pathname.new('.') + it "correctly finds the package directory" do + expect(expected_package.directory).to eq Pathname.new(".") end it { is_expected.to have_matching_package expected_package, expected_package_todo } end - context 'in app with an empty package.yml' do + context "in app with an empty package.yml" do let(:expected_package) do ParsePackwerk::Package.new( - name: 'packs/my_pack', + name: "packs/my_pack", enforce_dependencies: nil, enforce_privacy: false, dependencies: [], @@ -749,42 +750,42 @@ end before do - write_file('packs/my_pack/package.yml', '') + write_file("packs/my_pack/package.yml", "") end - it 'parses the file and returns a package with empty values' do + it "parses the file and returns a package with empty values" do expect(subject).to have_matching_package(expected_package, expected_package_todo) end end end - describe 'ParsePackwerk::Package#violations' do - context 'in app with a trivial root package' do + describe "ParsePackwerk::Package#violations" do + context "in app with a trivial root package" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS end - it 'has no violations' do - expect(ParsePackwerk.find('.').violations).to be_empty + it "has no violations" do + expect(ParsePackwerk.find(".").violations).to be_empty end end - context 'in app that has violations' do + context "in app that has violations" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true CONTENTS - write_file('packs/my_pack/package_todo.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. # @@ -801,9 +802,9 @@ CONTENTS end - it 'has violations' do - expected_violation = ParsePackwerk::Violation.new(class_name: 'SomeRootConstant', files: ['packs/my_pack/my_file.rb'], to_package_name: '.', type: 'dependency') - actual_violations = ParsePackwerk.find('packs/my_pack').violations + it "has violations" do + expected_violation = ParsePackwerk::Violation.new(class_name: "SomeRootConstant", files: ["packs/my_pack/my_file.rb"], to_package_name: ".", type: "dependency") + actual_violations = ParsePackwerk.find("packs/my_pack").violations expect(actual_violations.count).to eq 1 expect(actual_violations.first.class_name).to eq expected_violation.class_name expect(actual_violations.first.files).to eq expected_violation.files @@ -813,99 +814,101 @@ end end - describe '.yml' do + describe ".yml" do let(:configuration) { ParsePackwerk.yml } - describe 'exclude' do + describe "exclude" do subject { configuration.exclude } - context 'when the configuration file is not present' do - it { is_expected.to contain_exactly(Bundler.bundle_path.join('**').to_s, '{bin,node_modules,script,tmp,vendor}/**/*') } + context "when the configuration file is not present" do + it { is_expected.to contain_exactly(Bundler.bundle_path.join("**").to_s, "{bin,node_modules,script,tmp,vendor}/**/*") } end - context 'configuration is present' do + context "configuration is present" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) exclude: - 'a/b/**/c.rb' CONTENTS end - it { is_expected.to contain_exactly(Bundler.bundle_path.join('**').to_s, 'a/b/**/c.rb') } + it { is_expected.to contain_exactly(Bundler.bundle_path.join("**").to_s, "a/b/**/c.rb") } end - context 'when the exclude option is not defined' do + context "when the exclude option is not defined" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) # empty file CONTENTS end - it { is_expected.to contain_exactly(Bundler.bundle_path.join('**').to_s, '{bin,node_modules,script,tmp,vendor}/**/*') } + it { is_expected.to contain_exactly(Bundler.bundle_path.join("**").to_s, "{bin,node_modules,script,tmp,vendor}/**/*") } end - context 'when the exclude option is a string and not a list of strings' do + context "when the exclude option is a string and not a list of strings" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) exclude: 'a/b/**/c.rb' CONTENTS end - it { is_expected.to contain_exactly(Bundler.bundle_path.join('**').to_s, 'a/b/**/c.rb') } + + it { is_expected.to contain_exactly(Bundler.bundle_path.join("**").to_s, "a/b/**/c.rb") } end end - describe 'package_paths' do + describe "package_paths" do subject { configuration.package_paths } - context 'when the configuration file is not present' do - it { is_expected.to contain_exactly('**/', '.') } + context "when the configuration file is not present" do + it { is_expected.to contain_exactly("**/", ".") } end - context 'configuration is present' do + context "configuration is present" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) package_paths: - 'packs/*' CONTENTS end - it { is_expected.to contain_exactly('packs/*', '.') } + it { is_expected.to contain_exactly("packs/*", ".") } end - context 'when the package paths option is not defined' do + context "when the package paths option is not defined" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) # empty file CONTENTS end - it { is_expected.to contain_exactly('**/', '.') } + it { is_expected.to contain_exactly("**/", ".") } end - context 'when the package paths option is a string and not a list of strings' do + context "when the package paths option is a string and not a list of strings" do before do - write_file('packwerk.yml', <<~CONTENTS) + write_file("packwerk.yml", <<~CONTENTS) package_paths: 'packs/*' CONTENTS end - it { is_expected.to contain_exactly('packs/*', '.') } + + it { is_expected.to contain_exactly("packs/*", ".") } end end end - describe 'ParsePackwerk.package_from_path' do + describe "ParsePackwerk.package_from_path" do before do - write_file('packs/package1/package.yml', <<~CONTENTS) + write_file("packs/package1/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: true CONTENTS - write_file('packs/package1_new/package.yml', <<~CONTENTS) + write_file("packs/package1_new/package.yml", <<~CONTENTS) enforce_dependencies: true enforce_privacy: false CONTENTS - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS @@ -913,7 +916,7 @@ let(:expected_package1) do ParsePackwerk::Package.new( - name: 'packs/package1', + name: "packs/package1", enforce_dependencies: true, enforce_privacy: true, dependencies: [], @@ -925,7 +928,7 @@ let(:expected_package1_new) do ParsePackwerk::Package.new( - name: 'packs/package1_new', + name: "packs/package1_new", enforce_dependencies: true, enforce_privacy: false, dependencies: [], @@ -935,54 +938,60 @@ ) end - context 'given a filepath in pack1' do - let(:filepath) { 'packs/package1/path/to/file.rb' } + context "given a filepath in pack1" do + let(:filepath) { "packs/package1/path/to/file.rb" } - it 'returns the correct package' do + it "returns the correct package" do package = ParsePackwerk.package_from_path(filepath) - expect(package).to have_attributes({ - name: expected_package1.name, - enforce_dependencies: expected_package1.enforce_dependencies, - enforce_privacy: expected_package1.enforce_privacy - }) + expect(package).to have_attributes( + { + name: expected_package1.name, + enforce_dependencies: expected_package1.enforce_dependencies, + enforce_privacy: expected_package1.enforce_privacy, + } + ) end end - context 'given a file path in pack1_new' do - let(:filepath) { 'packs/package1_new/path/to/file.rb' } + context "given a file path in pack1_new" do + let(:filepath) { "packs/package1_new/path/to/file.rb" } - it 'returns the correct package' do + it "returns the correct package" do package = ParsePackwerk.package_from_path(filepath) - expect(package).to have_attributes({ - name: expected_package1_new.name, - enforce_dependencies: expected_package1_new.enforce_dependencies, - enforce_privacy: expected_package1_new.enforce_privacy - }) + expect(package).to have_attributes( + { + name: expected_package1_new.name, + enforce_dependencies: expected_package1_new.enforce_dependencies, + enforce_privacy: expected_package1_new.enforce_privacy, + } + ) end end - context 'given a file path that is exactly the root of a pack' do - let(:filepath) { 'packs/package1' } + context "given a file path that is exactly the root of a pack" do + let(:filepath) { "packs/package1" } - it 'returns the correct pack' do + it "returns the correct pack" do package = ParsePackwerk.package_from_path(filepath) - expect(package).to have_attributes({ - name: expected_package1.name, - enforce_dependencies: expected_package1.enforce_dependencies, - enforce_privacy: expected_package1.enforce_privacy - }) + expect(package).to have_attributes( + { + name: expected_package1.name, + enforce_dependencies: expected_package1.enforce_dependencies, + enforce_privacy: expected_package1.enforce_privacy, + } + ) end end - context 'given a file path not in a pack' do - let(:filepath) { 'path/to/file.rb' } + context "given a file path not in a pack" do + let(:filepath) { "path/to/file.rb" } let(:expected_root_package) do ParsePackwerk::Package.new( - name: '.', + name: ".", enforce_dependencies: false, enforce_privacy: false, dependencies: [], @@ -992,52 +1001,54 @@ ) end - it 'returns the root pack' do + it "returns the root pack" do package = ParsePackwerk.package_from_path(filepath) - expect(package).to have_attributes({ - name: expected_root_package.name, - enforce_dependencies: expected_root_package.enforce_dependencies, - enforce_privacy: expected_root_package.enforce_privacy - }) + expect(package).to have_attributes( + { + name: expected_root_package.name, + enforce_dependencies: expected_root_package.enforce_dependencies, + enforce_privacy: expected_root_package.enforce_privacy, + } + ) end end - context 'in an app with nested packs' do + context "in an app with nested packs" do before do - write_file('package.yml', <<~CONTENTS) + write_file("package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/file.rb') + write_file("packs/my_pack/file.rb") - write_file('packs/my_pack/subpack/package.yml', <<~CONTENTS) + write_file("packs/my_pack/subpack/package.yml", <<~CONTENTS) enforce_dependencies: false enforce_privacy: false CONTENTS - write_file('packs/my_pack/subpack/file.rb') + write_file("packs/my_pack/subpack/file.rb") end - it 'distinguishes between files in nested packs and parent packs' do - expect(ParsePackwerk.package_from_path('packs/my_pack/subpack/file.rb').name).to eq 'packs/my_pack/subpack' - expect(ParsePackwerk.package_from_path('packs/my_pack/file.rb').name).to eq 'packs/my_pack' + it "distinguishes between files in nested packs and parent packs" do + expect(ParsePackwerk.package_from_path("packs/my_pack/subpack/file.rb").name).to eq "packs/my_pack/subpack" + expect(ParsePackwerk.package_from_path("packs/my_pack/file.rb").name).to eq "packs/my_pack" end end end - describe 'ParsePackwerk.write_package_yml' do - let(:package_dir) { Pathname.new('packs/example_pack') } - let(:package_yml) { package_dir.join('package.yml') } - let(:package_todo_yml) { package_dir.join('package_todo.yml') } + describe "ParsePackwerk.write_package_yml" do + let(:package_dir) { Pathname.new("packs/example_pack") } + let(:package_yml) { package_dir.join("package.yml") } + let(:package_todo_yml) { package_dir.join("package_todo.yml") } - def build_pack(public_path: 'app/public', enforce_privacy: true, enforce_layers: true, owner: nil, dependencies: [], metadata: {}, config: {}) + def build_pack(public_path: "app/public", enforce_privacy: true, enforce_layers: true, owner: nil, dependencies: [], metadata: {}, config: {}) ParsePackwerk::Package.new( name: package_dir.to_s, enforce_dependencies: true, @@ -1046,7 +1057,7 @@ def build_pack(public_path: 'app/public', enforce_privacy: true, enforce_layers: public_path: public_path, dependencies: dependencies, metadata: metadata, - config: owner ? config.merge('owner' => owner) : config, + config: owner ? config.merge("owner" => owner) : config, violations: [] ) end @@ -1059,12 +1070,12 @@ def pack_as_hash(package) enforce_layers: package.enforce_layers, owner: package.owner, dependencies: package.dependencies, - metadata: package.metadata + metadata: package.metadata, } end - it 'does not generate invalid yaml for configs using enforcement_globs_ignore' do - path = Pathname.new('packs/my_pack/package.yml') + it "does not generate invalid yaml for configs using enforcement_globs_ignore" do + path = Pathname.new("packs/my_pack/package.yml") write_file path, <<~CONTENTS enforce_dependencies: false @@ -1083,10 +1094,10 @@ def pack_as_hash(package) expect { YAML.load_file(path) }.not_to raise_error end - context 'a simple package' do + context "a simple package" do let(:package) { build_pack } - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML enforce_dependencies: true @@ -1099,12 +1110,12 @@ def pack_as_hash(package) end end - context 'package with public_path' do + context "package with public_path" do let(:package) do - build_pack(public_path: 'other/path') + build_pack(public_path: "other/path") end - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML enforce_dependencies: true @@ -1118,12 +1129,12 @@ def pack_as_hash(package) end end - context 'package with strict checker enforcement' do + context "package with strict checker enforcement" do let(:package) do - build_pack(enforce_privacy: 'strict') + build_pack(enforce_privacy: "strict") end - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML enforce_dependencies: true @@ -1136,12 +1147,12 @@ def pack_as_hash(package) end end - context 'package with dependencies' do + context "package with dependencies" do let(:package) do - build_pack(dependencies: %w[my_other_pack1 my_other_pack2]) + build_pack(dependencies: %w(my_other_pack1 my_other_pack2)) end - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML enforce_dependencies: true @@ -1157,15 +1168,17 @@ def pack_as_hash(package) end end - context 'package with metadata' do + context "package with metadata" do let(:package) do - build_pack(metadata: { - 'owner' => 'Mission > Team', - 'protections' => { 'prevent_untyped_api' => 'fail_if_any', 'prevent_violations' => false } - }) + build_pack( + metadata: { + "owner" => "Mission > Team", + "protections" => { "prevent_untyped_api" => "fail_if_any", "prevent_violations" => false }, + } + ) end - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1183,7 +1196,7 @@ def pack_as_hash(package) expect(pack_as_hash(all_packages.first)).to eq pack_as_hash(package) end - context 'overwriting an existing package file' do + context "overwriting an existing package file" do before do write_file(package_yml, <<~CONTENTS) enforce_dependencies: true @@ -1196,10 +1209,10 @@ def pack_as_hash(package) end let(:existing_package) do - ParsePackwerk.find('packs/example_pack') + ParsePackwerk.find("packs/example_pack") end - it 'allows you to remove the dependencies list' do + it "allows you to remove the dependencies list" do new_package = existing_package.with(dependencies: []) ParsePackwerk.write_package_yml!(new_package) @@ -1214,10 +1227,10 @@ def pack_as_hash(package) end end - context 'package with owner' do - let(:package) { build_pack(owner: 'Mission > Team', dependencies: ['packs/foo']) } + context "package with owner" do + let(:package) { build_pack(owner: "Mission > Team", dependencies: ["packs/foo"]) } - it 'writes owner as a top-level key' do + it "writes owner as a top-level key" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1233,7 +1246,7 @@ def pack_as_hash(package) expect(pack_as_hash(all_packages.first)).to eq pack_as_hash(package) end - context 'overwriting an existing package file' do + context "overwriting an existing package file" do before do write_file(package_yml, <<~CONTENTS) enforce_dependencies: true @@ -1245,8 +1258,8 @@ def pack_as_hash(package) CONTENTS end - it 'allows you to change the owner' do - new_package = ParsePackwerk.find('packs/example_pack').with(owner: 'New Team') + it "allows you to change the owner" do + new_package = ParsePackwerk.find("packs/example_pack").with(owner: "New Team") ParsePackwerk.write_package_yml!(new_package) @@ -1260,15 +1273,15 @@ def pack_as_hash(package) PACKAGEYML end - it 'writes the file back unchanged when the owner is untouched' do + it "writes the file back unchanged when the owner is untouched" do original = package_yml.read - ParsePackwerk.write_package_yml!(ParsePackwerk.find('packs/example_pack')) + ParsePackwerk.write_package_yml!(ParsePackwerk.find("packs/example_pack")) expect(package_yml.read).to eq original end - it 'changes only the owner line when other config has non-string keys' do + it "changes only the owner line when other config has non-string keys" do write_file(package_yml, <<~CONTENTS) enforce_dependencies: true enforce_privacy: true @@ -1282,26 +1295,26 @@ def pack_as_hash(package) CONTENTS original = package_yml.read - ParsePackwerk.write_package_yml!(ParsePackwerk.find('packs/example_pack').with(owner: 'New Team')) + ParsePackwerk.write_package_yml!(ParsePackwerk.find("packs/example_pack").with(owner: "New Team")) - expect(package_yml.read).to eq original.sub('owner: Old Team', 'owner: New Team') + expect(package_yml.read).to eq original.sub("owner: Old Team", "owner: New Team") end - it 'leaves the package it was called on unchanged' do - package = ParsePackwerk.find('packs/example_pack') + it "leaves the package it was called on unchanged" do + package = ParsePackwerk.find("packs/example_pack") - package.with(owner: 'New Team') + package.with(owner: "New Team") - expect(package.owner).to eq 'Old Team' - expect(ParsePackwerk.find('packs/example_pack').owner).to eq 'Old Team' + expect(package.owner).to eq "Old Team" + expect(ParsePackwerk.find("packs/example_pack").owner).to eq "Old Team" end - it 'rejects an owner that is not a string' do - expect { ParsePackwerk.find('packs/example_pack').with(owner: 123) }.to raise_error(TypeError) + it "rejects an owner that is not a string" do + expect { ParsePackwerk.find("packs/example_pack").with(owner: 123) }.to raise_error(TypeError) end - it 'allows you to remove the owner' do - new_package = ParsePackwerk.find('packs/example_pack').with(owner: nil) + it "allows you to remove the owner" do + new_package = ParsePackwerk.find("packs/example_pack").with(owner: nil) ParsePackwerk.write_package_yml!(new_package) @@ -1314,27 +1327,29 @@ def pack_as_hash(package) PACKAGEYML end - it 'still honours an owner changed directly in config' do - package = ParsePackwerk.find('packs/example_pack') - package.config['owner'] = 'New Team' + it "still honours an owner changed directly in config" do + package = ParsePackwerk.find("packs/example_pack") + package.config["owner"] = "New Team" ParsePackwerk.write_package_yml!(package) - expect(package.owner).to eq 'New Team' - expect(YAML.load_file(package_yml)['owner']).to eq 'New Team' + expect(package.owner).to eq "New Team" + expect(YAML.load_file(package_yml)["owner"]).to eq "New Team" end end end - context 'package with other top-level config' do + context "package with other top-level config" do let(:package) do - build_pack(config: { - 'my_special_key' => { 'blah' => 1 }, - 'my_other_special_key' => true - }) + build_pack( + config: { + "my_special_key" => { "blah" => 1 }, + "my_other_special_key" => true, + } + ) end - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1351,14 +1366,14 @@ def pack_as_hash(package) end end - context 'app does not use extensions' do + context "app does not use extensions" do let(:write_packwerk_yml) do - write_file('packwerk.yml', '{}') + write_file("packwerk.yml", "{}") end let(:package) { build_pack(enforce_privacy: false, enforce_layers: false) } - it 'writes the right package' do + it "writes the right package" do ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML enforce_dependencies: true @@ -1369,12 +1384,12 @@ def pack_as_hash(package) end end - describe 'preserve_key_order option' do + describe "preserve_key_order option" do after do ParsePackwerk.preserve_key_order = false end - context 'when preserve_key_order is false (default)' do + context "when preserve_key_order is false (default)" do before do ParsePackwerk.preserve_key_order = false write_file(package_yml, <<~CONTENTS) @@ -1387,7 +1402,7 @@ def pack_as_hash(package) CONTENTS end - it 'reorders keys according to key_sort_order' do + it "reorders keys according to key_sort_order" do package = ParsePackwerk::Package.from(package_yml) ParsePackwerk.write_package_yml!(package) @@ -1402,7 +1417,7 @@ def pack_as_hash(package) end end - context 'when preserve_key_order is true' do + context "when preserve_key_order is true" do before do ParsePackwerk.preserve_key_order = true write_file(package_yml, <<~CONTENTS) @@ -1415,7 +1430,7 @@ def pack_as_hash(package) CONTENTS end - it 'preserves the original key order from the file' do + it "preserves the original key order from the file" do package = ParsePackwerk::Package.from(package_yml) ParsePackwerk.write_package_yml!(package) @@ -1429,10 +1444,10 @@ def pack_as_hash(package) PACKAGEYML end - it 'appends new keys in canonical order at the end' do + it "appends new keys in canonical order at the end" do package = ParsePackwerk::Package.from(package_yml) # Add metadata which wasn't in the original file - new_package = package.with(metadata: { 'owner' => 'Team A' }) + new_package = package.with(metadata: { "owner" => "Team A" }) ParsePackwerk.write_package_yml!(new_package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1447,9 +1462,9 @@ def pack_as_hash(package) PACKAGEYML end - it 'appends a newly added owner as a new key' do + it "appends a newly added owner as a new key" do package = ParsePackwerk::Package.from(package_yml) - new_package = package.with(owner: 'Team A') + new_package = package.with(owner: "Team A") ParsePackwerk.write_package_yml!(new_package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1463,7 +1478,7 @@ def pack_as_hash(package) PACKAGEYML end - it 'handles removed keys gracefully' do + it "handles removed keys gracefully" do package = ParsePackwerk::Package.from(package_yml) # Remove dependencies new_package = package.with(dependencies: []) @@ -1478,13 +1493,13 @@ def pack_as_hash(package) end end - context 'when preserve_key_order is true but package has no original_key_order' do + context "when preserve_key_order is true but package has no original_key_order" do before do ParsePackwerk.preserve_key_order = true end - it 'falls back to canonical key order for new packages' do - package = build_pack(dependencies: ['packs/foo']) + it "falls back to canonical key order for new packages" do + package = build_pack(dependencies: ["packs/foo"]) ParsePackwerk.write_package_yml!(package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1497,7 +1512,7 @@ def pack_as_hash(package) end end - context 'when package is modified after reading' do + context "when package is modified after reading" do before do ParsePackwerk.preserve_key_order = true write_file(package_yml, <<~CONTENTS) @@ -1510,10 +1525,10 @@ def pack_as_hash(package) CONTENTS end - it 'preserves key order even when dependencies change' do + it "preserves key order even when dependencies change" do package = ParsePackwerk::Package.from(package_yml) # Change dependencies value but keep the key - new_package = package.with(dependencies: ['packs/bar', 'packs/baz']) + new_package = package.with(dependencies: ["packs/bar", "packs/baz"]) ParsePackwerk.write_package_yml!(new_package) expect(package_yml.read).to eq <<~PACKAGEYML @@ -1528,12 +1543,12 @@ def pack_as_hash(package) end end - context 'preserves original key order when reading and writing package' do + context "preserves original key order when reading and writing package" do before do ParsePackwerk.preserve_key_order = true end - it 'stores original_key_order when reading package' do + it "stores original_key_order when reading package" do write_file(package_yml, <<~CONTENTS) enforce_privacy: true layer: admin @@ -1541,7 +1556,7 @@ def pack_as_hash(package) CONTENTS package = ParsePackwerk::Package.from(package_yml) - expect(package.original_key_order).to eq %w[enforce_privacy layer enforce_dependencies] + expect(package.original_key_order).to eq %w(enforce_privacy layer enforce_dependencies) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 36f7b8b..2d4423d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,18 @@ +# typed: false # frozen_string_literal: true -require 'bundler/setup' -require 'parse_packwerk' -require 'pry' -require 'hashdiff' +require "bundler/setup" +require "parse_packwerk" +require "pry" +require "hashdiff" # This improves the rspec diffs which should make debugging easier -require 'awesome_print' +require "awesome_print" -require_relative 'support/have_matching_package' +require_relative "support/have_matching_package" 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! @@ -21,7 +22,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 @@ -31,7 +32,7 @@ end end -def write_file(path, content = '') +def write_file(path, content = "") pathname = Pathname.new(path) FileUtils.mkdir_p(pathname.dirname) pathname.write(content) diff --git a/spec/support/have_matching_package.rb b/spec/support/have_matching_package.rb index 13508a8..4914679 100644 --- a/spec/support/have_matching_package.rb +++ b/spec/support/have_matching_package.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true RSpec::Matchers.define(:have_matching_package) do |expected_package, expected_package_todo| @@ -24,11 +25,20 @@ def hashify_violation(violation) type: violation.type, to_package_name: violation.to_package_name, class_name: violation.to_package_name, - files: violation.files + files: violation.files, } end def deep_hashify_package(package, package_todo) + hashified_package_todo = if package_todo.nil? + {} + else + { + pathname: package_todo.pathname.to_s, + violations: hashify_violations(package_todo.violations), + } + end + { name: package.name, enforce_dependencies: package.enforce_dependencies, @@ -36,14 +46,7 @@ def deep_hashify_package(package, package_todo) owner: package.owner, metadata: package.metadata, dependencies: package.dependencies.sort, - package_todo: if package_todo.nil? - {} - else - { - pathname: package_todo.pathname.to_s, - violations: hashify_violations(package_todo.violations) - } - end + package_todo: hashified_package_todo, } end