Koha-QA

 view release on metacpan or  search on metacpan

lib/Koha/QA/Tidy/TT.pm  view on Meta::CPAN

package Koha::QA::Tidy::TT;

use Modern::Perl;
use base 'Koha::QA::Base';
use File::ShareDir qw(dist_file dist_dir);
use File::Slurp    qw(read_file write_file);
use File::Spec;
use IPC::Run3;

=head1 NAME

Koha::QA::Tidy::TT - Centralized Template Toolkit tidiness checking using prettier

=head1 SYNOPSIS

  use Koha::QA::Tidy::TT;

  # With a file
  my $checker = Koha::QA::Tidy::TT->new({file => $file, prettierrc => $prettierrc});

  # Or with content directly
  my $checker = Koha::QA::Tidy::TT->new({content => $file_content, prettierrc => $prettierrc});

  my $is_tidy = $checker->check;
  my @errors = $checker->errors;

  # Return the tidy version
  my $success = $checker->fix;

=head1 DESCRIPTION

This module provides centralized Template Toolkit tidiness checking
and formatting using prettier with the @koha-community/prettier-plugin-template-toolkit.

=head1 METHODS

=head2 new

  my $checker = Koha::QA::Tidy::TT->new({file => $file, prettierrc => $prettierrc});

Creates a new Tidy::TT instance.

Arguments:
  - prettierrc: Optional path to .prettierrc.js file (default: .prettierrc.js)

=head2 check

  my $is_tidy = $checker->check;

Checks if a Template Toolkit file is tidy by comparing the original content with
the output from prettier.

=head2 errors

  my @errors = $checker->errors;

Returns array of error hashrefs, each with:
  - error: the error type (tidy_tt, no_prettierrc, tidy_tt_empty_output, tidy_tt_prettier_failed)

=head2 fix

  my $output = $checker->fix;



( run in 0.780 second using v1.01-cache-2.11-cpan-eb134014566 )