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
flyerhzm
October 18, 2015
Programming
4
3.7k
Refactor ruby code based on AST
flyerhzm
October 18, 2015
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
230
Find and Replace Code based on AST
flyerhzm
0
330
Rails Performance Tips
flyerhzm
0
1.2k
基于AST的代码优化
flyerhzm
10
840
Write ruby code to change ruby code
flyerhzm
5
3.6k
Building Asynchronous APIs
flyerhzm
25
9k
构建异步API服务
flyerhzm
19
7.3k
JRuby @ OpenFeint
flyerhzm
23
3.2k
Other Decks in Programming
See All in Programming
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
1
580
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
48
32k
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
210
Create a website using Spatial Web
akkeylab
0
310
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
610
A2A プロトコルを試してみる
azukiazusa1
2
1.2k
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
530
deno-redisの紹介とJSRパッケージの運用について (toranoana.deno #21)
uki00a
0
150
PipeCDのプラグイン化で目指すところ
warashi
1
180
GoのGenericsによるslice操作との付き合い方
syumai
3
690
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
230
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
340
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
800
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
KATA
mclloyd
30
14k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Optimizing for Happiness
mojombo
379
70k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Unsuck your backbone
ammeep
671
58k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
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