How To (Semi-)Automate JavaScript Refactoring
summary
Shows how to automate refactoring by scanning code for repeated patterns, extracting variant tokens with a parser, and applying simple filter scripts or Node stream transforms to template and replace duplicates. Demonstrates using grep/wc and git-history analysis to prioritize files, reports 37 spec failures from changing one brittle line, and claims a project removed 1000 lines in a week and reformatted 700 HTML files in two weeks. Uses JSLint scraping, Ruby and JS parsers (recommend Esprima), and fast set‑intersection for similarity detection.
AI-written summary · about
chapters (18)
- 0:00AUTOMATED REFACTORING
- 1:08NEW FUNCTIONALITY?
- 1:23NOT REFACTORING
- 2:26WHAT'S THIS FUNCTION?
- 2:47SPECS!
- 10:46REMOVED 1000 LINES OF CODE
- 11:471. KNOW YOUR CODE BASE
- 12:00CHOOSE A BROKEN PATTERN TO FIX
- 12:20SCAN CODE BASE WITH grep / awk / ag / ETC
- 14:18PARAMETERIZE THE HARD-CODED
- 14:28CLEAN THE CODE BY HAND
- 14:38WRITE FILTER SCRIPTS
- 15:49REDESIGN
- 16:00STREAMS
- 16:11REFORMATTED
- 20:11JS LINT
- 25:08Wrap function definitions in wrapper functions
- 29:25BAD CODE
related talks
43mMachine Powered Refactoring: Leverage AST's to Push Your Legacy Code (& the Web) Forward
20mThey see me refactorin'. They hatin'
47mComputer, refactor my code!
40mRefactoring large JavaScript codebases
36mThe Secrets of Successful Refactoring
25mManage large refactors with JSCodeShift
58mImproving Quality of JavaScript Code
45mConquering complexity: refactoring JavaScript projects
