Koha-QA

 view release on metacpan or  search on metacpan

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

package Koha::QA::Tidy::JS;

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

=head1 NAME

Koha::QA::Tidy::JS - Centralized JavaScript/TypeScript tidiness checking using prettier

=head1 SYNOPSIS

  use Koha::QA::Tidy::JS;

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

  # Or with content directly
  my $checker = Koha::QA::Tidy::JS->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 JavaScript/TypeScript/Vue tidiness checking
and formatting using prettier.

=head1 METHODS

=head2 new

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

Creates a new Tidy::JS instance.

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

=head2 check

  my $is_tidy = $checker->check;

Checks if a JavaScript 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_js, no_prettierrc, tidy_js_empty_output, tidy_js_prettier_failed)

=head2 fix

  my $output = $checker->fix;

Runs prettier on the file and returns the tidied content without modifying the file.



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