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.4k
Refactor ruby code based on AST
flyerhzm
October 18, 2015
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
120
Find and Replace Code based on AST
flyerhzm
0
180
Rails Performance Tips
flyerhzm
0
1.1k
基于AST的代码优化
flyerhzm
10
730
Write ruby code to change ruby code
flyerhzm
5
3.5k
Building Asynchronous APIs
flyerhzm
25
8.9k
构建异步API服务
flyerhzm
19
7.1k
JRuby @ OpenFeint
flyerhzm
23
3k
Other Decks in Programming
See All in Programming
3 Effective Rules for Success with Signals in Angular
manfredsteyer
PRO
0
120
APIのない大学ログインWebサービスをWKWebViewとJavaScriptでアプリ化した話
akidon0000
1
330
Introduction to GitOps
hwchiu
0
110
ピグパーティにおけるMongoDB CommunityバージョンからAtlasへの移行事例
10969hotaka
0
130
Async Await: Mastering Python's Time-Bending Tricks - EuroPython2024
yanbo
1
290
Webエディタライブラリ 「CodeMirror」から学ぶ Webアプリ開発のテクニック
ryosukeigarashi
0
250
I/O Extended Android in Korea 2024 ~ Whats new in Android development tools
pluu
0
250
AHC035解説
terryu16
0
710
Namespace on read
tagomoris
2
370
DynamoDB コスト最適化っぽいことの基本 with Terraform
kuro_kurorrr
2
250
Rubyのパフォーマンスプロファイリングの改善 / Enhancing performance profiling for Ruby
osyoyu
1
410
日付と正規化
megmogmog1965
0
140
Featured
See All Featured
The Cult of Friendly URLs
andyhume
75
5.9k
Atom: Resistance is Futile
akmur
261
25k
10 Git Anti Patterns You Should be Aware of
lemiorhan
652
58k
GitHub's CSS Performance
jonrohan
1026
450k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
44
4.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
248
12k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
353
29k
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
105
6.8k
Designing the Hi-DPI Web
ddemaree
276
34k
Building Applications with DynamoDB
mza
89
5.8k
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