Skip to content

Commit

Permalink
Implement packwerk show-offenses command
Browse files Browse the repository at this point in the history
  • Loading branch information
davidstosik committed Mar 30, 2023
1 parent d1ac0ea commit 15cfab5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def execute_command(args)
output_result(parse_run(args).check)
when "update-todo", "update"
output_result(parse_run(args).update_todo)
when "show-offenses", "show"
output_result(parse_run(args).show_offenses)
when "validate"
validate(args)
when "version"
Expand Down Expand Up @@ -118,6 +120,7 @@ def usage
Subcommands:
init - set up packwerk
check - run all checks
show-offenses - displays all offenses
update-todo - update package_todo.yml files
validate - verify integrity of packwerk and package configuration
version - output packwerk version
Expand Down
18 changes: 14 additions & 4 deletions lib/packwerk/parse_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def update_todo
Cli::Result.new(message: message, status: offense_collection.errors.empty?)
end

sig { returns(Cli::Result) }
def show_offenses
run_context = RunContext.from_configuration(@configuration)
all_offenses = find_offenses(run_context)

message = @offenses_formatter.show_offenses(all_offenses)

Cli::Result.new(message: message, status: true)
end

sig { returns(Cli::Result) }
def check
run_context = RunContext.from_configuration(@configuration)
Expand Down Expand Up @@ -93,8 +103,8 @@ def check
).returns(T::Array[Offense])
end
def find_offenses(run_context, &block)
offenses = T.let([], T::Array[Offense])
process_file = if block_given?
all_offenses = T.let([], T::Array[Offense])
process_file = if block
T.let(proc do |relative_file|
run_context.process_file(relative_file: relative_file).tap(&block)
end, ProcessFileProc)
Expand All @@ -105,14 +115,14 @@ def find_offenses(run_context, &block)
end

@progress_formatter.started_inspection(@relative_file_set) do
offenses = if @configuration.parallel?
all_offenses = if @configuration.parallel?
Parallel.flat_map(@relative_file_set, &process_file)
else
serial_find_offenses(&process_file)
end
end

offenses
all_offenses
end

sig { params(block: ProcessFileProc).returns(T::Array[Offense]) }
Expand Down

0 comments on commit 15cfab5

Please sign in to comment.