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.6k
Refactor ruby code based on AST
flyerhzm
October 18, 2015
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
160
Find and Replace Code based on AST
flyerhzm
0
240
Rails Performance Tips
flyerhzm
0
1.2k
基于AST的代码优化
flyerhzm
10
800
Write ruby code to change ruby code
flyerhzm
5
3.5k
Building Asynchronous APIs
flyerhzm
25
8.9k
构建异步API服务
flyerhzm
19
7.2k
JRuby @ OpenFeint
flyerhzm
23
3.1k
Other Decks in Programming
See All in Programming
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
4
250
2025.01.17_Sansan × DMM.swift
riofujimon
2
560
asdf-ecspresso作って 友達が増えた話 / Fujiwara Tech Conference 2025
koluku
0
1.4k
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
280
functionalなアプローチで動的要素を排除する
ryopeko
1
210
ドメインイベント増えすぎ問題
h0r15h0
2
570
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
180
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
php-conference-japan-2024
tasuku43
0
430
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.8k
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
Featured
See All Featured
Navigating Team Friction
lara
183
15k
We Have a Design System, Now What?
morganepeng
51
7.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Documentation Writing (for coders)
carmenintech
67
4.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Designing for humans not robots
tammielis
250
25k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
The Invisible Side of Design
smashingmag
299
50k
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