Perl::Lint - Yet Another 
Perl Source Code Linter 
http://bit.ly/1p5HdSA 
@moznion
VOTE ME!
SEE ALSO 
Perlの静的解析入門と 
Perlリファクタリングツール 
App::PRTのご紹介 
@hitode909 
! 
Day 2, 多目的教室3, 16:00
@moznion
@moznion 
@hitode909
Perl::Lint 
! https://github.com/moznion/Perl-Lint 
  
https://metacpan.org/release/MOZNION/Perl- 
Lint-0.01_01 (<= UNDERD...
Perl::Lint 
! https://github.com/moznion/Perl-Lint 
  
https://metacpan.org/release/MOZNION/Perl- 
Lint-0.01_02 (<= UNDERD...
What is 
Perl::Lint?
A. Source Code Linter 
for Perl
Yes, It’s like… 
Perl:: 
http://bit.ly/1l5HrYX
Are you using 
Perl::Critic? http://bit.ly/1pfMxCW
What is 
Perl::Critic?
A. Source Code Linter 
for Perl
Wait!!
What is 
Source Code 
Linter???
A. Analyzes the 
source code and 
detects the causes 
of bugs
Search 
and 
Destroy 
http://bit.ly/1AT3Bl3
Concretely…
There are five bad things
There are five bad things
There are five bad things
There are five bad things
There are five bad things
There are five bad things
It was fun?
Is this what I think it is?
It’s just CODE REVIEW?
But do you think human 
should do the such code 
review?
Human should work 
more creative
It seems possible to 
check by computer
There are five bad things
And probably 
human overlooks
Hard to Understand Code
Hard to Understand Code 
Destroy!
Hard to Understand Code 
Easy to review
Do you like clean code, 
and why?
Readable code 
! 
! 
Reviewable code
Readable code 
≒ 
! 
! 
Reviewable code
=> Maintainable!!
Maintainable code 
will be growing up 
along maintainable
Humans can focus on 
creative work
Okay, 
Make maintainable code 
by computer!
And then source code 
linter was appeared 
(1979 for C)
Now; 
js-lint, find-bugs, 
rubocop, etc…
And language 
processors: 
Go, Scala and etc.
Does Perl have?
Perl::Critic is awesome!
Perl::Critic checks 
the code conform 
to PBP style or not
Benefit to analyze 
code by computer
He don’t grumble
He is 
inexhaustible
He don’t take a mistake
He is fast 
(in many cases)
And can automation
Cost of human: HIGH 
! 
Cost of computer: LOW
Cost of human: HIGH 
! 
Cost of computer: LOW 
Good!!
Got it.
But… 
If there is Perl::Critic, 
Is Perl::Lint don’t need?
Perl::Critic is awesome 
but a little slow
In large project, 
It takes 3 minutes 
to run only Perl::Critic
How do you spend in 
meantime?
Coffee? 
How do you spend in 
meantime?
Coffee? 
Chat? 
How do you spend in 
meantime?
Coffee? 
Nap? Chat? 
How do you spend in 
meantime?
Coffee? 
Swing Copters? 
Nap? Chat? 
How do you spend in 
meantime?
Life is too short, 
so let’s accelerate!!
Rate [num/sec] 
100 
75 
50 
25 
0 
97 
18 
Perl::Critic Perl::Lint
Rate [num/sec] 
100 
75 
About 50 
400% increase 
25 
0 
97 
18 
Perl::Critic Perl::Lint
Yeah!!!! 
I'll show you all my tricks
A little break
Background that led to 
the development
This project receive 
TPF grant
Do you know 
TPF grant?
Nozaki-san and 
Maki-san (@lestrrat-san) 
are people in a high 
position of TPF grant
Maki-san「日本人がトップになっ 
たのに日本から1つもProposal出な 
いのちょっとアレじゃない?」▼ 
me「そうですなあ」▼ 
Maki-san「moznion出してよ」▼ 
me「!!!!!」▼
Time flies everything 
goes…
Perl::Lint!!!!
Let’s apply!!!
Return to our subject…
How do we do 
static analyzing for Perl?
Enough!
Joke :p
Two major methods 
- Evaluate Token 
- Evaluate AST
Two major methods 
- Evaluate Token 
- Evaluate AST
Tools - PPI - Compiler::Lexer
Tools - PPI - Compiler::Lexer
What is Compiler::Lexer?
*Very Fast* tokenizer 
made of C++
Compiler::Lexer is fast 
⇛ Perl::Lint is fast!
And others: 
Compiler::Parser, 
C::CodeGenerator::LLVM, 
etc… 
@goccy54++
Example of tokens 
that is generated by 
Compiler::Lexer
my $foo;
my $foo;
Points
Use these tokens 
to analyze
Enough!
Architecture of Perl::Lint
Top Level 
+args 
+site_policies 
+lint 
+lint_string 
Policies 
+evaluate 
1 
Filters 
+filter 
1 
1 .. * 
1 .. *
Simple and Easy!
Policies
Each policies are 
isolated
Easy to make 
your own policy
Samples
*** CAUTION *** 
A lot of bad 
code are here. 
Close your eyes.
@P::L::P::Miscellanea::ProhibitTies
@P::L::P::Miscellanea::ProhibitTies 
Check type
@P::L::P::Miscellanea::ProhibitTies 
Check data
アッ
Feature of 
Implementation 
and Bad Know-hows
Use C-Style for()
Use C-Style for() 
But PBP prohibit it!!
Use List::Util::any 
instead of grep
Don’t use regex, 
compare by eq in series
Or use hash 
…
Function calling 
is almost gone.
Use simple parts 
e.g. raw-bless, POPO
Filtering mechanism
Perl::Critic’s 
default rule system 
is a bit difficult…
Yes, I know, 
perlcriticrc can 
adjust them. 
But too much hustle
Perl::Lint checks 
the all of policies 
as default
And you can filter 
any policies as you like
Filter by `ignore`
Filter by `filter`
Yes, of course 
you can deny 
the all of policies :)
You can define 
your own filter
e.g.
And Perl::Lint provides 
default policies
For Perl::Critic users ;)
These are features 
of Perl::Lint
But installation is such a 
hassle!
Perl::Lint 
Playground 
http://perl-lint.moznion.net
You can try!
Meaning to publish 
Playground
It makes easy to get 
feedback
Motivation ➚
Publish the Playground 
is looking good!
Future works
Implement the all of 
policies…
## no lint
Module for testing 
(Like a Test::Perl::Critic)
Cooperate with GitHub 
(Like a Coveralls)
Inject the result 
into code as TODO 
comment 
(inspired by rubocop)
As you see, 
Perl::Lint is 
under development
SEGV, ABRT, etc…
I’m looking for 
contributors!
DEMO
Any Questions?
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Perl::Lint - Yet Another Perl Source Code Linter
Upcoming SlideShare
Loading in …5
×

Perl::Lint - Yet Another Perl Source Code Linter

2,146 views
2,036 views

Published on

YAPC::Asia 2014
Talking about Perl::Lint

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,146
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Perl::Lint - Yet Another Perl Source Code Linter

  1. 1. Perl::Lint - Yet Another Perl Source Code Linter http://bit.ly/1p5HdSA @moznion
  2. 2. VOTE ME!
  3. 3. SEE ALSO Perlの静的解析入門と Perlリファクタリングツール App::PRTのご紹介 @hitode909 ! Day 2, 多目的教室3, 16:00
  4. 4. @moznion
  5. 5. @moznion @hitode909
  6. 6. Perl::Lint ! https://github.com/moznion/Perl-Lint   https://metacpan.org/release/MOZNION/Perl- Lint-0.01_01 (<= UNDERDEVELOPMENT!!!)
  7. 7. Perl::Lint ! https://github.com/moznion/Perl-Lint   https://metacpan.org/release/MOZNION/Perl- Lint-0.01_02 (<= UNDERDEVELOPMENT!!!)
  8. 8. What is Perl::Lint?
  9. 9. A. Source Code Linter for Perl
  10. 10. Yes, It’s like… Perl:: http://bit.ly/1l5HrYX
  11. 11. Are you using Perl::Critic? http://bit.ly/1pfMxCW
  12. 12. What is Perl::Critic?
  13. 13. A. Source Code Linter for Perl
  14. 14. Wait!!
  15. 15. What is Source Code Linter???
  16. 16. A. Analyzes the source code and detects the causes of bugs
  17. 17. Search and Destroy http://bit.ly/1AT3Bl3
  18. 18. Concretely…
  19. 19. There are five bad things
  20. 20. There are five bad things
  21. 21. There are five bad things
  22. 22. There are five bad things
  23. 23. There are five bad things
  24. 24. There are five bad things
  25. 25. It was fun?
  26. 26. Is this what I think it is?
  27. 27. It’s just CODE REVIEW?
  28. 28. But do you think human should do the such code review?
  29. 29. Human should work more creative
  30. 30. It seems possible to check by computer
  31. 31. There are five bad things
  32. 32. And probably human overlooks
  33. 33. Hard to Understand Code
  34. 34. Hard to Understand Code Destroy!
  35. 35. Hard to Understand Code Easy to review
  36. 36. Do you like clean code, and why?
  37. 37. Readable code ! ! Reviewable code
  38. 38. Readable code ≒ ! ! Reviewable code
  39. 39. => Maintainable!!
  40. 40. Maintainable code will be growing up along maintainable
  41. 41. Humans can focus on creative work
  42. 42. Okay, Make maintainable code by computer!
  43. 43. And then source code linter was appeared (1979 for C)
  44. 44. Now; js-lint, find-bugs, rubocop, etc…
  45. 45. And language processors: Go, Scala and etc.
  46. 46. Does Perl have?
  47. 47. Perl::Critic is awesome!
  48. 48. Perl::Critic checks the code conform to PBP style or not
  49. 49. Benefit to analyze code by computer
  50. 50. He don’t grumble
  51. 51. He is inexhaustible
  52. 52. He don’t take a mistake
  53. 53. He is fast (in many cases)
  54. 54. And can automation
  55. 55. Cost of human: HIGH ! Cost of computer: LOW
  56. 56. Cost of human: HIGH ! Cost of computer: LOW Good!!
  57. 57. Got it.
  58. 58. But… If there is Perl::Critic, Is Perl::Lint don’t need?
  59. 59. Perl::Critic is awesome but a little slow
  60. 60. In large project, It takes 3 minutes to run only Perl::Critic
  61. 61. How do you spend in meantime?
  62. 62. Coffee? How do you spend in meantime?
  63. 63. Coffee? Chat? How do you spend in meantime?
  64. 64. Coffee? Nap? Chat? How do you spend in meantime?
  65. 65. Coffee? Swing Copters? Nap? Chat? How do you spend in meantime?
  66. 66. Life is too short, so let’s accelerate!!
  67. 67. Rate [num/sec] 100 75 50 25 0 97 18 Perl::Critic Perl::Lint
  68. 68. Rate [num/sec] 100 75 About 50 400% increase 25 0 97 18 Perl::Critic Perl::Lint
  69. 69. Yeah!!!! I'll show you all my tricks
  70. 70. A little break
  71. 71. Background that led to the development
  72. 72. This project receive TPF grant
  73. 73. Do you know TPF grant?
  74. 74. Nozaki-san and Maki-san (@lestrrat-san) are people in a high position of TPF grant
  75. 75. Maki-san「日本人がトップになっ たのに日本から1つもProposal出な いのちょっとアレじゃない?」▼ me「そうですなあ」▼ Maki-san「moznion出してよ」▼ me「!!!!!」▼
  76. 76. Time flies everything goes…
  77. 77. Perl::Lint!!!!
  78. 78. Let’s apply!!!
  79. 79. Return to our subject…
  80. 80. How do we do static analyzing for Perl?
  81. 81. Enough!
  82. 82. Joke :p
  83. 83. Two major methods - Evaluate Token - Evaluate AST
  84. 84. Two major methods - Evaluate Token - Evaluate AST
  85. 85. Tools - PPI - Compiler::Lexer
  86. 86. Tools - PPI - Compiler::Lexer
  87. 87. What is Compiler::Lexer?
  88. 88. *Very Fast* tokenizer made of C++
  89. 89. Compiler::Lexer is fast ⇛ Perl::Lint is fast!
  90. 90. And others: Compiler::Parser, C::CodeGenerator::LLVM, etc… @goccy54++
  91. 91. Example of tokens that is generated by Compiler::Lexer
  92. 92. my $foo;
  93. 93. my $foo;
  94. 94. Points
  95. 95. Use these tokens to analyze
  96. 96. Enough!
  97. 97. Architecture of Perl::Lint
  98. 98. Top Level +args +site_policies +lint +lint_string Policies +evaluate 1 Filters +filter 1 1 .. * 1 .. *
  99. 99. Simple and Easy!
  100. 100. Policies
  101. 101. Each policies are isolated
  102. 102. Easy to make your own policy
  103. 103. Samples
  104. 104. *** CAUTION *** A lot of bad code are here. Close your eyes.
  105. 105. @P::L::P::Miscellanea::ProhibitTies
  106. 106. @P::L::P::Miscellanea::ProhibitTies Check type
  107. 107. @P::L::P::Miscellanea::ProhibitTies Check data
  108. 108. アッ
  109. 109. Feature of Implementation and Bad Know-hows
  110. 110. Use C-Style for()
  111. 111. Use C-Style for() But PBP prohibit it!!
  112. 112. Use List::Util::any instead of grep
  113. 113. Don’t use regex, compare by eq in series
  114. 114. Or use hash …
  115. 115. Function calling is almost gone.
  116. 116. Use simple parts e.g. raw-bless, POPO
  117. 117. Filtering mechanism
  118. 118. Perl::Critic’s default rule system is a bit difficult…
  119. 119. Yes, I know, perlcriticrc can adjust them. But too much hustle
  120. 120. Perl::Lint checks the all of policies as default
  121. 121. And you can filter any policies as you like
  122. 122. Filter by `ignore`
  123. 123. Filter by `filter`
  124. 124. Yes, of course you can deny the all of policies :)
  125. 125. You can define your own filter
  126. 126. e.g.
  127. 127. And Perl::Lint provides default policies
  128. 128. For Perl::Critic users ;)
  129. 129. These are features of Perl::Lint
  130. 130. But installation is such a hassle!
  131. 131. Perl::Lint Playground http://perl-lint.moznion.net
  132. 132. You can try!
  133. 133. Meaning to publish Playground
  134. 134. It makes easy to get feedback
  135. 135. Motivation ➚
  136. 136. Publish the Playground is looking good!
  137. 137. Future works
  138. 138. Implement the all of policies…
  139. 139. ## no lint
  140. 140. Module for testing (Like a Test::Perl::Critic)
  141. 141. Cooperate with GitHub (Like a Coveralls)
  142. 142. Inject the result into code as TODO comment (inspired by rubocop)
  143. 143. As you see, Perl::Lint is under development
  144. 144. SEGV, ABRT, etc…
  145. 145. I’m looking for contributors!
  146. 146. DEMO
  147. 147. Any Questions?

×