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
210
Find and Replace Code based on AST
flyerhzm
0
300
Rails Performance Tips
flyerhzm
0
1.2k
基于AST的代码优化
flyerhzm
10
830
Write ruby code to change ruby code
flyerhzm
5
3.6k
Building Asynchronous APIs
flyerhzm
25
9k
构建异步API服务
flyerhzm
19
7.2k
JRuby @ OpenFeint
flyerhzm
23
3.2k
Other Decks in Programming
See All in Programming
MLOps Japan 勉強会 #52 - 特徴量を言語を越えて一貫して管理する, 『特徴量ドリブン』な MLOps の実現への試み
taniiicom
2
570
Proxmoxをまとめて管理できるコンソール作ってみました
karugamo
1
410
AI時代のリアーキテクチャ戦略 / Re-architecture Strategy in the AI Era
dachi023
0
190
Investigating Multithreaded PostgreSQL
macdice
0
150
Feature Flag 自動お掃除のための TypeScript プログラム変換
azrsh
PRO
4
630
TSConfigからTypeScriptの世界を覗く
planck16
2
1.3k
Parallel::Pipesの紹介
skaji
2
870
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
1
160
TVer iOSチームの共通認識の作り方 - Findy Job LT iOSアプリ開発の裏側 開発組織が向き合う課題とこれから
techtver
PRO
0
710
ワイがおすすめする新潟の食 / 20250530phpconf-niigata-eve
kasacchiful
0
190
iOSアプリ開発もLLMで自動運転する
hiragram
6
2.1k
〜可視化からアクセス制御まで〜 BigQuery×Looker Studioで コスト管理とデータソース認証制御する方法
cuebic9bic
1
270
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
42
2.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
14
1.5k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
123
52k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.8k
Side Projects
sachag
454
42k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Into the Great Unknown - MozCon
thekraken
39
1.8k
For a Future-Friendly Web
brad_frost
178
9.7k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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