Skip to content

Commit

Permalink
Don't log a non-JSON message to STDERR on linting success when --json…
Browse files Browse the repository at this point in the history
… is enabled

The message on STDERR was breaking nvim-lint and it's also weird.
  • Loading branch information
oalders committed Jan 13, 2024
1 parent c31e0a6 commit 70b8860
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/App/perlimports/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions t/cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 70b8860

Please sign in to comment.