diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..130824c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,35 @@ +inherit_from: .rubocop_todo.yml + +inherit_mode: + merge: + - Exclude + - Include + +inherit_gem: + rubocop-gusto: + - config/default.yml + +plugins: + - rubocop-gusto + +AllCops: + NewCops: enable + SuggestExtensions: false + TargetRubyVersion: 3.3 + Exclude: + - bin/**/* + - vendor/bundle/**/** + +Gemspec/DevelopmentDependencies: + Enabled: true + EnforcedStyle: gemspec + +Gemspec/RequireMFA: + Enabled: false + +RSpec/NotToNot: + Enabled: true + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..738dcae --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,168 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 10000` +# on 2026-11-30 21:06:59 UTC using RuboCop version 1.93.0. +# 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 +# Configuration parameters: EnforcedStyle, AllowedGems. +# SupportedStyles: Gemfile, gems.rb, gemspec +Gemspec/DevelopmentDependencies: + Exclude: + - 'spec/sample_app1/Gemfile' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Gusto/RegexpBypass: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: RequireParenthesesForMethodChains. +Lint/AmbiguousRange: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/UselessAssignment: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 4 +# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns, ForbiddenIdentifiers, ForbiddenPatterns. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/InefficientHashSearch: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/MapCompact: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 33 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 3 +RSpec/LeakyLocalVariable: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: SuggestedStrictness. +Sorbet/FalseSigil: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SuggestedStrictness. +Sorbet/StrictSigil: + Exclude: + - 'd3_graph_generator/parse_packwerk_integration.rb' + - 'sorbet/tapioca/require.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +Style/AutoResourceCleanup: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnConstant, AllowOnSelfClass. +Style/CaseEquality: + Exclude: + - 'd3_graph_generator/parse_packwerk_integration.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/DigChain: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 1 +Style/FileOpen: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 5 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'd3_graph_generator/parse_packwerk_integration.rb' + - 'spec/sample_app1/Gemfile' + - 'visualize_packs.gemspec' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowedReceivers. +# AllowedReceivers: Thread.current +Style/HashEachMethods: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 2 +# Configuration parameters: AllowedClasses. +Style/OneClassPerFile: + Exclude: + - 'lib/visualize_packs/options.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/ReduceToHash: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Methods. +Style/RedundantArgument: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/RedundantInterpolation: + Exclude: + - 'spec/visualize_packs_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/visualize_packs.rb' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. +# AllowedMethods: define_method +Style/SymbolProc: + Exclude: + - 'lib/visualize_packs.rb' diff --git a/Gemfile b/Gemfile index 9e9ddcc..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec - diff --git a/Gemfile.lock b/Gemfile.lock index 979ec83..f49d907 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,10 +10,16 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.4.3) benchmark (0.5.0) bigdecimal (4.1.3) + code_teams (1.3.1) + sorbet-runtime diff-lcs (1.6.2) erubi (1.13.1) + json (3.2.0) + language_server-protocol (3.17.0.6) + lint_roller (1.1.0) logger (1.7.0) netrc (0.11.0) packs-specification (0.0.11) @@ -22,7 +28,12 @@ GEM parse_packwerk (0.28.0) bigdecimal sorbet-runtime + parser (3.3.14.0) + ast (~> 2.4.1) + racc prism (1.9.0) + racc (1.8.1) + rainbow (3.1.1) rbi (0.4.3) prism (~> 1.0) rbs (>= 4.0.1) @@ -30,6 +41,7 @@ GEM logger prism (>= 1.6.0) tsort + regexp_parser (2.13.4) require-hooks (0.5.1) rexml (3.4.4) rspec (3.13.2) @@ -45,10 +57,53 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.7) + rubocop (1.93.0) + json (>= 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (>= 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.11.3, < 3.0) + rubocop-ast (>= 1.54.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.54.0) + ast (~> 2.4) + parser (>= 3.3.7.2) + prism (>= 1.7) + racc + 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-aarch64-linux) 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.13594) sorbet-static (= 0.6.13594) sorbet-runtime (0.6.13594) @@ -80,6 +135,9 @@ GEM tsort thor (1.5.0) tsort (0.2.0) + unicode-display_width (3.3.0) + unicode-emoji (~> 4.3) + unicode-emoji (4.3.0) PLATFORMS aarch64-linux @@ -89,6 +147,7 @@ PLATFORMS DEPENDENCIES bundler rspec (~> 3.12) + rubocop-gusto sorbet tapioca visualize_packs! diff --git a/Rakefile b/Rakefile index 806deab..a994466 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # typed: ignore -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/d3_graph_generator/parse_packwerk_integration.rb b/d3_graph_generator/parse_packwerk_integration.rb index 59a5183..145d5e7 100644 --- a/d3_graph_generator/parse_packwerk_integration.rb +++ b/d3_graph_generator/parse_packwerk_integration.rb @@ -1,36 +1,38 @@ -require 'bundler/inline' -require 'json' +# typed: false + +require "bundler/inline" +require "json" gemfile do - source 'https://rubygems.org' - gem 'parse_packwerk' - gem 'pry' + source "https://rubygems.org" + gem "parse_packwerk" + gem "pry" end d3_json = nil -Dir.chdir(ENV['RELATIVE_PATH_TO_REPOSITORY']) do +Dir.chdir(ENV.fetch("RELATIVE_PATH_TO_REPOSITORY", nil)) do d3_json = { - "nodes" => ParsePackwerk.all.reject {|package| package.name === "."}.map do |package| + "nodes" => ParsePackwerk.all.reject { |package| package.name === "." }.map do |package| readme_link = package.directory.join("README.md") readme = readme_link.exist? ? readme_link : nil { "id" => package.name, "group" => package.dependencies.length, "metadata" => { - "README" => "https://github.com/#{ENV['GITHUB_REPO_SLUG']}/blob/main/#{readme}" - } + "README" => "https://github.com/#{ENV.fetch('GITHUB_REPO_SLUG', nil)}/blob/main/#{readme}", + }, } end, - "links" => ParsePackwerk.all.reject {|package| package.name === "."}.flat_map do |package| - package.dependencies.reject { |d| d == '.' }.map do |dependency| + "links" => ParsePackwerk.all.reject { |package| package.name === "." }.flat_map do |package| + package.dependencies.reject { |d| d == "." }.map do |dependency| { "source" => package.name, "target" => dependency, - "value" => 1 + "value" => 1, } end - end + end, } end -Pathname('src/utilities/packwerk_graph.json').write(d3_json.to_json) +Pathname("src/utilities/packwerk_graph.json").write(d3_json.to_json) diff --git a/lib/visualize_packs.rb b/lib/visualize_packs.rb index db5d536..6dd4716 100644 --- a/lib/visualize_packs.rb +++ b/lib/visualize_packs.rb @@ -1,27 +1,27 @@ -# frozen_string_literal: true # typed: strict +# frozen_string_literal: true -require 'erb' -require 'packs-specification' -require 'parse_packwerk' -require 'digest/md5' +require "erb" +require "packs-specification" +require "parse_packwerk" +require "digest/md5" -require 'visualize_packs/options' -require 'visualize_packs/options_parser' +require "visualize_packs/options" +require "visualize_packs/options_parser" module VisualizePacks extend T::Sig class ArrowHead < T::Enum enums do - DependencyTodo = new('color=darkred style=dashed arrowhead=odiamond') - PrivacyTodo = new('color=darkred style=dashed arrowhead=crow') - LayerTodo = new('color=darkred style=dashed arrowhead=obox') - VisibilityTodo = new('color=darkred style=dashed arrowhead=tee') - FolderVisibilityTodo = new('color=darkred style=dashed arrowhead=odot') - ConfiguredDependency = new('color=darkgreen') - ConfiguredVisibleTo = new('color=blue') - ConfiguredNested = new('color=purple') + DependencyTodo = new("color=darkred style=dashed arrowhead=odiamond") + PrivacyTodo = new("color=darkred style=dashed arrowhead=crow") + LayerTodo = new("color=darkred style=dashed arrowhead=obox") + VisibilityTodo = new("color=darkred style=dashed arrowhead=tee") + FolderVisibilityTodo = new("color=darkred style=dashed arrowhead=odot") + ConfiguredDependency = new("color=darkgreen") + ConfiguredVisibleTo = new("color=blue") + ConfiguredNested = new("color=purple") end end @@ -29,43 +29,39 @@ class ArrowHead < T::Enum def self.package_graph!(args, raw_config, packages) options = OptionsParser.parse(args) - all_packages = filtered(packages, options).compact.sort_by {|x| x.name } + all_packages = filtered(packages, options).compact.sort_by { |x| x.name } all_packages = remove_nested_packs(all_packages, options) all_package_names = all_packages.map &:name show_edge = show_edge_builder(options, all_package_names) - node_color = node_color_builder() - node_protection = package_based_todos_text_maker() + node_color = node_color_builder + node_protection = package_based_todos_text_maker max_todo_count = max_todo_count(all_packages, show_edge, options) title = diagram_title(args, options, max_todo_count) - layers = (raw_config['layers'] || []) + ["NotInLayer"] - grouped_packages = layers.inject({}) do |result, key| + layers = (raw_config["layers"] || []) + ["NotInLayer"] + grouped_packages = layers.each_with_object({}) do |key, result| result[key] = [] - result end all_packages.each do |package| - key = package.config['layer'] || "NotInLayer" + key = package.config["layer"] || "NotInLayer" if layers.include?(key) grouped_packages[key] << package else - raise RuntimeError, "Package #{package.name} has layer key #{key}. Known layers are only #{layers.join(", ")}" + raise "Package #{package.name} has layer key #{key}. Known layers are only #{layers.join(', ')}" end end - all_team_names = all_packages.map { |p| code_owner(p) }.uniq - file = File.open(File.expand_path File.dirname(__FILE__) + "/graph.dot.erb") + file = File.open(File.expand_path(File.dirname(__FILE__) + "/graph.dot.erb")) templ = file.read.gsub(/^ *(<%.+%>) *$/, '\1') template = ERB.new(templ, trim_mode: "<>-") template.result(binding) end - private - sig { params(package: ParsePackwerk::Package).returns(T.nilable(String)) } def self.code_owner(package) package.config.dig("metadata", "owner") || package.config["owner"] @@ -76,7 +72,7 @@ def self.diagram_title(args, options, max_todo_count) return "<#{options.title}>" if options.title sub_title1_length = 0 - options_to_display = args.inject('') do |result, item| + options_to_display = args.inject("") do |result, item| sub_title1_length += item.length if sub_title1_length > 90 sub_title1_length = 0 @@ -88,11 +84,10 @@ def self.diagram_title(args, options, max_todo_count) end sub_title1 = "
#{options_to_display}" - - focus_info = if options.focus_pack - "Focus on #{limited_sentence(options.focus_pack)} (Edge mode: #{options.show_only_edges_to_focus_pack.serialize})" + if options.focus_pack + focus_info = "Focus on #{limited_sentence(options.focus_pack)} (Edge mode: #{options.show_only_edges_to_focus_pack.serialize})" else - "All packs" + focus_info = "All packs" end hidden_aspects = [ @@ -106,17 +101,22 @@ def self.diagram_title(args, options, max_todo_count) options.show_visibility ? nil : "visibility", options.roll_nested_into_parent_packs ? "nested packs" : nil, options.show_nested_relationships ? nil : "nested relationships", - ].compact.join(', ').strip - hidden_aspects_title = hidden_aspects != '' ? "Hiding #{hidden_aspects}" : nil + ].compact.join(", ").strip + hidden_aspects_title = hidden_aspects == "" ? nil : "Hiding #{hidden_aspects}" - todo_types = EdgeTodoTypes.values.size == options.relationship_todo_types.size ? nil : "Only #{options.relationship_todo_types.map &:serialize} todos", + todo_types = + EdgeTodoTypes.values.size == options.relationship_todo_types.size ? nil : "Only #{options.relationship_todo_types.map &:serialize} todos", - exclusions = options.exclude_packs.empty? ? nil : "Excluding pack#{options.exclude_packs.size > 1 ? 's' : ''}: #{limited_sentence(options.exclude_packs)}", + exclusions = if options.exclude_packs.empty? + nil + else + "Excluding pack#{'s' if options.exclude_packs.size > 1}: #{limited_sentence(options.exclude_packs)}" + end, - main_title = [focus_info, hidden_aspects_title, todo_types, exclusions].compact.join('. ') + main_title = [focus_info, hidden_aspects_title, todo_types, exclusions].compact.join(". ") if options.show_relationship_todos && max_todo_count - sub_title2 = "
Widest todo edge is #{max_todo_count} todo#{max_todo_count > 1 ? 's' : ''}" + sub_title2 = "
Widest todo edge is #{max_todo_count} todo#{'s' if max_todo_count > 1}" end "<#{main_title}#{sub_title1}#{sub_title2}>" end @@ -128,41 +128,42 @@ def self.limited_sentence(list) if list.size <= 2 list.join(" and ") else - "#{T.must(list[0, 2]).join(", ")}, and #{list.size - 2} more" + "#{T.must(list[0, 2]).join(', ')}, and #{list.size - 2} more" end end sig { params(options: Options, all_package_names: T::Array[String]).returns(T.proc.params(arg0: String, arg1: String).returns(T::Boolean)) } def self.show_edge_builder(options, all_package_names) - return lambda do |start_node, end_node| + -> (start_node, end_node) do all_package_names.include?(start_node) && - all_package_names.include?(end_node) && - ( - case options.show_only_edges_to_focus_pack - when FocusPackEdgeDirection::All then - true - when FocusPackEdgeDirection::None then - match_packs?(start_node, options.focus_pack) && match_packs?(end_node, options.focus_pack) - when FocusPackEdgeDirection::InOut then - match_packs?(start_node, options.focus_pack) || match_packs?(end_node, options.focus_pack) - when FocusPackEdgeDirection::In then - match_packs?(end_node, options.focus_pack) - when FocusPackEdgeDirection::Out then - match_packs?(start_node, options.focus_pack) - end - ) + all_package_names.include?(end_node) && + ( + case options.show_only_edges_to_focus_pack + when FocusPackEdgeDirection::All + true + when FocusPackEdgeDirection::None + match_packs?(start_node, options.focus_pack) && match_packs?(end_node, options.focus_pack) + when FocusPackEdgeDirection::InOut + match_packs?(start_node, options.focus_pack) || match_packs?(end_node, options.focus_pack) + when FocusPackEdgeDirection::In + match_packs?(end_node, options.focus_pack) + when FocusPackEdgeDirection::Out + match_packs?(start_node, options.focus_pack) + end + ) end end - sig { returns(T.nilable(T.proc.params(arg0: String).returns(String))) } + sig { returns(T.nilable(T.proc.params(arg0: T.nilable(String)).returns(T.nilable(String)))) } def self.node_color_builder - return lambda do |text| + -> (text) do return unless text - hash_value = Digest::SHA256.hexdigest(text.encode('utf-8')) + + hash_value = Digest::SHA256.hexdigest(text.encode("utf-8")) color_code = T.must(hash_value[0, 6]) - r = T.must(color_code[0, 2]).to_i(16) % 128 + 128 - g = T.must(color_code[2, 2]).to_i(16) % 128 + 128 - b = T.must(color_code[4, 2]).to_i(16) % 128 + 128 + r = (T.must(color_code[0, 2]).to_i(16) % 128) + 128 + g = (T.must(color_code[2, 2]).to_i(16) % 128) + 128 + b = (T.must(color_code[4, 2]).to_i(16) % 128) + 128 "#%02X%02X%02X" % [r, g, b] end end @@ -174,13 +175,11 @@ def self.max_todo_count(all_packages, show_edge, options) all_packages.each do |package| todos_by_package = package.violations&.group_by(&:to_package_name) todos_by_package&.keys&.each do |todos_to_package| - todo_types = todos_by_package&& todos_by_package[todos_to_package]&.group_by(&:type) + todo_types = todos_by_package && todos_by_package[todos_to_package]&.group_by(&:type) todo_types&.keys&.each do |todo_type| - if options.relationship_todo_types.include?(EdgeTodoTypes.deserialize(todo_type)) - if show_edge.call(package.name, todos_to_package) - key = "#{package.name}->#{todos_to_package}:#{todo_type}" - todo_counts[key] = todo_types && todo_types[todo_type]&.count - end + if options.relationship_todo_types.include?(EdgeTodoTypes.deserialize(todo_type)) && show_edge.call(package.name, todos_to_package) + key = "#{package.name}->#{todos_to_package}:#{todo_type}" + todo_counts[key] = todo_types && todo_types[todo_type]&.count end end end @@ -220,12 +219,10 @@ def self.filtered(packages, options) nested_packages = all_nested_packages(packages.map { |p| p.name }) - packages_by_name = packages.inject({}) do |res, p| + packages_by_name = packages.each_with_object({}) do |p, res| res[p.name] = p - res end - result = T.let([], T::Array[T.nilable(String)]) result = packages.map { |pack| pack.name } if focus_pack @@ -239,19 +236,18 @@ def self.filtered(packages, options) todos_in = options.show_relationship_todos ? todos_in(packages, focus_pack_name, options) : [] case options.show_only_edges_to_focus_pack - when FocusPackEdgeDirection::All, FocusPackEdgeDirection::InOut then + when FocusPackEdgeDirection::All, FocusPackEdgeDirection::InOut result += dependents + dependencies + todos_out + todos_in - when FocusPackEdgeDirection::In then + when FocusPackEdgeDirection::In result += dependents + todos_in - when FocusPackEdgeDirection::Out then + when FocusPackEdgeDirection::Out result += dependencies + todos_out - when FocusPackEdgeDirection::None then + when FocusPackEdgeDirection::None # nothing to do end - parent_packs = result.inject([]) do |res, package_name| + parent_packs = result.each_with_object([]) do |package_name, res| res << nested_packages[package_name] - res end result = (result + parent_packs).uniq.compact @@ -266,15 +262,13 @@ def self.filtered(packages, options) sig { params(all_package_names: T::Array[String]).returns(T::Hash[String, String]) } def self.all_nested_packages(all_package_names) - all_package_names.reject { |p| p == '.' }.inject({}) do |result, package| + all_package_names.reject { |p| p == "." }.each_with_object({}) do |package, result| package_map_tally = all_package_names.map { |other_package| Pathname.new(package).parent.to_s.include?(other_package) } acc = [] all_package_names.each_with_index { |pack, idx| acc << pack if package_map_tally[idx] } acc.sort_by(&:length) result[package] = acc.first unless acc.empty? - - result end end @@ -307,7 +301,6 @@ def self.remove_nested_packs(packages, options) end end - morphed_dependencies = package.dependencies.map do |d| nested_packages[d] || d end.uniq.reject { |p| p == package.name } @@ -321,8 +314,7 @@ def self.remove_nested_packs(packages, options) ) end.reject { |v| v.to_package_name == package.name } - - new_package = ParsePackwerk::Package.new( + ParsePackwerk::Package.new( name: package.name, enforce_dependencies: package.enforce_dependencies, enforce_privacy: package.enforce_privacy, @@ -340,12 +332,12 @@ def self.remove_nested_packs(packages, options) sig { params(pack: String, packs_name_with_wildcards: T.nilable(T::Array[String])).returns(T::Boolean) } def self.match_packs?(pack, packs_name_with_wildcards) - !packs_name_with_wildcards || packs_name_with_wildcards.any? {|p| File.fnmatch(p, pack)} + !packs_name_with_wildcards || packs_name_with_wildcards.any? { |p| File.fnmatch(p, pack) } end sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String]).returns(T::Array[String]) } def self.dependencies_of(all_packages, focus_packs_names) - focus_packs = all_packages.select { focus_packs_names.include?(_1.name)} + focus_packs = all_packages.select { focus_packs_names.include?(_1.name) } focus_packs.inject([]) do |result, pack| result += pack.dependencies @@ -355,38 +347,36 @@ def self.dependencies_of(all_packages, focus_packs_names) sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String]).returns(T::Array[String]) } def self.dependents_on(all_packages, focus_packs_names) - all_packages.select { |pack| pack.dependencies.any? { focus_packs_names.include?(_1) }}.map &:name + all_packages.select { |pack| pack.dependencies.any? { focus_packs_names.include?(_1) } }.map &:name end sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String], options: Options).returns(T::Array[String]) } def self.todos_in(all_packages, focus_packs_names, options) all_packages.select do |p| - (p.violations || []).inject([]) do |res, todo| + (p.violations || []).each_with_object([]) do |todo, res| res << todo.to_package_name if options.relationship_todo_types.include?(EdgeTodoTypes.deserialize(todo.type)) - res end.any? { |v| focus_packs_names.include?(v) } end.map { |pack| pack.name } end sig { params(all_packages: T::Array[ParsePackwerk::Package], focus_packs_names: T::Array[String], options: Options).returns(T::Array[String]) } def self.todos_out(all_packages, focus_packs_names, options) - all_packages.inject([]) do |result, p| + all_packages.each_with_object([]) do |p, result| focus_packs_names.include?(p.name) && (p.violations || []).each do |todo| result << todo.to_package_name if options.relationship_todo_types.include?(EdgeTodoTypes.deserialize(todo.type)) end - result end end - sig { params(protection: String, package_name: String, rubocop_config: T.any(NilClass, T::Boolean, T::Hash[String, T.untyped]), rubocop_todo: T.any(NilClass, T::Boolean, T::Hash[String, T.untyped])).returns(T.nilable(Integer)) } - def self.package_based_todos_for(protection, package_name, rubocop_config, rubocop_todo) + sig { params(protection: String, package_name: String, rubocop_config: T.nilable(T.any(T::Boolean, T::Hash[String, T.untyped])), rubocop_todo: T.nilable(T.any(T::Boolean, T::Hash[String, T.untyped]))).returns(T.nilable(Integer)) } + def self.package_based_todos_for(protection, package_name, rubocop_config, rubocop_todo) rubocop_config = {} if rubocop_config.is_a?(TrueClass) || rubocop_config.is_a?(FalseClass) || rubocop_config.is_a?(NilClass) rubocop_todo = {} if rubocop_todo.is_a?(TrueClass) || rubocop_todo.is_a?(FalseClass) || rubocop_todo.is_a?(NilClass) - raise ArgumentError unless ['Packs/ClassMethodsAsPublicApis', 'Packs/DocumentedPublicApis', 'Packs/RootNamespaceIsPackName', 'Packs/TypedPublicApis'].include?(protection) - return nil unless (rubocop_config.dig(protection)&.dig('Enabled')) + raise ArgumentError unless ["Packs/ClassMethodsAsPublicApis", "Packs/DocumentedPublicApis", "Packs/RootNamespaceIsPackName", "Packs/TypedPublicApis"].include?(protection) + return nil unless rubocop_config.dig(protection)&.dig("Enabled") - (rubocop_todo.dig(protection)&.dig('Exclude') || []).inject(0) do |result, todo| + (rubocop_todo.dig(protection)&.dig("Exclude") || []).inject(0) do |result, todo| result += 1 if todo.start_with?("#{package_name}/") result end @@ -394,21 +384,21 @@ def self.package_based_todos_for(protection, package_name, rubocop_config, rubo sig { returns(T.untyped) } def self.package_based_todos_text_maker - ->(package_name) { + -> (package_name) do [ - 'Packs/ClassMethodsAsPublicApis', - 'Packs/DocumentedPublicApis', - 'Packs/RootNamespaceIsPackName', - 'Packs/TypedPublicApis' + "Packs/ClassMethodsAsPublicApis", + "Packs/DocumentedPublicApis", + "Packs/RootNamespaceIsPackName", + "Packs/TypedPublicApis", ].map do |protection| rubocop_config = File.exist?("#{package_name}/.rubocop.yml") ? YAML.load_file("#{package_name}/.rubocop.yml") : {} rubocop_todo = File.exist?(".rubocop_todo.yml") ? YAML.load_file(".rubocop_todo.yml") : {} - todo_value = package_based_todos_for(protection, package_name, rubocop_config, rubocop_todo) - abbreviation = T.must(protection.split('/')[1]).chars[0] + todo_value = package_based_todos_for(protection, package_name, rubocop_config, rubocop_todo) + abbreviation = T.must(protection.split("/")[1])[0] "#{abbreviation}: #{todo_value}" if todo_value end.compact.join(", ") - } + end end end diff --git a/lib/visualize_packs/options.rb b/lib/visualize_packs/options.rb index 05cb57b..772fb46 100644 --- a/lib/visualize_packs/options.rb +++ b/lib/visualize_packs/options.rb @@ -1,5 +1,5 @@ -# frozen_string_literal: true # typed: strict +# frozen_string_literal: true class EdgeTodoTypes < T::Enum enums do diff --git a/lib/visualize_packs/options_parser.rb b/lib/visualize_packs/options_parser.rb index 403e427..a9da89f 100644 --- a/lib/visualize_packs/options_parser.rb +++ b/lib/visualize_packs/options_parser.rb @@ -1,5 +1,5 @@ +# typed: strict # frozen_string_literal: true -#typed: strict require "optparse" @@ -11,34 +11,34 @@ def self.parse(args) options = Options.new OptionParser.new do |opt| - opt.on('--no-legend', "Don't show legend") { |o| options.show_legend = false } + opt.on("--no-legend", "Don't show legend") { |_o| options.show_legend = false } - opt.on('--no-dependency-arrows', "Don't show accepted dependency arrows") { |o| options.show_dependencies = false } - opt.on('--no-privacy-boxes', "Don't show privacy enforcement box on a pack") { |o| options.show_privacy = false } - opt.on('--no-layers', "Don't show architectural layers") { |o| options.show_layers = false } - opt.on('--no-visibility-arrows', "Don't show visibility arrows") { |o| options.show_visibility = false } + opt.on("--no-dependency-arrows", "Don't show accepted dependency arrows") { |_o| options.show_dependencies = false } + opt.on("--no-privacy-boxes", "Don't show privacy enforcement box on a pack") { |_o| options.show_privacy = false } + opt.on("--no-layers", "Don't show architectural layers") { |_o| options.show_layers = false } + opt.on("--no-visibility-arrows", "Don't show visibility arrows") { |_o| options.show_visibility = false } - opt.on('--no-todo-edges', "Don't show todos for package relationships") { |o| options.show_relationship_todos = false } + opt.on("--no-todo-edges", "Don't show todos for package relationships") { |_o| options.show_relationship_todos = false } opt.on("--edge-todo-types=STRING", "Show only the selected types of relationship todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |o| options.relationship_todo_types = o.to_s.split(",").uniq.map { EdgeTodoTypes.deserialize(_1) } } - opt.on("--use-edge-todos-for-layout", "Show only the selected types of relationship todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |o| options.use_relationship_todos_for_layout = true } + opt.on("--use-edge-todos-for-layout", "Show only the selected types of relationship todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |_o| options.use_relationship_todos_for_layout = true } - opt.on('--no-teams', "Don't show team colors") { |o| options.show_teams = false } - opt.on('--no-node-todos', "Don't show package-based todos") { |o| options.show_node_todos = false } + opt.on("--no-teams", "Don't show team colors") { |_o| options.show_teams = false } + opt.on("--no-node-todos", "Don't show package-based todos") { |_o| options.show_node_todos = false } - opt.on('--focus-pack=STRING', "Focus on a specific pack(s). Comma-separated list of packs. Wildcards supported: 'packs/*'") { |o| options.focus_pack = o.to_s.split(",") } - opt.on('--focus-pack-edge-mode=STRING', "If focus-pack is set, this shows only between focused packs (when set to none) or the edges into / out of / in and out of the focus packs to non-focus packs (which will be re-added to the graph). One of #{FocusPackEdgeDirection.values.map &:serialize}") { |o| options.show_only_edges_to_focus_pack = FocusPackEdgeDirection.deserialize(o) } - opt.on('--exclude-packs=', "Exclude listed packs from diagram. If used with include you will get all included that are not excluded. Wildcards supported: 'packs/ignores/*'") { |o| options.exclude_packs = o.to_s.split(",") } + opt.on("--focus-pack=STRING", "Focus on a specific pack(s). Comma-separated list of packs. Wildcards supported: 'packs/*'") { |o| options.focus_pack = o.to_s.split(",") } + opt.on("--focus-pack-edge-mode=STRING", "If focus-pack is set, this shows only between focused packs (when set to none) or the edges into / out of / in and out of the focus packs to non-focus packs (which will be re-added to the graph). One of #{FocusPackEdgeDirection.values.map &:serialize}") { |o| options.show_only_edges_to_focus_pack = FocusPackEdgeDirection.deserialize(o) } + opt.on("--exclude-packs=", "Exclude listed packs from diagram. If used with include you will get all included that are not excluded. Wildcards supported: 'packs/ignores/*'") { |o| options.exclude_packs = o.to_s.split(",") } - opt.on('--roll-nested-into-parent-packs', "Don't show nested packs (not counting root). Connect edges to top-level pack instead") { |o| options.roll_nested_into_parent_packs = true } - opt.on('--no-nesting-arrows', "Don't draw relationships between parents and nested packs") { |o| options.show_nested_relationships = false } + opt.on("--roll-nested-into-parent-packs", "Don't show nested packs (not counting root). Connect edges to top-level pack instead") { |_o| options.roll_nested_into_parent_packs = true } + opt.on("--no-nesting-arrows", "Don't draw relationships between parents and nested packs") { |_o| options.show_nested_relationships = false } - opt.on('--remote-base-url=STRING', "Link packs to a URL (affects graphviz SVG generation)") { |o| options.remote_base_url = o } + opt.on("--remote-base-url=STRING", "Link packs to a URL (affects graphviz SVG generation)") { |o| options.remote_base_url = o } - opt.on('--title=STRING', "Set a custom diagram title") { |o| options.title = o } + opt.on("--title=STRING", "Set a custom diagram title") { |o| options.title = o } - opt.on('-V', '--version', "Show version") do + opt.on("-V", "--version", "Show version") do spec_path = File.expand_path("../visualize_packs.gemspec", __dir__) - spec = Gem::Specification::load(spec_path) + spec = Gem::Specification.load(spec_path) puts "Version #{spec.version}" exit end @@ -52,4 +52,3 @@ def self.parse(args) options end end - diff --git a/spec/sample_app1/Gemfile b/spec/sample_app1/Gemfile index b04ada3..1bf1584 100644 --- a/spec/sample_app1/Gemfile +++ b/spec/sample_app1/Gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -gem 'visualize_packs', path: '../../' -gem 'parse_packwerk' +gem "parse_packwerk" +gem "visualize_packs", path: "../../" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a73e7cb..f73de19 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,9 @@ -# frozen_string_literal: true # typed: ignore +# frozen_string_literal: true 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! @@ -22,4 +22,3 @@ "Expected packs #{actual_array.map(&:name).sort} to eq: #{expected_array.map(&:name).sort}" end end - diff --git a/spec/visualize_packs_spec.rb b/spec/visualize_packs_spec.rb index 6e23a80..0ec3edf 100644 --- a/spec/visualize_packs_spec.rb +++ b/spec/visualize_packs_spec.rb @@ -1,14 +1,15 @@ +# typed: false # frozen_string_literal: true -require 'packs-specification' -require 'sorbet-runtime' +require "packs-specification" +require "sorbet-runtime" -require_relative '../lib/visualize_packs' +require_relative "../lib/visualize_packs" RSpec.describe "VisualizePacks" do describe ".all_nested_packages" do it "has an empty result if there are no nested packs" do - input = %w(. packs/a packs/b ) + input = %w(. packs/a packs/b) expected_output = {} expect(VisualizePacks.all_nested_packages(input)).to eq(expected_output) @@ -19,7 +20,7 @@ expected_output = { "packs/a/z" => "packs/a", "packs/b/packs/x" => "packs/b", - "packs/b/packs/y" => "packs/b" + "packs/b/packs/y" => "packs/b", } expect(VisualizePacks.all_nested_packages(input)).to eq(expected_output) @@ -43,22 +44,22 @@ name: "packs/a", enforce_dependencies: true, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", metadata: {}, violations: [], - dependencies: ['packs/b', 'packs/b/nested', 'packs/a/nested'], - config: {enforce_dependencies: true, enforce_privacy: true}, + dependencies: ["packs/b", "packs/b/nested", "packs/a/nested"], + config: { enforce_dependencies: true, enforce_privacy: true } ) allow(top_level_a).to receive(:violations) do [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", class_name: "SomeClass1", files: ["some_file1"] ), ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b/nested", class_name: "SomeClass2", files: ["some_file2"] @@ -69,22 +70,22 @@ name: "packs/a/nested", enforce_dependencies: true, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", metadata: {}, violations: [], - dependencies: ['packs/a', 'packs/b'], - config: {enforce_dependencies: true, enforce_privacy: true}, + dependencies: ["packs/a", "packs/b"], + config: { enforce_dependencies: true, enforce_privacy: true } ) allow(nested_a).to receive(:violations) do [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", class_name: "SomeClass7", files: ["some_file7"] ), ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b/nested", class_name: "SomeClass8", files: ["some_file8"] @@ -96,16 +97,16 @@ name: "packs/b", enforce_dependencies: true, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", metadata: {}, violations: [], - dependencies: ['packs/b/nested'], - config: {enforce_dependencies: true, enforce_privacy: true}, + dependencies: ["packs/b/nested"], + config: { enforce_dependencies: true, enforce_privacy: true } ) allow(top_level_b).to receive(:violations) do [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b/nested", class_name: "SomeClass4", files: ["some_file4"] @@ -117,22 +118,22 @@ name: "packs/b/nested", enforce_dependencies: true, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", metadata: {}, violations: [], - dependencies: ['packs/a', 'packs/b'], - config: {enforce_dependencies: true, enforce_privacy: true}, + dependencies: ["packs/a", "packs/b"], + config: { enforce_dependencies: true, enforce_privacy: true } ) allow(nested_b).to receive(:violations) do [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/a", class_name: "SomeClass5", files: ["some_file5"] ), ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", class_name: "SomeClass6", files: ["some_file6"] @@ -152,16 +153,16 @@ new_top_level_b = result[1] expect(new_top_level_b.name).to eq "packs/b" - expect(new_top_level_a.dependencies).to eq ['packs/b'] + expect(new_top_level_a.dependencies).to eq ["packs/b"] expect(new_top_level_a.violations.map(&:inspect)).to eq [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", class_name: "SomeClass1", files: ["some_file1"] ), ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", ## this is no longer pointing to the nested package! class_name: "SomeClass2", files: ["some_file2"] @@ -170,26 +171,26 @@ # violations from the nested package ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", class_name: "SomeClass7", files: ["some_file7"] ), ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/b", ## this is no longer pointing to the nested package! class_name: "SomeClass8", files: ["some_file8"] ), ].map(&:inspect) - expect(new_top_level_b.dependencies).to eq ['packs/a'] + expect(new_top_level_b.dependencies).to eq ["packs/a"] ## this does not include a self reference to packs/b ## it does now include the dependency on packs/a from the nested pack expect(new_top_level_b.violations.map(&:inspect)).to eq [ ParsePackwerk::Violation.new( - type: 'privacy', + type: "privacy", to_package_name: "packs/a", class_name: "SomeClass5", files: ["some_file5"] @@ -215,19 +216,19 @@ # Define expectations this way: # [todo_count, max_count, expected_value] [ - [0, 1, 0], - [1, 1, 1], - [0, 3, 0], - [2, 3, 5.5], - [3, 3, 10], - [0, 10, 0], - [4, 10, 4], - [9, 10, 9], - [10, 10, 10], - [0, 100, 0], - [25, 100, 3.18], - [75, 100, 7.73], - [99, 100, 9.91], + [0, 1, 0], + [1, 1, 1], + [0, 3, 0], + [2, 3, 5.5], + [3, 3, 10], + [0, 10, 0], + [4, 10, 4], + [9, 10, 9], + [10, 10, 10], + [0, 100, 0], + [25, 100, 3.18], + [75, 100, 7.73], + [99, 100, 9.91], ].each do |todo_count, max_count, expectation| it "returns #{expectation} for a todo count of #{todo_count} and max todos being #{max_count}" do expect(VisualizePacks.todo_edge_width(todo_count, max_count)).to eq expectation @@ -235,21 +236,21 @@ end end - describe '.max_todo_count' do + describe ".max_todo_count" do before do - @package_with_todos = -> (todos) { + @package_with_todos = -> (todos) do x = ParsePackwerk::Package.new( name: "packs/a", enforce_dependencies: true, enforce_privacy: false, - public_path: 'app/public', + public_path: "app/public", metadata: {}, dependencies: [], violations: [], - config: {}, + config: {} ) allow(x).to receive(:violations) do - todos.keys.inject([]) do |result, todo_type| + todos.keys.each_with_object([]) do |todo_type, result| todos[todo_type].times do result << ParsePackwerk::Violation.new( type: todo_type.to_s, @@ -258,33 +259,32 @@ files: ["some_file1"] ) end - result end end x - } + end @options = Options.new end - let(:show_edge) { VisualizePacks.show_edge_builder(@options, [@package.name, 'packs/b']) } + let(:show_edge) { VisualizePacks.show_edge_builder(@options, [@package.name, "packs/b"]) } it "is nil if todos aren't being shown" do @options.show_relationship_todos = false - @package = @package_with_todos.call({privacy: 1}) + @package = @package_with_todos.call({ privacy: 1 }) - expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be nil + expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be_nil end it "is nil if there aren't any todos" do @options.show_relationship_todos = true @package = @package_with_todos.call({}) - expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be nil + expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be_nil end it "returns the highest number of todos found in shown package relationships" do @options.show_relationship_todos = true - @package = @package_with_todos.call({privacy: 3, dependency: 1}) + @package = @package_with_todos.call({ privacy: 3, dependency: 1 }) expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be 3 end @@ -292,23 +292,23 @@ it "does not include counts from todo types that are not being shown" do @options.show_relationship_todos = true @options.relationship_todo_types = [EdgeTodoTypes::Privacy, EdgeTodoTypes::Layer] - @package = @package_with_todos.call({privacy: 3, dependency: 4, layer: 2}) + @package = @package_with_todos.call({ privacy: 3, dependency: 4, layer: 2 }) expect(VisualizePacks.max_todo_count([@package], show_edge, @options)).to be 3 end end - describe '.match_packs?' do - it 'does not exclude non-matches' do + describe ".match_packs?" do + it "does not exclude non-matches" do expect(VisualizePacks.match_packs?("pack", ["packs", "spack", "ack", "components"])).to be_falsy end - it 'excludes matches' do + it "excludes matches" do expect(VisualizePacks.match_packs?("pack", ["pack", "park"])).to be_truthy expect(VisualizePacks.match_packs?("park", ["pack", "park"])).to be_truthy end - it 'excludes matches using fnmatch' do + it "excludes matches using fnmatch" do expect(VisualizePacks.match_packs?("component", ["pack/*"])).to be_falsy expect(VisualizePacks.match_packs?("pack", ["pack/*"])).to be_falsy expect(VisualizePacks.match_packs?("pack/a", ["pack/*"])).to be_truthy @@ -319,152 +319,150 @@ end end - describe '.filtered' do - let(:pack_name_lookup) { + describe ".filtered" do + let(:pack_name_lookup) do { - 'a' => 'packs/a', - '1' => 'packs/a/1', - '2' => 'packs/a/2', - '3' => 'packs/b/3', - '4' => 'packs/b/4', - 'c' => 'packs/c' + "a" => "packs/a", + "1" => "packs/a/1", + "2" => "packs/a/2", + "3" => "packs/b/3", + "4" => "packs/b/4", + "c" => "packs/c", } - } - let(:pack_lookup) { + end + let(:pack_lookup) do { - 'a' => @pack_a, - '1' => @pack_1, - '2' => @pack_2, - '3' => @pack_3, - '4' => @pack_4, - 'c' => @pack_c + "a" => @pack_a, + "1" => @pack_1, + "2" => @pack_2, + "3" => @pack_3, + "4" => @pack_4, + "c" => @pack_c, } - } - let(:edge_type_lookup) { + end + let(:edge_type_lookup) do { - 'd' => EdgeTodoTypes::Dependency, - 'p' => EdgeTodoTypes::Privacy, - 'a' => EdgeTodoTypes::Layer, - 'v' => EdgeTodoTypes::Visibility, - 'f' => EdgeTodoTypes::Folder_Visibility + "d" => EdgeTodoTypes::Dependency, + "p" => EdgeTodoTypes::Privacy, + "a" => EdgeTodoTypes::Layer, + "v" => EdgeTodoTypes::Visibility, + "f" => EdgeTodoTypes::Folder_Visibility, } - } - let(:edge_mode_lookup) { + end + let(:edge_mode_lookup) do { - 'a' => FocusPackEdgeDirection::All, - 'i' => FocusPackEdgeDirection::In, - 'o' => FocusPackEdgeDirection::Out, - 'b' => FocusPackEdgeDirection::InOut, - 'n' => FocusPackEdgeDirection::None + "a" => FocusPackEdgeDirection::All, + "i" => FocusPackEdgeDirection::In, + "o" => FocusPackEdgeDirection::Out, + "b" => FocusPackEdgeDirection::InOut, + "n" => FocusPackEdgeDirection::None, } - } + end - let(:dependency_generate) { ->(str, node_name) { str.split(' ').map { _1[0] == node_name ? pack_name_lookup[_1[1]]: nil}.compact } } + let(:dependency_generate) { -> (str, node_name) { str.split(" ").map { _1[0] == node_name ? pack_name_lookup[_1[1]] : nil }.compact } } - let(:make_todo) { - ->(type, to_package_name) { + let(:make_todo) do + -> (type, to_package_name) do ParsePackwerk::Violation.new( type: type.serialize, - to_package_name: to_package_name, + to_package_name:, class_name: "SomeClass1", files: ["some_file1"] ) - } - } - let(:todo_generate) { - ->(str, node_name) { - str.split(' ').map { _1[0] == node_name ? make_todo.(edge_type_lookup[_1[1]], pack_name_lookup[_1[2]]): nil}.compact - } - } + end + end + let(:todo_generate) do + -> (str, node_name) do + str.split(" ").map { _1[0] == node_name ? make_todo.(edge_type_lookup[_1[1]], pack_name_lookup[_1[2]]) : nil }.compact + end + end - let(:make_pack) { - ->(name, dependencies = [], todos = []) { + let(:make_pack) do + -> (name, dependencies = [], todos = []) do ParsePackwerk::Package.new( - name: name, + name:, enforce_dependencies: true, enforce_privacy: false, - public_path: '', + public_path: "", metadata: {}, - dependencies: dependencies, + dependencies:, config: {}, violations: todos ) - } - } + end + end true_ = true - cases = [ - # packages show_relationship_todos edge_focus_mode todos focus_pack exclude_packs expectation test_description - # show_deps relationship_todo_types dependencies - # 0 1 2 3 4 5 6 7 8 9 + [ + # [0: packages, 1: show_deps, 2: show_relationship_todos, 3: relationship_todo_types, 4: edge_focus_mode, + # 5: dependencies, 6: todos, 7: focus_pack, 8: exclude_packs, 9: expectation, 10: test_description] - #basic usage - [' ', true_, false, 'dpav', 'a', ' ', ' ', nil, [], ' ', 'empty list works'], - [' 1234 ', true_, false, 'dpav', 'a', ' ', ' ', nil, [], ' 1234 ', 'unfiltered list works (even if there are more nodes)'], - ['a1234c', true_, false, 'dpav', 'a', ' ', ' ', nil, [], 'a1234c', 'unfiltered list works'], + # basic usage + [" ", true_, false, "dpav", "a", " ", " ", nil, [], " ", "empty list works"], + [" 1234 ", true_, false, "dpav", "a", " ", " ", nil, [], " 1234 ", "unfiltered list works (even if there are more nodes)"], + ["a1234c", true_, false, "dpav", "a", " ", " ", nil, [], "a1234c", "unfiltered list works"], # Filtering (including wildcards) - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(), [], ' ', 'Empty focus_pack array filters all nodes'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(packs/a/1), [], 'a1 ', 'basic filtering works'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(packs/*), [], 'a1234c', 'filtering with wildcard works'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(packs/a/*), [], 'a12 ', 'parent nodes of filtered nodes are shown'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(packs/b/*), [], ' 34 ', 'nested _looking_ nodes (without parent) getting filtered works'], - #Filtering + dependencies - ['a1234c', false, true_, 'dpav', 'a', 'a1 2a', ' ', %w(packs/a), [], 'a ', 'dependency nodes not shown if dependency edges not shown'], - ['a1234c', true_, true_, 'dpav', 'a', 'a1 2a', ' ', %w(packs/a), [], 'a12 ', 'dependency nodes shown if dependency edges shown'], - ['a1234c', true_, true_, 'dpav', 'n', 'a1 2a', ' ', %w(packs/a), [], 'a ', 'dependency nodes not shown if edge mode none'], - ['a1234c', true_, true_, 'dpav', 'o', 'a1 2a', ' ', %w(packs/a), [], 'a1 ', 'only out dependency nodes shown if edge mode out'], - ['a1234c', true_, true_, 'dpav', 'i', 'a1 2a', ' ', %w(packs/a), [], 'a 2 ', 'only in dependency nodes shown if edge mode in'], - ['a1234c', true_, true_, 'dpav', 'b', 'a1 2a', ' ', %w(packs/a), [], 'a12 ', 'dependency nodes shown if edge mode inout'], - #Filtering + todos - ['a1234c', true_, false, 'dpav', 'a', ' ', ' ap1 2pa', %w(packs/a), [], 'a ', 'todo nodes not shown if todos not shown'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ap1 2pa', %w(packs/a), [], 'a12 ', 'todo nodes shown if todos shown'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', 'ad1 ap2 aa3 av4', %w(packs/a), [], 'a1234 ', 'todo nodes shown for all todo types'], - ['a1234c', true_, true_, 'd ', 'a', ' ', ' ap1 2pa', %w(packs/a), [], 'a ', 'todo nodes not shown if todo type filtered'], - ['a1234c', true_, true_, 'd ', 'a', ' ', ' ad1 ap1 2pa', %w(packs/a), [], 'a1 ', 'todo nodes shown if specific todo type not filtered'], - ['a1234c', true_, true_, 'dpav', 'n', ' ', ' ap1 2pa', %w(packs/a), [], 'a ', 'todo nodes not shown if edge mode none'], - ['a1234c', true_, true_, 'dpav', 'o', ' ', ' ap1 2pa', %w(packs/a), [], 'a1 ', 'only out todo nodes shown if edge mode out'], - ['a1234c', true_, true_, 'dpav', 'i', ' ', ' ap1 2pa', %w(packs/a), [], 'a 2 ', 'only in todo nodes shown if edge mode in'], - ['a1234c', true_, true_, 'dpav', 'b', ' ', ' ap1 2pa', %w(packs/a), [], 'a12 ', 'todo nodes shown if edge mode inout'], - #Filtering + excluding (including wildcards) - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', nil, %w(packs/a/1), 'a 234c', 'exclude_packs removes node'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', nil, %w(packs/a/*), 'a 34c', 'exclude_packs with wildcard removes nodes'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', nil, %w(packs/a packs/a/*), ' 34c', 'exclude_packs with multiple excludes works'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ', %w(packs/a), %w(packs/a), ' ', 'exclude_packs excludes focus'], - ['a1234c', true_, true_, 'dpav', 'a', 'a1 ', ' ', %w(packs/a), %w(packs/a), ' 1 ', 'exclude_packs excludes focus but keeps dependency'], - ['a1234c', true_, true_, 'dpav', 'a', ' ', ' ad1', %w(packs/a), %w(packs/a), ' 1 ', 'exclude_packs excludes focus but keeps todo'], - #Filtering + dependencies + todos + excluding - ['a1234c', true_, true_, ' pa ', 'o', 'a1 2a', ' ad3 4aa apc', %w(packs/a), %w(packs/a), ' 1 c', 'combination of todo filtering, edge mode, focus, and exclude works'], - ].each do |c| - + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(), [], " ", "Empty focus_pack array filters all nodes"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(packs/a/1), [], "a1 ", "basic filtering works"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(packs/*), [], "a1234c", "filtering with wildcard works"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(packs/a/*), [], "a12 ", "parent nodes of filtered nodes are shown"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(packs/b/*), [], " 34 ", "nested _looking_ nodes (without parent) getting filtered works"], + # Filtering + dependencies + ["a1234c", false, true_, "dpav", "a", "a1 2a", " ", %w(packs/a), [], "a ", "dependency nodes not shown if dependency edges not shown"], + ["a1234c", true_, true_, "dpav", "a", "a1 2a", " ", %w(packs/a), [], "a12 ", "dependency nodes shown if dependency edges shown"], + ["a1234c", true_, true_, "dpav", "n", "a1 2a", " ", %w(packs/a), [], "a ", "dependency nodes not shown if edge mode none"], + ["a1234c", true_, true_, "dpav", "o", "a1 2a", " ", %w(packs/a), [], "a1 ", "only out dependency nodes shown if edge mode out"], + ["a1234c", true_, true_, "dpav", "i", "a1 2a", " ", %w(packs/a), [], "a 2 ", "only in dependency nodes shown if edge mode in"], + ["a1234c", true_, true_, "dpav", "b", "a1 2a", " ", %w(packs/a), [], "a12 ", "dependency nodes shown if edge mode inout"], + # Filtering + todos + ["a1234c", true_, false, "dpav", "a", " ", " ap1 2pa", %w(packs/a), [], "a ", "todo nodes not shown if todos not shown"], + ["a1234c", true_, true_, "dpav", "a", " ", " ap1 2pa", %w(packs/a), [], "a12 ", "todo nodes shown if todos shown"], + ["a1234c", true_, true_, "dpav", "a", " ", "ad1 ap2 aa3 av4", %w(packs/a), [], "a1234 ", "todo nodes shown for all todo types"], + ["a1234c", true_, true_, "d ", "a", " ", " ap1 2pa", %w(packs/a), [], "a ", "todo nodes not shown if todo type filtered"], + ["a1234c", true_, true_, "d ", "a", " ", " ad1 ap1 2pa", %w(packs/a), [], "a1 ", "todo nodes shown if specific todo type not filtered"], + ["a1234c", true_, true_, "dpav", "n", " ", " ap1 2pa", %w(packs/a), [], "a ", "todo nodes not shown if edge mode none"], + ["a1234c", true_, true_, "dpav", "o", " ", " ap1 2pa", %w(packs/a), [], "a1 ", "only out todo nodes shown if edge mode out"], + ["a1234c", true_, true_, "dpav", "i", " ", " ap1 2pa", %w(packs/a), [], "a 2 ", "only in todo nodes shown if edge mode in"], + ["a1234c", true_, true_, "dpav", "b", " ", " ap1 2pa", %w(packs/a), [], "a12 ", "todo nodes shown if edge mode inout"], + # Filtering + excluding (including wildcards) + ["a1234c", true_, true_, "dpav", "a", " ", " ", nil, %w(packs/a/1), "a 234c", "exclude_packs removes node"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", nil, %w(packs/a/*), "a 34c", "exclude_packs with wildcard removes nodes"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", nil, %w(packs/a packs/a/*), " 34c", "exclude_packs with multiple excludes works"], + ["a1234c", true_, true_, "dpav", "a", " ", " ", %w(packs/a), %w(packs/a), " ", "exclude_packs excludes focus"], + ["a1234c", true_, true_, "dpav", "a", "a1 ", " ", %w(packs/a), %w(packs/a), " 1 ", "exclude_packs excludes focus but keeps dependency"], + ["a1234c", true_, true_, "dpav", "a", " ", " ad1", %w(packs/a), %w(packs/a), " 1 ", "exclude_packs excludes focus but keeps todo"], + # Filtering + dependencies + todos + excluding + ["a1234c", true_, true_, " pa ", "o", "a1 2a", " ad3 4aa apc", %w(packs/a), %w(packs/a), " 1 c", "combination of todo filtering, edge mode, focus, and exclude works"], + ].each do |c| it "#{c[10]}" do options = Options.new options.focus_pack = c[7] options.exclude_packs = c[8] options.show_dependencies = c[1] options.show_relationship_todos = c[2] - options.relationship_todo_types = c[3].gsub(' ', '').chars.map { edge_type_lookup[_1] } + options.relationship_todo_types = c[3].delete(" ").chars.map { edge_type_lookup[_1] } options.show_only_edges_to_focus_pack = edge_mode_lookup[c[4]] - @pack_a = make_pack.(pack_name_lookup['a'], dependency_generate.(c[5], 'a'), todo_generate.(c[6], 'a')) - @pack_1 = make_pack.(pack_name_lookup['1'], dependency_generate.(c[5], '1'), todo_generate.(c[6], '1')) - @pack_2 = make_pack.(pack_name_lookup['2'], dependency_generate.(c[5], '2'), todo_generate.(c[6], '2')) - @pack_3 = make_pack.(pack_name_lookup['3'], dependency_generate.(c[5], '3'), todo_generate.(c[6], '3')) - @pack_4 = make_pack.(pack_name_lookup['4'], dependency_generate.(c[5], '4'), todo_generate.(c[6], '4')) - @pack_c = make_pack.(pack_name_lookup['c'], dependency_generate.(c[5], 'c'), todo_generate.(c[6], 'c')) + @pack_a = make_pack.(pack_name_lookup["a"], dependency_generate.(c[5], "a"), todo_generate.(c[6], "a")) + @pack_1 = make_pack.(pack_name_lookup["1"], dependency_generate.(c[5], "1"), todo_generate.(c[6], "1")) + @pack_2 = make_pack.(pack_name_lookup["2"], dependency_generate.(c[5], "2"), todo_generate.(c[6], "2")) + @pack_3 = make_pack.(pack_name_lookup["3"], dependency_generate.(c[5], "3"), todo_generate.(c[6], "3")) + @pack_4 = make_pack.(pack_name_lookup["4"], dependency_generate.(c[5], "4"), todo_generate.(c[6], "4")) + @pack_c = make_pack.(pack_name_lookup["c"], dependency_generate.(c[5], "c"), todo_generate.(c[6], "c")) - input_packages = c[0].gsub(' ', '').chars.map { pack_lookup[_1] } - expected_output_packages = c[9].gsub(' ', '').chars.map { pack_lookup[_1] } + input_packages = c[0].delete(" ").chars.map { pack_lookup[_1] } + expected_output_packages = c[9].delete(" ").chars.map { pack_lookup[_1] } expect(VisualizePacks.filtered(input_packages, options)).to match_packs(expected_output_packages) end end end - describe '.show_edge_builder' do - subject { VisualizePacks.show_edge_builder(@options, %w(a b c d)) } + describe ".show_edge_builder" do + subject { VisualizePacks.show_edge_builder(@options, %w(a b c d)) } - it 'returns a proc' do + it "returns a proc" do @options = Options.new @package_names = [] @@ -473,32 +471,32 @@ true_ = true - tests___ = ['a b', 'a c', 'a d', 'a e', 'b a', 'b c', 'b d', 'b e', 'c a', 'c b', 'c d', 'c e', 'd a', 'd b', 'd c', 'd e', 'e a', 'e b', 'e c', 'e d'] - cases = [ + tests___ = ["a b", "a c", "a d", "a e", "b a", "b c", "b d", "b e", "c a", "c b", "c d", "c e", "d a", "d b", "d c", "d e", "e a", "e b", "e c", "e d"] + [ [:all__, [true_, true_, true_, false, true_, true_, true_, false, true_, true_, true_, false, true_, true_, true_, false, false, false, false, false]], [:inout, [true_, true_, true_, false, true_, true_, true_, false, true_, true_, false, false, true_, true_, false, false, false, false, false, false]], [:in___, [true_, false, false, false, true_, false, false, false, true_, true_, false, false, true_, true_, false, false, false, false, false, false]], [:out__, [true_, true_, true_, false, true_, true_, true_, false, false, false, false, false, false, false, false, false, false, false, false, false]], [:none_, [true_, false, false, false, true_, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]], ].each do |edge_mode_line| - edge_mode = FocusPackEdgeDirection.deserialize(edge_mode_line[0].to_s.gsub('_', '')) + edge_mode = FocusPackEdgeDirection.deserialize(edge_mode_line[0].to_s.delete("_")) expectations = edge_mode_line[1] - (0..tests___.size-1).to_a.each do |index| + (0..tests___.size - 1).to_a.each do |index| it "returns #{expectations[index]} for mode #{edge_mode.serialize} with nodes a, b, c, d and focus nodes a, b for the edge #{tests___[index]}" do @options = Options.new @options.show_only_edges_to_focus_pack = edge_mode - @options.focus_pack = ['a', 'b'] + @options.focus_pack = ["a", "b"] edge_show = VisualizePacks.show_edge_builder(@options, %w(a b c d)) - expect(edge_show.call(*tests___[index].split(' '))).to eq(expectations[index]) + expect(edge_show.call(*tests___[index].split(" "))).to eq(expectations[index]) end end end end - describe '.diagram_title' do - context 'with a custom title from options' do + describe ".diagram_title" do + context "with a custom title from options" do it "returns whatever is set" do options = Options.new options.title = "Some title" @@ -507,8 +505,8 @@ end end - context 'without a custom title from options' do - describe 'with basic options and nil max edge count' do + context "without a custom title from options" do + describe "with basic options and nil max edge count" do it "doesn't show todo info" do options = Options.new @@ -516,7 +514,7 @@ end end - describe 'with basic options and 0 max edge count' do + describe "with basic options and 0 max edge count" do it "shows max as 0" do options = Options.new @@ -526,7 +524,7 @@ end end - describe 'with basic options and 1 max edge count' do + describe "with basic options and 1 max edge count" do it "shows max as 1" do options = Options.new @@ -536,7 +534,7 @@ end end - describe 'with basic options and non-zero max edge count' do + describe "with basic options and non-zero max edge count" do it "shows appropriate max" do options = Options.new @@ -552,17 +550,18 @@ options = Options.new diagram_title = VisualizePacks.diagram_title( - ['--title=Hide everything', '--no-node-todos', '--no-legend', '--no-layers', '--no-visibility', '--no-dependency-arrows', '--no-todo-edges', '--no-privacy-boxes', '--no-teams', '--no-nesting-arrows', '--remote-base-url=https://github.com/rubyatscale/visualize_packwerk/tree/main/spec/sample_app'], + ["--title=Hide everything", "--no-node-todos", "--no-legend", "--no-layers", "--no-visibility", "--no-dependency-arrows", "--no-todo-edges", "--no-privacy-boxes", "--no-teams", "--no-nesting-arrows", "--remote-base-url=https://github.com/rubyatscale/visualize_packwerk/tree/main/spec/sample_app"], options, - nil) + nil + ) expect(diagram_title).to eq( - "<All packs
--title=Hide everything --no-node-todos --no-legend --no-layers --no-visibility
--no-dependency-arrows --no-todo-edges --no-privacy-boxes --no-teams --no-nesting-arrows
--remote-base-url=https://github.com/rubyatscale/visualize_packwerk/tree/main/spec/sample_app>" - ) + "<All packs
--title=Hide everything --no-node-todos --no-legend --no-layers --no-visibility
--no-dependency-arrows --no-todo-edges --no-privacy-boxes --no-teams --no-nesting-arrows
--remote-base-url=https://github.com/rubyatscale/visualize_packwerk/tree/main/spec/sample_app>" + ) end end end - describe '.package_based_todos_for' do + describe ".package_based_todos_for" do let(:full_rubocop) { YAML.load(<<~YAML) } inherit_from: ../../.rubocop.yml @@ -610,44 +609,44 @@ - 'packs/b/something3' - 'packs/b/something4' - 'packs/b/something5' - YML + YML - let(:empty_yaml) { YAML.load('') } + let(:empty_yaml) { YAML.load("") } [ - [' Packs/ClassMethodsAsPublicApis', 'packs/a', 'dtrc', :empty_yaml, 0], - - [' Packs/Something', 'packs/a', 'dtrc', :full_rubocop_todo, :error], - ['Something/ClassMethodsAsPublicApis', 'packs/a', 'dtrc', :full_rubocop_todo, :error], - - [' Packs/ClassMethodsAsPublicApis', 'packs/a', 'dtr ', :full_rubocop_todo, nil], - [' Packs/ClassMethodsAsPublicApis', 'packs/a', 'dtrc', :full_rubocop_todo, 1], - [' Packs/ClassMethodsAsPublicApis', 'packs/b', 'dtrc', :full_rubocop_todo, 2], - [' Packs/ClassMethodsAsPublicApis', 'packs/c', 'dtrc', :full_rubocop_todo, 0], - - [' Packs/DocumentedPublicApis', 'packs/a', ' trc', :full_rubocop_todo, nil], - [' Packs/DocumentedPublicApis', 'packs/a', 'dtrc', :full_rubocop_todo, 1], - [' Packs/DocumentedPublicApis', 'packs/b', 'dtrc', :full_rubocop_todo, 3], - [' Packs/DocumentedPublicApis', 'packs/c', 'dtrc', :full_rubocop_todo, 0], - - [' Packs/RootNamespaceIsPackName', 'packs/a', 'dt c', :full_rubocop_todo, nil], - [' Packs/RootNamespaceIsPackName', 'packs/a', 'dtrc', :full_rubocop_todo, 1], - [' Packs/RootNamespaceIsPackName', 'packs/b', 'dtrc', :full_rubocop_todo, 4], - [' Packs/RootNamespaceIsPackName', 'packs/c', 'dtrc', :full_rubocop_todo, 0], - - [' Packs/TypedPublicApis', 'packs/a', 'd rc', :full_rubocop_todo, nil], - [' Packs/TypedPublicApis', 'packs/a', 'dtrc', :full_rubocop_todo, 1], - [' Packs/TypedPublicApis', 'packs/b', 'dtrc', :full_rubocop_todo, 5], - [' Packs/TypedPublicApis', 'packs/c', 'dtrc', :full_rubocop_todo, 0], + [" Packs/ClassMethodsAsPublicApis", "packs/a", "dtrc", :empty_yaml, 0], + + [" Packs/Something", "packs/a", "dtrc", :full_rubocop_todo, :error], + ["Something/ClassMethodsAsPublicApis", "packs/a", "dtrc", :full_rubocop_todo, :error], + + [" Packs/ClassMethodsAsPublicApis", "packs/a", "dtr ", :full_rubocop_todo, nil], + [" Packs/ClassMethodsAsPublicApis", "packs/a", "dtrc", :full_rubocop_todo, 1], + [" Packs/ClassMethodsAsPublicApis", "packs/b", "dtrc", :full_rubocop_todo, 2], + [" Packs/ClassMethodsAsPublicApis", "packs/c", "dtrc", :full_rubocop_todo, 0], + + [" Packs/DocumentedPublicApis", "packs/a", " trc", :full_rubocop_todo, nil], + [" Packs/DocumentedPublicApis", "packs/a", "dtrc", :full_rubocop_todo, 1], + [" Packs/DocumentedPublicApis", "packs/b", "dtrc", :full_rubocop_todo, 3], + [" Packs/DocumentedPublicApis", "packs/c", "dtrc", :full_rubocop_todo, 0], + + [" Packs/RootNamespaceIsPackName", "packs/a", "dt c", :full_rubocop_todo, nil], + [" Packs/RootNamespaceIsPackName", "packs/a", "dtrc", :full_rubocop_todo, 1], + [" Packs/RootNamespaceIsPackName", "packs/b", "dtrc", :full_rubocop_todo, 4], + [" Packs/RootNamespaceIsPackName", "packs/c", "dtrc", :full_rubocop_todo, 0], + + [" Packs/TypedPublicApis", "packs/a", "d rc", :full_rubocop_todo, nil], + [" Packs/TypedPublicApis", "packs/a", "dtrc", :full_rubocop_todo, 1], + [" Packs/TypedPublicApis", "packs/b", "dtrc", :full_rubocop_todo, 5], + [" Packs/TypedPublicApis", "packs/c", "dtrc", :full_rubocop_todo, 0], ].each do |test| it "works for #{test.join(', ')}" do protection = test[0].strip pack_name = test[1].strip - @DocumentedPublicApis = test[2].include?('d') - @RootNamespaceIsPackName = test[2].include?('r') - @TypedPublicApis = test[2].include?('t') - @ClassMethodsAsPublicApis = test[2].include?('c') + @DocumentedPublicApis = test[2].include?("d") + @RootNamespaceIsPackName = test[2].include?("r") + @TypedPublicApis = test[2].include?("t") + @ClassMethodsAsPublicApis = test[2].include?("c") rubocop_todo = test[3] == :full_rubocop_todo ? full_rubocop_todo : empty_yaml expectation = test[4] diff --git a/visualize_packs.gemspec b/visualize_packs.gemspec index 0315afd..4459412 100644 --- a/visualize_packs.gemspec +++ b/visualize_packs.gemspec @@ -1,38 +1,38 @@ Gem::Specification.new do |spec| spec.name = "visualize_packs" - spec.version = '0.6.0' - spec.authors = ['Gusto Engineers'] - spec.email = ['dev@gusto.com'] - spec.summary = 'A gem to visualize connections in a Ruby app that uses packs' - spec.description = 'A gem to visualize connections in a Ruby app that uses packs' - spec.homepage = 'https://github.com/rubyatscale/visualize_packs' - spec.license = 'MIT' + spec.version = "0.6.0" + spec.authors = ["Gusto Engineers"] + spec.email = ["dev@gusto.com"] + spec.summary = "A gem to visualize connections in a Ruby app that uses packs" + spec.description = "A gem to visualize connections in a Ruby app that uses packs" + spec.homepage = "https://github.com/rubyatscale/visualize_packs" + spec.license = "MIT" if spec.respond_to?(:metadata) - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/rubyatscale/visualize_packs' - spec.metadata['changelog_uri'] = 'https://github.com/rubyatscale/visualize_packs/releases' - spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/rubyatscale/visualize_packs" + spec.metadata["changelog_uri"] = "https://github.com/rubyatscale/visualize_packs/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 - spec.executables << 'visualize_packs' + spec.executables << "visualize_packs" # Specify which files should be added to the gem when it is released. - spec.files = Dir['README.md', 'lib/**/*', "bin/**/*"] - spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 3.3' + spec.files = Dir["README.md", "lib/**/*", "bin/**/*"] + spec.require_paths = ["lib"] + spec.required_ruby_version = ">= 3.3" - spec.add_dependency 'bigdecimal' - spec.add_development_dependency 'bundler' + spec.add_dependency "bigdecimal" + spec.add_development_dependency "bundler" spec.add_development_dependency "rspec", "~> 3.12" - spec.add_development_dependency 'sorbet' - spec.add_development_dependency 'tapioca' - - spec.add_dependency 'packs-specification' - spec.add_dependency 'parse_packwerk', '>= 0.20.0' - spec.add_dependency 'sorbet-runtime' + spec.add_development_dependency "rubocop-gusto" + spec.add_development_dependency "sorbet" + spec.add_development_dependency "tapioca" + spec.add_dependency "packs-specification" + spec.add_dependency "parse_packwerk", ">= 0.20.0" + spec.add_dependency "sorbet-runtime" end