From e1da3184e5c6516ebb7254d9c151c36488bcc94f Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Tue, 6 Dec 2022 08:21:06 -0500 Subject: [PATCH] Mark private API as constant --- empty_commit | 0 lib/packwerk.rb | 59 ++++--- lib/packwerk/application_load_paths.rb | 2 + lib/packwerk/application_validator.rb | 30 ++-- lib/packwerk/association_inspector.rb | 2 + lib/packwerk/cache.rb | 3 +- lib/packwerk/cli.rb | 12 +- lib/packwerk/cli/result.rb | 11 ++ lib/packwerk/configuration.rb | 4 +- lib/packwerk/const_node_inspector.rb | 2 + lib/packwerk/constant_discovery.rb | 4 +- lib/packwerk/constant_name_inspector.rb | 2 + lib/packwerk/file_processor.rb | 4 +- lib/packwerk/files_for_processing.rb | 2 + ...atter.rb => default_offenses_formatter.rb} | 6 +- lib/packwerk/generators/configuration_file.rb | 2 +- lib/packwerk/graph.rb | 2 + lib/packwerk/node.rb | 2 + lib/packwerk/node_helpers.rb | 2 + lib/packwerk/node_processor.rb | 2 + lib/packwerk/node_processor_factory.rb | 10 +- lib/packwerk/node_visitor.rb | 2 + lib/packwerk/offense_collection.rb | 2 + lib/packwerk/offenses_formatter.rb | 2 +- lib/packwerk/parse_run.rb | 18 +- lib/packwerk/parsed_constant_definitions.rb | 2 + lib/packwerk/reference_extractor.rb | 4 +- lib/packwerk/result.rb | 9 - lib/packwerk/run_context.rb | 8 +- lib/packwerk/unresolved_reference.rb | 2 + lib/packwerk/validator.rb | 10 +- .../result.rb | 2 +- .../validators/dependency_validator.rb | 20 +-- test/parser_test_helper.rb | 10 +- test/support/application_fixture_helper.rb | 154 +++++++++--------- test/support/factory_helper.rb | 38 +++-- test/support/offenses_formatter_plain.rb | 4 +- .../rails_application_fixture_helper.rb | 2 +- test/unit/application_validator_test.rb | 4 +- test/unit/cache_test.rb | 2 +- test/unit/checker_test.rb | 2 +- test/unit/cli_test.rb | 8 +- test/unit/file_processor_test.rb | 4 +- test/unit/files_for_processing_test.rb | 20 +-- .../generators/configuration_file_test.rb | 8 +- test/unit/generators/root_package_test.rb | 4 +- test/unit/node_visitor_test.rb | 2 +- test/unit/offense_collection_test.rb | 2 +- test/unit/package_todo_test.rb | 18 +- test/unit/parse_run_test.rb | 44 ++--- .../reference_checker_test.rb | 2 +- test/unit/reference_extractor_test.rb | 8 +- 52 files changed, 325 insertions(+), 255 deletions(-) create mode 100644 empty_commit create mode 100644 lib/packwerk/cli/result.rb rename lib/packwerk/formatters/{offenses_formatter.rb => default_offenses_formatter.rb} (92%) delete mode 100644 lib/packwerk/result.rb rename lib/packwerk/{application_validator => validator}/result.rb (90%) diff --git a/empty_commit b/empty_commit new file mode 100644 index 000000000..e69de29bb diff --git a/lib/packwerk.rb b/lib/packwerk.rb index da4033c11..dc33c9a73 100644 --- a/lib/packwerk.rb +++ b/lib/packwerk.rb @@ -13,44 +13,58 @@ module Packwerk extend ActiveSupport::Autoload + # Public APIs + autoload :Checker + autoload :Cli + autoload :Offense + autoload :OffensesFormatter + autoload :OutputStyle + autoload :Package + autoload :PackageSet + autoload :PackageTodo + autoload :Parsers + autoload :Reference + autoload :ReferenceOffense + autoload :Validator + autoload :Version + + # Private APIs + # Please submit an issue if you have a use-case for these autoload :ApplicationLoadPaths autoload :ApplicationValidator autoload :AssociationInspector - autoload :OffenseCollection autoload :Cache - autoload :Checker - autoload :Cli autoload :Configuration autoload :ConstantDiscovery autoload :ConstantNameInspector autoload :ConstNodeInspector - autoload :PackageTodo autoload :ExtensionLoader autoload :FileProcessor autoload :FilesForProcessing autoload :Graph - autoload :Loader autoload :Node autoload :NodeHelpers autoload :NodeProcessor autoload :NodeProcessorFactory autoload :NodeVisitor - autoload :Offense - autoload :OffensesFormatter - autoload :OutputStyle - autoload :Package - autoload :PackageSet + autoload :OffenseCollection autoload :ParsedConstantDefinitions - autoload :Parsers autoload :ParseRun - autoload :UnresolvedReference - autoload :Reference autoload :ReferenceExtractor - autoload :ReferenceOffense - autoload :Result autoload :RunContext - autoload :Validator - autoload :Version + autoload :UnresolvedReference + + module Validator + extend ActiveSupport::Autoload + + autoload :Result + end + + class Cli + extend ActiveSupport::Autoload + + autoload :Result + end module OutputStyles extend ActiveSupport::Autoload @@ -69,6 +83,8 @@ module Formatters autoload :ProgressFormatter end + private_constant :Formatters + module Generators extend ActiveSupport::Autoload @@ -76,6 +92,8 @@ module Generators autoload :RootPackage end + private_constant :Generators + module ReferenceChecking extend ActiveSupport::Autoload @@ -89,17 +107,18 @@ module Checkers end end + private_constant :ReferenceChecking + class ApplicationValidator extend ActiveSupport::Autoload - autoload :Result autoload :Helpers end end -# Required to register the default OffensesFormatter +# Required to register the DefaultOffensesFormatter # We put this at the *end* of the file to specify all autoloads first -require "packwerk/formatters/offenses_formatter" +require "packwerk/formatters/default_offenses_formatter" # Required to register the default DependencyChecker require "packwerk/reference_checking/checkers/dependency_checker" diff --git a/lib/packwerk/application_load_paths.rb b/lib/packwerk/application_load_paths.rb index ec5710e15..d7833390e 100644 --- a/lib/packwerk/application_load_paths.rb +++ b/lib/packwerk/application_load_paths.rb @@ -70,4 +70,6 @@ def assert_load_paths_present(paths) end end end + + private_constant :ApplicationLoadPaths end diff --git a/lib/packwerk/application_validator.rb b/lib/packwerk/application_validator.rb index e92b2bd55..6b5116e7d 100644 --- a/lib/packwerk/application_validator.rb +++ b/lib/packwerk/application_validator.rb @@ -12,13 +12,13 @@ class ApplicationValidator include Validator extend T::Sig - sig { params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) } + sig { params(package_set: PackageSet, configuration: Configuration).returns(Validator::Result) } def check_all(package_set, configuration) results = Validator.all.flat_map { |validator| validator.call(package_set, configuration) } merge_results(results) end - sig { override.params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) } + sig { override.params(package_set: PackageSet, configuration: Configuration).returns(Validator::Result) } def call(package_set, configuration) results = [ check_package_manifest_syntax(configuration), @@ -37,7 +37,7 @@ def permitted_keys ] end - sig { params(configuration: Configuration).returns(Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_package_manifest_syntax(configuration) errors = [] @@ -54,10 +54,10 @@ def check_package_manifest_syntax(configuration) end if errors.empty? - Result.new(ok: true) + Validator::Result.new(ok: true) else merge_results( - errors.map { |error| Result.new(ok: false, error_value: error) }, + errors.map { |error| Validator::Result.new(ok: false, error_value: error) }, separator: "\n", before_errors: "Malformed syntax in the following manifests:\n\n", after_errors: "\n", @@ -65,7 +65,7 @@ def check_package_manifest_syntax(configuration) end end - sig { params(configuration: Configuration).returns(Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_application_structure(configuration) resolver = ConstantResolver.new( root_path: configuration.root_path.to_s, @@ -74,13 +74,13 @@ def check_application_structure(configuration) begin resolver.file_map - Result.new(ok: true) + Validator::Result.new(ok: true) rescue => e - Result.new(ok: false, error_value: e.message) + Validator::Result.new(ok: false, error_value: e.message) end end - sig { params(configuration: Configuration).returns(Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_package_manifest_paths(configuration) all_package_manifests = package_manifests(configuration, "**/") package_paths_package_manifests = package_manifests(configuration, package_glob(configuration)) @@ -88,9 +88,9 @@ def check_package_manifest_paths(configuration) difference = all_package_manifests - package_paths_package_manifests if difference.empty? - Result.new(ok: true) + Validator::Result.new(ok: true) else - Result.new( + Validator::Result.new( ok: false, error_value: <<~EOS Expected package paths for all package.ymls to be specified, but paths were missing for the following manifests: @@ -101,15 +101,15 @@ def check_package_manifest_paths(configuration) end end - sig { params(configuration: Configuration).returns(Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_root_package_exists(configuration) root_package_path = File.join(configuration.root_path, "package.yml") all_packages_manifests = package_manifests(configuration, package_glob(configuration)) if all_packages_manifests.include?(root_package_path) - Result.new(ok: true) + Validator::Result.new(ok: true) else - Result.new( + Validator::Result.new( ok: false, error_value: <<~EOS A root package does not exist. Create an empty `package.yml` at the root directory. @@ -130,4 +130,6 @@ def relative_paths(configuration, paths) paths.map { |path| relative_path(configuration, path) } end end + + private_constant :ApplicationValidator end diff --git a/lib/packwerk/association_inspector.rb b/lib/packwerk/association_inspector.rb index 899ef8499..d2990b9fe 100644 --- a/lib/packwerk/association_inspector.rb +++ b/lib/packwerk/association_inspector.rb @@ -70,4 +70,6 @@ def association_name(arguments) NodeHelpers.literal_value(association_name_node) end end + + private_constant :AssociationInspector end diff --git a/lib/packwerk/cache.rb b/lib/packwerk/cache.rb index fb21ca08e..269c8280a 100644 --- a/lib/packwerk/cache.rb +++ b/lib/packwerk/cache.rb @@ -169,8 +169,9 @@ def out(out) puts(out) end end - end + end end + private_constant :Cache private_constant :Debug end diff --git a/lib/packwerk/cli.rb b/lib/packwerk/cli.rb index 34ac173b7..19efbeea4 100644 --- a/lib/packwerk/cli.rb +++ b/lib/packwerk/cli.rb @@ -14,8 +14,8 @@ class Cli out: T.any(StringIO, IO), err_out: T.any(StringIO, IO), environment: String, - style: Packwerk::OutputStyle, - offenses_formatter: T.nilable(Packwerk::OffensesFormatter) + style: OutputStyle, + offenses_formatter: T.nilable(OffensesFormatter) ).void end def initialize( @@ -77,12 +77,12 @@ def init sig { returns(T::Boolean) } def generate_configs - configuration_file = Packwerk::Generators::ConfigurationFile.generate( + configuration_file = Generators::ConfigurationFile.generate( root: @configuration.root_path, out: @out ) - root_package = Packwerk::Generators::RootPackage.generate(root: @configuration.root_path, out: @out) + root_package = Generators::RootPackage.generate(root: @configuration.root_path, out: @out) success = configuration_file && root_package @@ -159,7 +159,7 @@ def validate(_paths) sig { returns(ApplicationValidator) } def validator - Packwerk::ApplicationValidator.new + ApplicationValidator.new end sig { returns(PackageSet) } @@ -170,7 +170,7 @@ def package_set ) end - sig { params(result: ApplicationValidator::Result).void } + sig { params(result: Validator::Result).void } def list_validation_errors(result) @out.puts if result.ok? diff --git a/lib/packwerk/cli/result.rb b/lib/packwerk/cli/result.rb new file mode 100644 index 000000000..b106820d9 --- /dev/null +++ b/lib/packwerk/cli/result.rb @@ -0,0 +1,11 @@ +# typed: strict +# frozen_string_literal: true + +module Packwerk + class Cli + class Result < T::Struct + const :message, String + const :status, T::Boolean + end + end +end diff --git a/lib/packwerk/configuration.rb b/lib/packwerk/configuration.rb index a1ba82cc2..07853c411 100644 --- a/lib/packwerk/configuration.rb +++ b/lib/packwerk/configuration.rb @@ -51,7 +51,7 @@ def initialize(configs = {}, config_path: nil) @cache_directory = Pathname.new(configs["cache_directory"] || "tmp/cache/packwerk") @config_path = config_path - @offenses_formatter_identifier = configs["offenses_formatter"] || Formatters::OffensesFormatter::IDENTIFIER + @offenses_formatter_identifier = configs["offenses_formatter"] || Formatters::DefaultOffensesFormatter::IDENTIFIER if configs.key?("require") configs["require"].each do |require_directive| @@ -77,4 +77,6 @@ def cache_enabled? @cache_enabled end end + + private_constant :Configuration end diff --git a/lib/packwerk/const_node_inspector.rb b/lib/packwerk/const_node_inspector.rb index eda29168d..8184d0535 100644 --- a/lib/packwerk/const_node_inspector.rb +++ b/lib/packwerk/const_node_inspector.rb @@ -52,4 +52,6 @@ def fully_qualify_constant(ancestors) "::" + NodeHelpers.parent_module_name(ancestors: ancestors) end end + + private_constant :ConstNodeInspector end diff --git a/lib/packwerk/constant_discovery.rb b/lib/packwerk/constant_discovery.rb index 8890b35a9..9f2d4aa2c 100644 --- a/lib/packwerk/constant_discovery.rb +++ b/lib/packwerk/constant_discovery.rb @@ -50,7 +50,7 @@ def package_from_path(path) # @param const_name [String] The unresolved constant's name. # @param current_namespace_path [Array] (optional) The namespace of the context in which the constant is # used, e.g. ["Apps", "Models"] for `Apps::Models`. Defaults to [] which means top level. - # @return [Packwerk::ConstantDiscovery::ConstantContext] + # @return [ConstantDiscovery::ConstantContext] sig do params( const_name: String, @@ -74,4 +74,6 @@ def context_for(const_name, current_namespace_path: []) ) end end + + private_constant :ConstantDiscovery end diff --git a/lib/packwerk/constant_name_inspector.rb b/lib/packwerk/constant_name_inspector.rb index 70d93363d..9acfa959e 100644 --- a/lib/packwerk/constant_name_inspector.rb +++ b/lib/packwerk/constant_name_inspector.rb @@ -18,4 +18,6 @@ module ConstantNameInspector end def constant_name_from_node(node, ancestors:); end end + + private_constant :ConstantNameInspector end diff --git a/lib/packwerk/file_processor.rb b/lib/packwerk/file_processor.rb index 6f9452499..9e8fe5cb9 100644 --- a/lib/packwerk/file_processor.rb +++ b/lib/packwerk/file_processor.rb @@ -64,7 +64,7 @@ def references_from_ast(node, relative_file) references = [] node_processor = @node_processor_factory.for(relative_file: relative_file, node: node) - node_visitor = Packwerk::NodeVisitor.new(node_processor: node_processor) + node_visitor = NodeVisitor.new(node_processor: node_processor) node_visitor.visit(node, ancestors: [], result: references) references @@ -82,4 +82,6 @@ def parser_for(file_path) @parser_factory.for_path(file_path) end end + + private_constant :FileProcessor end diff --git a/lib/packwerk/files_for_processing.rb b/lib/packwerk/files_for_processing.rb index 034f2207a..fa07626a2 100644 --- a/lib/packwerk/files_for_processing.rb +++ b/lib/packwerk/files_for_processing.rb @@ -111,4 +111,6 @@ def relative_files_for_globs(relative_globs) Set.new(relative_globs.flat_map { |glob| Dir[glob] }) end end + + private_constant :FilesForProcessing end diff --git a/lib/packwerk/formatters/offenses_formatter.rb b/lib/packwerk/formatters/default_offenses_formatter.rb similarity index 92% rename from lib/packwerk/formatters/offenses_formatter.rb rename to lib/packwerk/formatters/default_offenses_formatter.rb index e5f331b5e..5fca60a96 100644 --- a/lib/packwerk/formatters/offenses_formatter.rb +++ b/lib/packwerk/formatters/default_offenses_formatter.rb @@ -3,8 +3,8 @@ module Packwerk module Formatters - class OffensesFormatter - include Packwerk::OffensesFormatter + class DefaultOffensesFormatter + include OffensesFormatter IDENTIFIER = T.let("default", String) @@ -20,7 +20,7 @@ def show_offenses(offenses) EOS end - sig { override.params(offense_collection: Packwerk::OffenseCollection, fileset: T::Set[String]).returns(String) } + sig { override.params(offense_collection: OffenseCollection, fileset: T::Set[String]).returns(String) } def show_stale_violations(offense_collection, fileset) if offense_collection.stale_violations?(fileset) "There were stale violations found, please run `packwerk update-todo`" diff --git a/lib/packwerk/generators/configuration_file.rb b/lib/packwerk/generators/configuration_file.rb index 136440202..1f5dd948c 100644 --- a/lib/packwerk/generators/configuration_file.rb +++ b/lib/packwerk/generators/configuration_file.rb @@ -25,7 +25,7 @@ def initialize(root:, out: $stdout) sig { returns(T::Boolean) } def generate @out.puts("📦 Generating Packwerk configuration file...") - default_config_path = File.join(@root, ::Packwerk::Configuration::DEFAULT_CONFIG_PATH) + default_config_path = File.join(@root, Configuration::DEFAULT_CONFIG_PATH) if File.exist?(default_config_path) @out.puts("⚠️ Packwerk configuration file already exists.") diff --git a/lib/packwerk/graph.rb b/lib/packwerk/graph.rb index 7b6af4410..8008deae8 100644 --- a/lib/packwerk/graph.rb +++ b/lib/packwerk/graph.rb @@ -79,4 +79,6 @@ def add_cycle(cycle) @cycles << cycle end end + + private_constant :Graph end diff --git a/lib/packwerk/node.rb b/lib/packwerk/node.rb index 5789486c2..db6111065 100644 --- a/lib/packwerk/node.rb +++ b/lib/packwerk/node.rb @@ -5,4 +5,6 @@ module Packwerk class Node Location = Struct.new(:line, :column) end + + private_constant :Node end diff --git a/lib/packwerk/node_helpers.rb b/lib/packwerk/node_helpers.rb index bc769294f..93d028731 100644 --- a/lib/packwerk/node_helpers.rb +++ b/lib/packwerk/node_helpers.rb @@ -332,4 +332,6 @@ def receiver(method_call_or_block_node) end end end + + private_constant :NodeHelpers end diff --git a/lib/packwerk/node_processor.rb b/lib/packwerk/node_processor.rb index e56a6ad24..d782054ce 100644 --- a/lib/packwerk/node_processor.rb +++ b/lib/packwerk/node_processor.rb @@ -29,4 +29,6 @@ def call(node, ancestors) @reference_extractor.reference_from_node(node, ancestors: ancestors, relative_file: @relative_file) end end + + private_constant :NodeProcessor end diff --git a/lib/packwerk/node_processor_factory.rb b/lib/packwerk/node_processor_factory.rb index 111d0497d..5b1f29f13 100644 --- a/lib/packwerk/node_processor_factory.rb +++ b/lib/packwerk/node_processor_factory.rb @@ -6,12 +6,12 @@ class NodeProcessorFactory < T::Struct extend T::Sig const :root_path, String - const :context_provider, Packwerk::ConstantDiscovery + const :context_provider, ConstantDiscovery const :constant_name_inspectors, T::Array[ConstantNameInspector] sig { params(relative_file: String, node: AST::Node).returns(NodeProcessor) } def for(relative_file:, node:) - ::Packwerk::NodeProcessor.new( + NodeProcessor.new( reference_extractor: reference_extractor(node: node), relative_file: relative_file, ) @@ -19,13 +19,15 @@ def for(relative_file:, node:) private - sig { params(node: AST::Node).returns(::Packwerk::ReferenceExtractor) } + sig { params(node: AST::Node).returns(ReferenceExtractor) } def reference_extractor(node:) - ::Packwerk::ReferenceExtractor.new( + ReferenceExtractor.new( constant_name_inspectors: constant_name_inspectors, root_node: node, root_path: root_path, ) end end + + private_constant :NodeProcessorFactory end diff --git a/lib/packwerk/node_visitor.rb b/lib/packwerk/node_visitor.rb index 4a16faf57..2b9e31b20 100644 --- a/lib/packwerk/node_visitor.rb +++ b/lib/packwerk/node_visitor.rb @@ -21,4 +21,6 @@ def visit(node, ancestors:, result:) end end end + + private_constant :NodeVisitor end diff --git a/lib/packwerk/offense_collection.rb b/lib/packwerk/offense_collection.rb index 38c9a86d3..3511bd70a 100644 --- a/lib/packwerk/offense_collection.rb +++ b/lib/packwerk/offense_collection.rb @@ -120,4 +120,6 @@ def package_todo_file_for(package) File.join(@root_path, package.name, "package_todo.yml") end end + + private_constant :OffenseCollection end diff --git a/lib/packwerk/offenses_formatter.rb b/lib/packwerk/offenses_formatter.rb index 46151c812..ca8e79209 100644 --- a/lib/packwerk/offenses_formatter.rb +++ b/lib/packwerk/offenses_formatter.rb @@ -61,7 +61,7 @@ def formatter_by_identifier(name) def show_offenses(offenses) end - sig { abstract.params(offense_collection: Packwerk::OffenseCollection, for_files: T::Set[String]).returns(String) } + sig { abstract.params(offense_collection: OffenseCollection, for_files: T::Set[String]).returns(String) } def show_stale_violations(offense_collection, for_files) end diff --git a/lib/packwerk/parse_run.rb b/lib/packwerk/parse_run.rb index d72f07335..ebce79b32 100644 --- a/lib/packwerk/parse_run.rb +++ b/lib/packwerk/parse_run.rb @@ -35,17 +35,17 @@ def initialize( @file_set_specified = file_set_specified end - sig { returns(Result) } + sig { returns(Cli::Result) } def update_todo if @file_set_specified message = <<~MSG.squish ⚠️ update-todo must be called without any file arguments. MSG - return Result.new(message: message, status: false) + return Cli::Result.new(message: message, status: false) end - run_context = Packwerk::RunContext.from_configuration(@configuration) + run_context = RunContext.from_configuration(@configuration) offense_collection = find_offenses(run_context) offense_collection.persist_package_todo_files(run_context.package_set) @@ -54,12 +54,12 @@ def update_todo ✅ `package_todo.yml` has been updated. EOS - Result.new(message: message, status: offense_collection.errors.empty?) + Cli::Result.new(message: message, status: offense_collection.errors.empty?) end - sig { returns(Result) } + sig { returns(Cli::Result) } def check - run_context = Packwerk::RunContext.from_configuration(@configuration) + run_context = RunContext.from_configuration(@configuration) offense_collection = find_offenses(run_context, show_errors: true) messages = [ @@ -71,12 +71,12 @@ def check result_status = offense_collection.outstanding_offenses.empty? && !offense_collection.stale_violations?(@relative_file_set) && offense_collection.strict_mode_violations.empty? - Result.new(message: messages.select(&:present?).join("\n") + "\n", status: result_status) + Cli::Result.new(message: messages.select(&:present?).join("\n") + "\n", status: result_status) end private - sig { params(run_context: Packwerk::RunContext, show_errors: T::Boolean).returns(OffenseCollection) } + sig { params(run_context: RunContext, show_errors: T::Boolean).returns(OffenseCollection) } def find_offenses(run_context, show_errors: false) offense_collection = OffenseCollection.new(@configuration.root_path) all_offenses = T.let([], T::Array[Offense]) @@ -123,4 +123,6 @@ def update_progress(failed: false) end end end + + private_constant :ParseRun end diff --git a/lib/packwerk/parsed_constant_definitions.rb b/lib/packwerk/parsed_constant_definitions.rb index 589814a1f..4043d3aea 100644 --- a/lib/packwerk/parsed_constant_definitions.rb +++ b/lib/packwerk/parsed_constant_definitions.rb @@ -61,4 +61,6 @@ def add_definition(constant_name, current_namespace_path, location) @local_definitions[resolved_constant] = location end end + + private_constant :ParsedConstantDefinitions end diff --git a/lib/packwerk/reference_extractor.rb b/lib/packwerk/reference_extractor.rb index 4e97b4aa1..7c90e1d8f 100644 --- a/lib/packwerk/reference_extractor.rb +++ b/lib/packwerk/reference_extractor.rb @@ -51,7 +51,7 @@ def get_fully_qualified_references_from(unresolved_references, context_provider) sig do params( - constant_name_inspectors: T::Array[Packwerk::ConstantNameInspector], + constant_name_inspectors: T::Array[ConstantNameInspector], root_node: ::AST::Node, root_path: String, ).void @@ -125,4 +125,6 @@ def local_reference?(constant_name, name_location, namespace_path) ) end end + + private_constant :ReferenceExtractor end diff --git a/lib/packwerk/result.rb b/lib/packwerk/result.rb deleted file mode 100644 index 48f1ca2a7..000000000 --- a/lib/packwerk/result.rb +++ /dev/null @@ -1,9 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -module Packwerk - class Result < T::Struct - const :message, String - const :status, T::Boolean - end -end diff --git a/lib/packwerk/run_context.rb b/lib/packwerk/run_context.rb index 9fa6d6f6e..8dae554a1 100644 --- a/lib/packwerk/run_context.rb +++ b/lib/packwerk/run_context.rb @@ -109,7 +109,7 @@ def node_processor_factory sig { returns(ConstantDiscovery) } def context_provider - @context_provider ||= ::Packwerk::ConstantDiscovery.new( + @context_provider ||= ConstantDiscovery.new( constant_resolver: resolver, packages: package_set ) @@ -127,9 +127,11 @@ def resolver sig { returns(T::Array[ConstantNameInspector]) } def constant_name_inspectors [ - ::Packwerk::ConstNodeInspector.new, - ::Packwerk::AssociationInspector.new(inflector: @inflector, custom_associations: @custom_associations), + ConstNodeInspector.new, + AssociationInspector.new(inflector: @inflector, custom_associations: @custom_associations), ] end end + + private_constant :RunContext end diff --git a/lib/packwerk/unresolved_reference.rb b/lib/packwerk/unresolved_reference.rb index 3dd99a660..ea778db66 100644 --- a/lib/packwerk/unresolved_reference.rb +++ b/lib/packwerk/unresolved_reference.rb @@ -13,4 +13,6 @@ module Packwerk :source_location, keyword_init: true, ) + + private_constant :UnresolvedReference end diff --git a/lib/packwerk/validator.rb b/lib/packwerk/validator.rb index 307295196..02f07e728 100644 --- a/lib/packwerk/validator.rb +++ b/lib/packwerk/validator.rb @@ -32,7 +32,7 @@ def all def permitted_keys end - sig { abstract.params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) } + sig { abstract.params(package_set: PackageSet, configuration: Configuration).returns(Validator::Result) } def call(package_set, configuration) end @@ -58,19 +58,19 @@ def package_glob(configuration) sig do params( - results: T::Array[ApplicationValidator::Result], + results: T::Array[Validator::Result], separator: String, before_errors: String, after_errors: String, - ).returns(ApplicationValidator::Result) + ).returns(Validator::Result) end def merge_results(results, separator: "\n", before_errors: "", after_errors: "") results.reject!(&:ok?) if results.empty? - ApplicationValidator::Result.new(ok: true) + Validator::Result.new(ok: true) else - ApplicationValidator::Result.new( + Validator::Result.new( ok: false, error_value: [ before_errors, diff --git a/lib/packwerk/application_validator/result.rb b/lib/packwerk/validator/result.rb similarity index 90% rename from lib/packwerk/application_validator/result.rb rename to lib/packwerk/validator/result.rb index d75cb0cb0..96d901476 100644 --- a/lib/packwerk/application_validator/result.rb +++ b/lib/packwerk/validator/result.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true module Packwerk - class ApplicationValidator + module Validator class Result < T::Struct extend T::Sig diff --git a/lib/packwerk/validators/dependency_validator.rb b/lib/packwerk/validators/dependency_validator.rb index 9313e7fc8..7a8137292 100644 --- a/lib/packwerk/validators/dependency_validator.rb +++ b/lib/packwerk/validators/dependency_validator.rb @@ -8,7 +8,7 @@ class DependencyValidator include Validator sig do - override.params(package_set: PackageSet, configuration: Configuration).returns(ApplicationValidator::Result) + override.params(package_set: PackageSet, configuration: Configuration).returns(Validator::Result) end def call(package_set, configuration) results = [ @@ -30,7 +30,7 @@ def permitted_keys private - sig { params(configuration: Configuration).returns(ApplicationValidator::Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_package_manifest_syntax(configuration) errors = [] @@ -51,10 +51,10 @@ def check_package_manifest_syntax(configuration) end if errors.empty? - ApplicationValidator::Result.new(ok: true) + Validator::Result.new(ok: true) else merge_results( - errors.map { |error| ApplicationValidator::Result.new(ok: false, error_value: error) }, + errors.map { |error| Validator::Result.new(ok: false, error_value: error) }, separator: "\n", before_errors: "Malformed syntax in the following manifests:\n\n", after_errors: "\n", @@ -62,7 +62,7 @@ def check_package_manifest_syntax(configuration) end end - sig { params(package_set: PackageSet).returns(ApplicationValidator::Result) } + sig { params(package_set: PackageSet).returns(Validator::Result) } def check_acyclic_graph(package_set) edges = package_set.flat_map do |package| package.dependencies.map do |dependency| @@ -75,9 +75,9 @@ def check_acyclic_graph(package_set) cycle_strings = build_cycle_strings(dependency_graph.cycles) if dependency_graph.acyclic? - ApplicationValidator::Result.new(ok: true) + Validator::Result.new(ok: true) else - ApplicationValidator::Result.new( + Validator::Result.new( ok: false, error_value: <<~EOS Expected the package dependency graph to be acyclic, but it contains the following circular dependencies: @@ -88,7 +88,7 @@ def check_acyclic_graph(package_set) end end - sig { params(configuration: Configuration).returns(ApplicationValidator::Result) } + sig { params(configuration: Configuration).returns(Validator::Result) } def check_valid_package_dependencies(configuration) packages_dependencies = package_manifests_settings_for(configuration, "dependencies") .delete_if { |_, deps| deps.nil? } @@ -104,7 +104,7 @@ def check_valid_package_dependencies(configuration) end if packages_with_invalid_dependencies.empty? - ApplicationValidator::Result.new(ok: true) + Validator::Result.new(ok: true) else error_locations = packages_with_invalid_dependencies.map do |package, invalid_dependencies| package ||= configuration.root_path @@ -117,7 +117,7 @@ def check_valid_package_dependencies(configuration) EOS end - ApplicationValidator::Result.new( + Validator::Result.new( ok: false, error_value: "These dependencies do not point to valid packages:\n\n#{error_locations.join("\n")}" ) diff --git a/test/parser_test_helper.rb b/test/parser_test_helper.rb index e41982d5c..d90423ec2 100644 --- a/test/parser_test_helper.rb +++ b/test/parser_test_helper.rb @@ -1,10 +1,12 @@ # typed: true # frozen_string_literal: true -module ParserTestHelper - class << self - def parse(source) - Packwerk::Parsers::Ruby.new.call(io: StringIO.new(source)) +module Packwerk + module ParserTestHelper + class << self + def parse(source) + Parsers::Ruby.new.call(io: StringIO.new(source)) + end end end end diff --git a/test/support/application_fixture_helper.rb b/test/support/application_fixture_helper.rb index 5cc652a96..bc0f6b96c 100644 --- a/test/support/application_fixture_helper.rb +++ b/test/support/application_fixture_helper.rb @@ -1,104 +1,106 @@ # typed: true # frozen_string_literal: true -module ApplicationFixtureHelper - TEMP_FIXTURE_DIR = ROOT.join("tmp", "fixtures").to_s - DEFAULT_TEMPLATE = :minimal +module Packwerk + module ApplicationFixtureHelper + TEMP_FIXTURE_DIR = ROOT.join("tmp", "fixtures").to_s + DEFAULT_TEMPLATE = :minimal - extend T::Helpers + extend T::Helpers - requires_ancestor { Kernel } + requires_ancestor { Kernel } - def setup_application_fixture - @old_working_dir = Dir.pwd - end + def setup_application_fixture + @old_working_dir = Dir.pwd + end - def remove_extensions - Object.send(:remove_const, :MyLocalExtension) - reset_formatters - end + def remove_extensions + Object.send(:remove_const, :MyLocalExtension) + reset_formatters + end - def reset_formatters - Packwerk::OffensesFormatter.instance_variable_set(:@formatter_by_identifier, nil) - current_formatters = Packwerk::OffensesFormatter.instance_variable_get(:@offenses_formatters) - new_formatters = current_formatters.delete_if { |f| f.new.identifier == "my_offenses_formatter" } - Packwerk::OffensesFormatter.instance_variable_set(:@offenses_formatters, new_formatters) - end + def reset_formatters + Packwerk::OffensesFormatter.instance_variable_set(:@formatter_by_identifier, nil) + current_formatters = Packwerk::OffensesFormatter.instance_variable_get(:@offenses_formatters) + new_formatters = current_formatters.delete_if { |f| f.new.identifier == "my_offenses_formatter" } + Packwerk::OffensesFormatter.instance_variable_set(:@offenses_formatters, new_formatters) + end - def teardown_application_fixture - Dir.chdir(@old_working_dir) - FileUtils.remove_entry(@app_dir, true) if using_template? - end + def teardown_application_fixture + Dir.chdir(@old_working_dir) + FileUtils.remove_entry(@app_dir, true) if using_template? + end - def use_template(template) - raise "use_template may only be called once per test" if using_template? + def use_template(template) + raise "use_template may only be called once per test" if using_template? - copy_dir("test/fixtures/#{template}") - Dir.chdir(app_dir) - end - - def app_dir - unless using_template? - raise "You need to set up an application fixture by calling `use_template(:the_template)`." + copy_dir("test/fixtures/#{template}") + Dir.chdir(app_dir) end - @app_dir - end + def app_dir + unless using_template? + raise "You need to set up an application fixture by calling `use_template(:the_template)`." + end - def config - @config ||= Packwerk::Configuration.from_path(app_dir) - end + @app_dir + end - def package_set - @package_set ||= Packwerk::PackageSet.load_all_from(config.root_path) - end + def config + @config ||= Configuration.from_path(app_dir) + end - def to_app_path(relative_path) - File.join(app_dir, relative_path) - end + def package_set + @package_set ||= Packwerk::PackageSet.load_all_from(config.root_path) + end - def to_app_paths(*relative_paths) - relative_paths.map { |path| to_app_path(path) } - end + def to_app_path(relative_path) + File.join(app_dir, relative_path) + end - def merge_into_app_yaml_file(relative_path, hash) - path = to_app_path(relative_path) - YamlFile.new(path).merge(hash) - end + def to_app_paths(*relative_paths) + relative_paths.map { |path| to_app_path(path) } + end - def remove_app_entry(relative_path) - FileUtils.remove_entry(to_app_path(relative_path)) - end + def merge_into_app_yaml_file(relative_path, hash) + path = to_app_path(relative_path) + YamlFile.new(path).merge(hash) + end - def open_app_file(path, mode: "w+", &block) - expanded_path = to_app_path(File.join(path)) - File.open(expanded_path, mode, &block) - end + def remove_app_entry(relative_path) + FileUtils.remove_entry(to_app_path(relative_path)) + end - # This gets cleaned up by `teardown_application_fixture` - def write_app_file(path, content) - expanded_path = to_app_path(File.join(*path)) - FileUtils.mkdir_p(Pathname.new(expanded_path).dirname) - File.open(expanded_path, "w+") do |file| - file.write(content) - file.flush + def open_app_file(path, mode: "w+", &block) + expanded_path = to_app_path(File.join(path)) + File.open(expanded_path, mode, &block) end - end - private + # This gets cleaned up by `teardown_application_fixture` + def write_app_file(path, content) + expanded_path = to_app_path(File.join(*path)) + FileUtils.mkdir_p(Pathname.new(expanded_path).dirname) + File.open(expanded_path, "w+") do |file| + file.write(content) + file.flush + end + end - def using_template? - defined? @app_dir - end + private - def copy_dir(path) - root = FileUtils.mkdir_p(fixture_path).last - FileUtils.cp_r("#{path}/.", T.must(root)) - @app_dir = root - end + def using_template? + defined? @app_dir + end + + def copy_dir(path) + root = FileUtils.mkdir_p(fixture_path).last + FileUtils.cp_r("#{path}/.", T.must(root)) + @app_dir = root + end - def fixture_path - T.bind(self, Minitest::Runnable) - File.join(TEMP_FIXTURE_DIR, "#{name}-#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}") + def fixture_path + T.bind(self, Minitest::Runnable) + File.join(TEMP_FIXTURE_DIR, "#{name}-#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}") + end end end diff --git a/test/support/factory_helper.rb b/test/support/factory_helper.rb index 6c0568e13..cf50332f8 100644 --- a/test/support/factory_helper.rb +++ b/test/support/factory_helper.rb @@ -1,24 +1,26 @@ # typed: true # frozen_string_literal: true -module FactoryHelper - def build_reference( - source_package: Packwerk::Package.new(name: "components/source", config: {}), - destination_package: Packwerk::Package.new(name: "components/destination", config: {}), - path: "some/path.rb", - constant_name: "::SomeName", - source_location: Packwerk::Node::Location.new(2, 12) - ) - constant = Packwerk::ConstantDiscovery::ConstantContext.new( - constant_name, - "some/location.rb", - destination_package, - ) - Packwerk::Reference.new( - package: source_package, - relative_path: path, - constant: constant, - source_location: source_location, +module Packwerk + module FactoryHelper + def build_reference( + source_package: Packwerk::Package.new(name: "components/source", config: {}), + destination_package: Packwerk::Package.new(name: "components/destination", config: {}), + path: "some/path.rb", + constant_name: "::SomeName", + source_location: Node::Location.new(2, 12) ) + constant = ConstantDiscovery::ConstantContext.new( + constant_name, + "some/location.rb", + destination_package, + ) + Packwerk::Reference.new( + package: source_package, + relative_path: path, + constant: constant, + source_location: source_location, + ) + end end end diff --git a/test/support/offenses_formatter_plain.rb b/test/support/offenses_formatter_plain.rb index 175ba427f..c0bfa915b 100644 --- a/test/support/offenses_formatter_plain.rb +++ b/test/support/offenses_formatter_plain.rb @@ -3,8 +3,8 @@ module Packwerk module Formatters - class OffensesFormatterPlain < OffensesFormatter - include Packwerk::OffensesFormatter + class OffensesFormatterPlain < DefaultOffensesFormatter + include OffensesFormatter IDENTIFIER = T.let("plain", String) extend T::Sig diff --git a/test/support/rails_application_fixture_helper.rb b/test/support/rails_application_fixture_helper.rb index 8f2914720..0d36bca52 100644 --- a/test/support/rails_application_fixture_helper.rb +++ b/test/support/rails_application_fixture_helper.rb @@ -5,7 +5,7 @@ require "zeitwerk" module RailsApplicationFixtureHelper - include ApplicationFixtureHelper + include Packwerk::ApplicationFixtureHelper class Autoloaders include Enumerable diff --git a/test/unit/application_validator_test.rb b/test/unit/application_validator_test.rb index 3878f5d8c..998d4bf9e 100644 --- a/test/unit/application_validator_test.rb +++ b/test/unit/application_validator_test.rb @@ -73,9 +73,9 @@ class ApplicationValidatorTest < Minitest::Test private - sig { returns(Packwerk::ApplicationValidator) } + sig { returns(ApplicationValidator) } def validator - @application_validator ||= Packwerk::ApplicationValidator.new + @application_validator ||= ApplicationValidator.new end end end diff --git a/test/unit/cache_test.rb b/test/unit/cache_test.rb index 79c168809..8cc4bbe85 100644 --- a/test/unit/cache_test.rb +++ b/test/unit/cache_test.rb @@ -43,7 +43,7 @@ class CacheTest < Minitest::Test configuration = Configuration.from_path configuration.stubs(cache_enabled?: true) - parse_run = Packwerk::ParseRun.new(relative_file_set: Set.new([filepath.to_s]), configuration: configuration) + parse_run = ParseRun.new(relative_file_set: Set.new([filepath.to_s]), configuration: configuration) parse_run.update_todo parse_run.update_todo diff --git a/test/unit/checker_test.rb b/test/unit/checker_test.rb index 971a6c5c6..1d5ab8e03 100644 --- a/test/unit/checker_test.rb +++ b/test/unit/checker_test.rb @@ -7,7 +7,7 @@ module Packwerk class CheckerTest < Minitest::Test test "#find is correctly able to find the right checker" do found_checker = Checker.find("dependency") - assert T.unsafe(found_checker).is_a?(Packwerk::ReferenceChecking::Checkers::DependencyChecker) + assert T.unsafe(found_checker).is_a?(ReferenceChecking::Checkers::DependencyChecker) end end end diff --git a/test/unit/cli_test.rb b/test/unit/cli_test.rb index cea1e4c9e..9fc35faf6 100644 --- a/test/unit/cli_test.rb +++ b/test/unit/cli_test.rb @@ -95,8 +95,8 @@ class CliTest < Minitest::Test string_io = StringIO.new cli = ::Packwerk::Cli.new(out: string_io) - validator = typed_mock(check_all: ApplicationValidator::Result.new(ok: true)) - Packwerk::ApplicationValidator.expects(:new).returns(validator) + validator = typed_mock(check_all: Validator::Result.new(ok: true)) + ApplicationValidator.expects(:new).returns(validator) success = cli.execute_command(["validate"]) @@ -109,8 +109,8 @@ class CliTest < Minitest::Test string_io = StringIO.new cli = ::Packwerk::Cli.new(out: string_io) - validator = typed_mock(check_all: ApplicationValidator::Result.new(ok: false, error_value: "I'm an error")) - Packwerk::ApplicationValidator.expects(:new).returns(validator) + validator = typed_mock(check_all: Validator::Result.new(ok: false, error_value: "I'm an error")) + ApplicationValidator.expects(:new).returns(validator) success = cli.execute_command(["validate"]) diff --git a/test/unit/file_processor_test.rb b/test/unit/file_processor_test.rb index 570bef7f9..931a0bb7d 100644 --- a/test/unit/file_processor_test.rb +++ b/test/unit/file_processor_test.rb @@ -16,7 +16,7 @@ class FileProcessorTest < Minitest::Test cache_directory: Pathname.new("tmp/cache/packwerk"), config_path: "packwerk.yml" ) - @file_processor = ::Packwerk::FileProcessor.new(node_processor_factory: @node_processor_factory, cache: @cache) + @file_processor = FileProcessor.new(node_processor_factory: @node_processor_factory, cache: @cache) end test "#call visits all nodes in a file path with no references" do @@ -100,7 +100,7 @@ class FileProcessorTest < Minitest::Test test "#call with an invalid syntax doesn't parse node" do @node_processor_factory.expects(:for).never - file_processor = ::Packwerk::FileProcessor.new( + file_processor = FileProcessor.new( node_processor_factory: @node_processor_factory, cache: Cache.new( enable_cache: false, diff --git a/test/unit/files_for_processing_test.rb b/test/unit/files_for_processing_test.rb index f21f4df48..8972d4ef7 100644 --- a/test/unit/files_for_processing_test.rb +++ b/test/unit/files_for_processing_test.rb @@ -11,7 +11,7 @@ class FilesForProcessingTest < Minitest::Test setup_application_fixture use_template(:skeleton) @package_path = "components/sales" - @configuration = ::Packwerk::Configuration.from_path + @configuration = Configuration.from_path end teardown do @@ -19,7 +19,7 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with custom paths includes only include glob in custom paths" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: [@package_path], configuration: @configuration, ).files @@ -28,7 +28,7 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with custom paths excludes the exclude glob in custom paths" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: [@package_path], configuration: @configuration ).files @@ -38,25 +38,25 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with no custom paths includes only include glob across codebase" do - files = ::Packwerk::FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files + files = FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files assert_all_match(files, @configuration.include) end test "fetch with no custom paths excludes the exclude glob across codebase" do - files = ::Packwerk::FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files + files = FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files excluded_file_patterns = @configuration.exclude.map { |pattern| File.join(@configuration.root_path, pattern) } refute_any_match(files, Set.new(excluded_file_patterns)) end test "fetch does not return duplicated file paths" do - files = ::Packwerk::FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files + files = FilesForProcessing.fetch(relative_file_paths: [], configuration: @configuration).files assert_equal files, Set.new(files) end test "fetch with custom paths without ignoring nested packages includes only include glob in custom paths including nested package files" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: ["."], configuration: @configuration, ignore_nested_packages: false @@ -66,7 +66,7 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with no custom paths ignoring nested packages includes only include glob across codebase" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: [], configuration: @configuration, ignore_nested_packages: true @@ -76,7 +76,7 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with custom paths ignoring nested packages includes only include glob in custom paths without nested package files" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: ["."], configuration: @configuration, ignore_nested_packages: true @@ -87,7 +87,7 @@ class FilesForProcessingTest < Minitest::Test end test "fetch with custom paths for files includes only include glob in custom paths" do - files = ::Packwerk::FilesForProcessing.fetch( + files = FilesForProcessing.fetch( relative_file_paths: [ "components/sales/app/models/order.rb", "components/sales/app/views/order.html.erb", diff --git a/test/unit/generators/configuration_file_test.rb b/test/unit/generators/configuration_file_test.rb index d31dee7bf..470a906eb 100644 --- a/test/unit/generators/configuration_file_test.rb +++ b/test/unit/generators/configuration_file_test.rb @@ -16,15 +16,15 @@ class ConfigurationFileTest < Minitest::Test end test ".generate creates a default configuration file if there were empty load paths array" do - generated_file_path = File.join(@temp_dir, Packwerk::Configuration::DEFAULT_CONFIG_PATH) - assert(Packwerk::Generators::ConfigurationFile.generate(root: @temp_dir, out: @string_io)) + generated_file_path = File.join(@temp_dir, Configuration::DEFAULT_CONFIG_PATH) + assert(Generators::ConfigurationFile.generate(root: @temp_dir, out: @string_io)) assert(File.exist?(generated_file_path)) end test ".generate does not create a configuration file if a file exists" do - file_path = File.join(@temp_dir, Packwerk::Configuration::DEFAULT_CONFIG_PATH) + file_path = File.join(@temp_dir, Configuration::DEFAULT_CONFIG_PATH) File.open(file_path, "w") do |_f| - assert(Packwerk::Generators::ConfigurationFile.generate( + assert(Generators::ConfigurationFile.generate( root: @temp_dir, out: @string_io )) diff --git a/test/unit/generators/root_package_test.rb b/test/unit/generators/root_package_test.rb index c1ce57c7c..af4aae126 100644 --- a/test/unit/generators/root_package_test.rb +++ b/test/unit/generators/root_package_test.rb @@ -17,7 +17,7 @@ class RootPackageTest < Minitest::Test end test ".generate creates a package.yml file" do - success = Packwerk::Generators::RootPackage.generate(root: @temp_dir, out: @string_io) + success = Generators::RootPackage.generate(root: @temp_dir, out: @string_io) assert(File.exist?(@generated_file_path)) assert success assert_includes @string_io.string, "root package generated" @@ -25,7 +25,7 @@ class RootPackageTest < Minitest::Test test ".generate does not create a package.yml file if package.yml already exists" do File.open(File.join(@temp_dir, "package.yml"), "w") do |_f| - success = Packwerk::Generators::RootPackage.generate(root: @temp_dir, out: @string_io) + success = Generators::RootPackage.generate(root: @temp_dir, out: @string_io) assert success assert_includes @string_io.string, "Root package already exists" end diff --git a/test/unit/node_visitor_test.rb b/test/unit/node_visitor_test.rb index ccad4e6ee..637fa8de5 100644 --- a/test/unit/node_visitor_test.rb +++ b/test/unit/node_visitor_test.rb @@ -11,7 +11,7 @@ class NodeVisitorTest < Minitest::Test test "#visit visits the correct number of nodes" do node_processor = typed_mock node_processor.expects(:call).times(3).returns(["an offense"]) - file_node_visitor = Packwerk::NodeVisitor.new(node_processor: node_processor) + file_node_visitor = NodeVisitor.new(node_processor: node_processor) node = ParserTestHelper.parse("class Hello; world; end") result = [] diff --git a/test/unit/offense_collection_test.rb b/test/unit/offense_collection_test.rb index fdfbe38b0..ae0dc2256 100644 --- a/test/unit/offense_collection_test.rb +++ b/test/unit/offense_collection_test.rb @@ -51,7 +51,7 @@ class OffenseCollectionTest < Minitest::Test package_todo = Packwerk::PackageTodo.new(package, ".") package_todo .stubs(:listed?) - .with(reference, violation_type: Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + .with(reference, violation_type: ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) .returns(true) Packwerk::PackageTodo .stubs(:new) diff --git a/test/unit/package_todo_test.rb b/test/unit/package_todo_test.rb index 994772eff..36a7107ad 100644 --- a/test/unit/package_todo_test.rb +++ b/test/unit/package_todo_test.rb @@ -91,9 +91,9 @@ class PackageTodoTest < Minitest::Test package_todo = PackageTodo.new(package, "test/fixtures/package_todo.yml") package_todo.add_entries(first_violated_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(second_violated_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) assert package_todo.stale_violations?(Set.new([ "orders/app/jobs/orders/sweepers/purge_old_document_rows_task.rb", "orders/app/models/orders/services/adjustment_engine.rb", @@ -152,7 +152,7 @@ class PackageTodoTest < Minitest::Test package_todo = PackageTodo.new(reference.constant.package, file.path) package_todo.add_entries(reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.dump expected_output = { @@ -206,17 +206,17 @@ class PackageTodoTest < Minitest::Test ) package_todo.add_entries(second_package_first_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(second_package_first_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(second_package_second_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(second_package_second_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(second_package_third_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.add_entries(first_package_reference, - Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) + ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE) package_todo.dump diff --git a/test/unit/parse_run_test.rb b/test/unit/parse_run_test.rb index 2c8a21c5e..391498fc6 100644 --- a/test/unit/parse_run_test.rb +++ b/test/unit/parse_run_test.rb @@ -22,7 +22,7 @@ class ParseRunTest < Minitest::Test RunContext.any_instance.stubs(:process_file).returns([]) OffenseCollection.any_instance.expects(:dump_package_todo_files).once - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["path/of/exile.rb"]), configuration: Configuration.from_path ) @@ -41,7 +41,7 @@ class ParseRunTest < Minitest::Test RunContext.any_instance.stubs(:process_file).returns([offense]) OffenseCollection.any_instance.expects(:dump_package_todo_files).once - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["path/of/exile.rb"]), configuration: Configuration.from_path ) @@ -62,7 +62,7 @@ class ParseRunTest < Minitest::Test test "#update-todo returns exit code 1 when ran with file args" do use_template(:minimal) - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["path/of/exile.rb"]), file_set_specified: true, configuration: Configuration.from_path @@ -106,7 +106,7 @@ def something - a/b/c.rb YML - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["app/models/my_model.rb", "components/sales/app/models/order.rb"]), configuration: Configuration.from_path ) @@ -133,10 +133,10 @@ def something PackageTodo.any_instance.stubs(:listed?).returns(true) out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["some/path.rb"]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) RunContext.any_instance.stubs(:process_file).returns([offense]) result = parse_run.check @@ -210,10 +210,10 @@ def something ) out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new([file_to_check]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) RunContext.any_instance.stubs(:process_file).returns([offense1, offense2]) result = parse_run.check @@ -256,10 +256,10 @@ def something YML out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new([file_to_check]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) RunContext.any_instance.stubs(:process_file).returns([]) result = parse_run.check @@ -303,16 +303,16 @@ def something YML out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new([file_to_check]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) offense = ReferenceOffense.new( reference: build_reference(path: file_to_check), message: "some message", - violation_type: Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE + violation_type: ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE ) RunContext.any_instance.stubs(:process_file).returns([offense]) @@ -350,16 +350,16 @@ def something YML out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["components/source/some/path.rb"]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) offense = ReferenceOffense.new( reference: build_reference(path: "components/source/some/path.rb", source_package: source_package), message: "some message", - violation_type: Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE + violation_type: ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE ) RunContext.any_instance.stubs(:process_file).returns([offense]) @@ -406,16 +406,16 @@ def something out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new([file_to_check]), configuration: Configuration.new({ "parallel" => false, "offenses_formatter" => "plain" }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) offense = ReferenceOffense.new( reference: build_reference(path: file_to_check), message: "some message", - violation_type: Packwerk::ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE + violation_type: ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE ) RunContext.any_instance.stubs(:process_file).returns([offense]) @@ -454,10 +454,10 @@ def something PackageTodo.any_instance.stubs(:listed?).returns(true) OffenseCollection.any_instance.stubs(:stale_violations?).returns(true) out = StringIO.new - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["some/path.rb"]), configuration: Configuration.new({ "parallel" => false }), - progress_formatter: Packwerk::Formatters::ProgressFormatter.new(out) + progress_formatter: Formatters::ProgressFormatter.new(out) ) RunContext.any_instance.stubs(:process_file).returns([offense]) result = parse_run.check @@ -491,7 +491,7 @@ def something message: "some message", violation_type: ReferenceChecking::Checkers::DependencyChecker::VIOLATION_TYPE ) - parse_run = Packwerk::ParseRun.new( + parse_run = ParseRun.new( relative_file_set: Set.new(["some/path.rb", "some/other_path.rb"]), configuration: Configuration.new ) diff --git a/test/unit/reference_checking/reference_checker_test.rb b/test/unit/reference_checking/reference_checker_test.rb index 7342a3a61..c0339f579 100644 --- a/test/unit/reference_checking/reference_checker_test.rb +++ b/test/unit/reference_checking/reference_checker_test.rb @@ -52,7 +52,7 @@ def strict_mode_violation?(_listed_offense) end def reference_checker(checkers = [StubChecker.new]) - Packwerk::ReferenceChecking::ReferenceChecker.new(checkers) + ReferenceChecking::ReferenceChecker.new(checkers) end end end diff --git a/test/unit/reference_extractor_test.rb b/test/unit/reference_extractor_test.rb index 028c83c4e..20bcbcff2 100644 --- a/test/unit/reference_extractor_test.rb +++ b/test/unit/reference_extractor_test.rb @@ -20,7 +20,7 @@ def setup resolver = ConstantResolver.new(root_path: app_dir, load_paths: load_paths) packages = ::Packwerk::PackageSet.load_all_from(app_dir) - @context_provider = ::Packwerk::ConstantDiscovery.new( + @context_provider = ConstantDiscovery.new( constant_resolver: resolver, packages: packages ) @@ -214,7 +214,7 @@ def teardown private class DummyAssociationInspector - include Packwerk::ConstantNameInspector + include ConstantNameInspector def initialize(association: false, reference_name: "Dummy", expected_args: nil) @association = association @@ -241,7 +241,7 @@ def process(code, file_path, constant_name_inspectors = DEFAULT_INSPECTORS) root_node = ParserTestHelper.parse(code) file_path = to_app_path(file_path) - extractor = ::Packwerk::ReferenceExtractor.new( + extractor = ReferenceExtractor.new( constant_name_inspectors: constant_name_inspectors, root_node: root_node, root_path: app_dir @@ -254,7 +254,7 @@ def process(code, file_path, constant_name_inspectors = DEFAULT_INSPECTORS) file_path: Pathname.new(file_path).relative_path_from(app_dir).to_s ) - ::Packwerk::ReferenceExtractor.get_fully_qualified_references_from( + ReferenceExtractor.get_fully_qualified_references_from( unresolved_references, @context_provider )