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

feature/code-absence; fix missing filename #54

Merged
merged 2 commits into from
Jan 4, 2025
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
25 changes: 24 additions & 1 deletion lib/Zarn/Engine/Source_to_Sink.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,32 @@ package Zarn::Engine::Source_to_Sink {
'rules=s' => \$rules
);


if ($ast && $rules) {
my @absence = grep { $_->{type} && $_->{type} eq 'absence' } $rules->@*;
for my $rule (@absence) {
my $category = $rule -> {category};
my $title = $rule -> {name};
my $message = $rule -> {message};
foreach my $token ($rule -> {sample} -> @*) {
if ($ast->content() !~ m/$token/xms ) {
push @results, {
category => $category,
title => $title,
message => $message,
line_sink => 'n/a',
rowchar_sink => 'n/a',
line_source => 'n/a',
rowchar_source => 'n/a'
};
}
}
}

my @presence = grep { !($_->{type}) || $_->{type} eq 'presence' } $rules->@*;

foreach my $token (@{$ast -> find('PPI::Token') || []}) {
foreach my $rule (@{$rules}) {
foreach my $rule (@presence) {
my @sample = $rule -> {sample} -> @*;
my $category = $rule -> {category};
my $title = $rule -> {name};
Expand Down
2 changes: 1 addition & 1 deletion lib/Zarn/Helper/Rules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ package Zarn::Helper::Rules {
}
}

1;
1;
4 changes: 2 additions & 2 deletions zarn.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
);

if ( !$source ) {
print "\nZarn v0.1.0"

Check failure on line 30 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 30, column 9. See pages 208,278 of PBP.
. "\nCore Commands"
. "\n==============\n"
. "\tCommand Description\n"
Expand Down Expand Up @@ -56,7 +56,7 @@
);

if (@analysis) {
$analysis[0]->{'file'} = $file;
map { $_->{file} = $file } @analysis;

Check failure on line 59 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

"map" used in void context at line 59, column 17. Use a "for" loop instead.
}

push @results, @analysis;
Expand All @@ -72,19 +72,19 @@
my $line_source = $result->{line_source};
my $rowchar_source = $result->{rowchar_source};

print

Check failure on line 75 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 75, column 9. See pages 208,278 of PBP.
"[$category] - FILE:$file \t Potential: $title. \t Dangerous function on line: $line_sink:$rowchar_sink \t Data point possibility controlled: $line_source:$rowchar_source\n";
}

if ($sarif) {
my $sarif_data = Zarn::Helper::Sarif->new(@results);

open( my $output, '>', $sarif ) or croak "Cannot open the $sarif file\n";

Check failure on line 82 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Builtin function called with parentheses at line 82, column 9. See page 13 of PBP.
print $output encode_json($sarif_data);

Check failure on line 83 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

File handle for "print" or "printf" is not braced at line 83, column 9. See page 217 of PBP.

Check failure on line 83 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 83, column 9. See pages 208,278 of PBP.
close($output) or die "Error to close the file\n";

Check failure on line 84 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Builtin function called with parentheses at line 84, column 9. See page 13 of PBP.
}

return 0;
}

main();
main();
Loading