Kang-min Liu // @gugod
LINE Fukuoka
YAPC Tokyo
自動修復?
PPI で
コードを
変更
Perl5 code を DOM にする
$doc = PPI::Document->new('Module.pm');
$doc->prune('PPI::Token::Comment');
$doc->save('Module.pm');
# ArrarRef[ PPI::Element ] | undef
$elements = $doc->find('PPI::Token::Whitespace');
# ArrarRef[ PPI::Element ] | undef
$elements = $doc->find(sub {
$_[1]->isa('PPI::Statement::Sub')
&& $_[1]->name eq 'hoge'
});
# PPI::Element | undef
$element = $doc->find_first(sub {
$_[1]->isa('PPI::Token::Symbol')
&& $_[1]->content eq '$hoge'
});
remove
)if ($found = $doc->find(...)) {
for my $elem (@$found) {
$elem->remove;
}
}
insert_*
)
$new_elem = ...; # 作る
$elem = $doc->find_first(...);
$elem->insert_before( $new_elem );
$elem->insert_after( $new_elem );
my $doc2 = PPI::Document->new(\$code_str);
my @new_elems = $doc2->children;
my $e = $doc->find_first(...);
for (@new_elems) {
$_->remove; # cut
$e->insert_before($_); # paste
}
$e のまえに paste
$bug = $doc->find( ??? )
eval "print $foo"; # not ok
eval { print $foo }; # ok
my $foo = $baz if $bar; #not ok
my $foo = $baz unless $bar; #not ok
our $foo = $baz for @list; #not ok
local $foo = $baz foreach @list; #not ok
code review は
bot がしてくれて
良いやん
CI で code review しましょう
# .reviewdog.yml
runner:
perlcritic:
cmd: perlcritic --profile .perlcriticrc --verbose 1 *.psgi lib/
errorformat:
- "%f:%l:%c:%m"
name: perlcritic
Docker Image: https://hub.docker.com/r/gugod/perlcritic-reviewdog
Drone CI に使用可能
bot が
修正してくれません ?
do_this();;
semi-colons 多すぎ / empty statements.# A
$n = scalar @arr;
# B
$n = @arr;
# A
@a = @{[ "foo", "bar", foo() ]};
# B
@a = ("foo", "bar", foo());
$bugs = $doc->find( ... )
ご清聴
ありがとう
ございました