From c31e0a6be53a0303240d93db8650b8a363cb0343 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sat, 13 Jan 2024 11:54:53 +0000 Subject: [PATCH 1/2] Allow for OK messages on STDERR in precious config --- precious.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/precious.toml b/precious.toml index 166d54e..c3634e2 100644 --- a/precious.toml +++ b/precious.toml @@ -40,6 +40,7 @@ cmd = [ "perl", "-Ilib", "script/perlimports" ] lint_flags = ["--lint" ] tidy_flags = ["-i" ] ok_exit_codes = 0 +ignore_stderr = [".* OK"] [commands.perltidy] type = "both" From 70b8860c84ccaaae65eba90a128b6a0a4330f77a Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Fri, 12 Jan 2024 20:20:15 -0500 Subject: [PATCH 2/2] Don't log a non-JSON message to STDERR on linting success when --json is enabled The message on STDERR was breaking nvim-lint and it's also weird. --- lib/App/perlimports/CLI.pm | 4 ++-- t/cli.t | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/App/perlimports/CLI.pm b/lib/App/perlimports/CLI.pm index d8f213e..1c1ff48 100644 --- a/lib/App/perlimports/CLI.pm +++ b/lib/App/perlimports/CLI.pm @@ -482,10 +482,10 @@ FILENAME: return $pi_doc->linter_success; } ); - if ($linter_success) { + if ( $linter_success && !$self->_json ) { $logger->error( $filename . ' OK' ); } - else { + elsif ( !$linter_success ) { $exit_code = 1; } next FILENAME; diff --git a/t/cli.t b/t/cli.t index 8fbad5e..1b8385f 100644 --- a/t/cli.t +++ b/t/cli.t @@ -174,6 +174,22 @@ subtest '--lint success' => sub { is( $exit, 0, 'exit code is success' ); }; +subtest '--lint --json success' => sub { + local @ARGV = ( + '--lint', + '--json', + '--no-config-file', + '-f' => 'test-data/lint-success.pl', + ); + my $cli = App::perlimports::CLI->new; + my ( $stdout, $stderr, $exit ) = capture { + $cli->run; + }; + is( $stderr, q{}, 'success message on STDERR' ); + is( $stdout, q{}, 'no STDOUT' ); + is( $exit, 0, 'exit code is success' ); +}; + subtest '--lint failure import args' => sub { local @ARGV = ( '--lint',