Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Refactor ruby code based on AST
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
flyerhzm
October 18, 2015
Programming
4.3k
4
Share
Refactor ruby code based on AST
flyerhzm
October 18, 2015
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
360
Find and Replace Code based on AST
flyerhzm
0
480
Rails Performance Tips
flyerhzm
0
1.4k
基于AST的代码优化
flyerhzm
10
900
Write ruby code to change ruby code
flyerhzm
5
3.8k
Building Asynchronous APIs
flyerhzm
25
9.1k
构建异步API服务
flyerhzm
19
7.4k
JRuby @ OpenFeint
flyerhzm
23
3.4k
Other Decks in Programming
See All in Programming
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
390
飯MCP
yusukebe
0
510
GitHubCopilotCLIをはじめよう.pdf
htkym
0
150
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
490
Alternatives to JPA 2026
debop
0
110
Kingdom of the Machine
yui_knk
2
320
Don't Prompt Harder, Structure Better
kitasuke
0
760
iOS機能開発のAI環境と起きた変化
ryunakayama
0
180
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.4k
Swift Concurrency Type System
inamiy
0
530
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
940
Google Nest CamとApple Vision frameworkと猫🐈🐈⬛ / onishi50
yutailang0119
0
110
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
260
The SEO Collaboration Effect
kristinabergwall1
0
420
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.8k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
260
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
Facilitating Awesome Meetings
lara
57
6.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Marketing to machines
jonoalderson
1
5.2k
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