Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't log a non-JSON message to STDERR on linting success when --json is enabled #107

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions precious.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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