Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Refactor ruby code based on AST
flyerhzm
October 18, 2015
Programming
4
2.9k
Refactor ruby code based on AST
flyerhzm
October 18, 2015
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
Rails Performance Tips
flyerhzm
0
1k
基于AST的代码优化
flyerhzm
10
580
Write ruby code to change ruby code
flyerhzm
5
3.2k
Building Asynchronous APIs
flyerhzm
25
8.8k
构建异步API服务
flyerhzm
19
6.8k
JRuby @ OpenFeint
flyerhzm
23
2.8k
Other Decks in Programming
See All in Programming
Hatena Engineer Seminar #23「新卒研修で気軽に『ありがとう』を伝え合える Slack アプリを開発した話」
slashnephy
0
410
Functional Fun in Kotlin
nomisrev
1
130
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
650
CPU/GPU高速化セミナー 浮動小数点から文字列への高速変換の論文を読んでみた / cpugpu acceleration seminar 20230201
fixstars
0
110
存在しないアセットへの参照と 未公開アセットでのネタバレに どう立ち向かうか / How to prevent missing assets and spoilers by assets
orgachem
0
210
Software Architecture
hschwentner
3
1.1k
Amebaブログの会員画面システム刷新の道程
ryotasugawara
1
260
domain層のモジュール化 / MoT TechTalk #15
mot_techtalk
0
160
フロントエンドで学んだことをデータ分析で使ってみた話
daichi_igarashi
0
190
監視せなあかんし、五大紙だけにオオカミってな🐺🐺🐺🐺🐺
sadnessojisan
3
1.6k
Workshop on Jetpack compose
aldefy
0
140
OIDC仕様に準拠した Makuake ID連携基盤構築の裏側
ymtdzzz
0
610
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
69
7.6k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
13
5.5k
Optimizing for Happiness
mojombo
365
64k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
38
3.6k
The Invisible Customer
myddelton
113
12k
Music & Morning Musume
bryan
37
4.7k
Designing Experiences People Love
moore
130
22k
BBQ
matthewcrist
75
8.1k
Making Projects Easy
brettharned
102
4.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
226
130k
Embracing the Ebb and Flow
colly
75
3.6k
Into the Great Unknown - MozCon
thekraken
2
310
Transcript
Refactor ruby code based on AST Richard Huang @flyerhzm
None
None
Problem
Code Review
None
None
Repeat, Repeat, Repeat
None
None
Any solution?
CodeClimate
None
None
PullReview
How they work?
CodeClimate / PullReview flay flog brakeman rails_best_practices … Open Source
Gems
flay analyzes code for structural similarities
None
flog reports the most tortured code
None
brakeman a static analysis security vulnerability scanner for rails applications
None
rails_best_practices checks the quality of rails code
None
How they work?
flay flog brakeman rails_best_practices … ruby_parser ripper parser ruby parser
=> AST CodeClimate / PullReview
ParseTree • First ruby parser • Not support ruby 1.9
or newer
ruby_parser • Most popular ruby parser • Output is 100%
equivalent to ParseTree
None
None
ActiveRecord::Base belongs_to :user touch :archived_at def archive
ripper • Ruby built-in parser • Support ruby
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
parser • A new ruby parser • Support rewriting
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
Good enough?
Auto rewrite!
transpec the rspec syntax converter
None
None
None
None
rubocop static code analyzer based on the community ruby style
guide
None
None
transpec rubocop parser
None
Generic Solution
Synvert converts ruby code to better syntax
DSL • within_file / within_files • with_node / within_node •
if_exist_node / unless_exist_node • append / insert / insert_after / replace_with / remove • ……
None
None
None
Demo Convert rspec to new syntax Convert rails code from
2.3 to 3.0 Convert rails code from 3.2 to 4.0
Side Project not published yet
None
None
Refs CodeClimate - https://codeclimate.com/ PullReview - https://www.pullreview.com/ flay - https://github.com/seattlerb/flay
flog - https://github.com/seattlerb/flog brakeman - https://github.com/presidentbeef/brakeman rails_best_practices - https://github.com/railsbp/ rails_best_practices
Refs parsetree - https://github.com/seattlerb/parsetree ruby_parser - https://github.com/seattlerb/ruby_parser parser - https://github.com/whitequark/parser
rubocop - https://github.com/bbatsov/rubocop transpec - https://github.com/yujinakayama/transpec synvert - https://github.com/xinminlabs/synvert
Thank You