Write ruby code to change ruby code Richard Huang Xinmin Labs
About Me Founder at Xinmin Labs Full Stack Developer Open Source Enthusiast @flyerhzm
Hey, let’s use rspec new syntax for project A Yes, sure, I love the rspec new syntax
Hey, let’s use rspec new syntax for project B Hmmm…ok
Hey, let’s use rspec new syntax for project C Oh, no, I don’t want to repeat it again
Developers love upgrading and refactoring code
Developers hate changing code again and again
Metric Tools • cane - fails your build if code quality thresholds are not met • reek - is a tool that examines Ruby classes, modules and methods and reports any code smells it finds. • rails_best_practices - is a tool to check the quality of rails code. • ……
Tell you what to do, but can’t do for you
IDE • can rename class / method / variable name • can extract methods • can ……
IDE • can’t customize
Based on text
Based on text Replace FactoryGirl.create with create ! $ sed -i '' 's/FactoryGirl.create/create/g' spec/**/*.rb
Based on text Replace FactoryGirl.create with create ! !
Based on text Hard to be accurate ! ! ! !
Based on text Hard to convert complicated cases ! ! ! !
Based on AST
What’s AST AST is short for Abstract Syntax Tree
Why AST It is much more accurate to parse ruby code.