TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Codemod – A library to assist with large-scale codebase refactoring

42 点作者 pestkranker将近 8 年前

8 条评论

xaedes将近 8 年前
I also like Clang Tools for C++ AST and programmatic refactoring. Much better than regex replace. What exactly is the benefit of Codemod? Too me it seems like a glorified regex replacer, nothing more.<p>Suppose you have a function Foo::bar() and Bar::bar(). You decide to replace Bar::bar() by Bar::foo(). Good look with doing that via regex. Foo::bar() calls will most likely be affected as well. Matching directly on the AST solves this problem by explicitely matching all Bar::bar() calls.<p>What I really want: a language agnostic abstract syntax tree parser, matcher and transformer.<p>AST matchers and Clang refactoring tools: <a href="http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;07&#x2F;29&#x2F;ast-matchers-and-clang-refactoring-tools" rel="nofollow">http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;07&#x2F;29&#x2F;ast-matchers-and-cla...</a><p>Refactoring C++ with Clang with cool examples: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=yuIOGfcOH0k" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=yuIOGfcOH0k</a><p>Clang rename refactoring tool: <a href="https:&#x2F;&#x2F;clang.llvm.org&#x2F;extra&#x2F;clang-rename.html" rel="nofollow">https:&#x2F;&#x2F;clang.llvm.org&#x2F;extra&#x2F;clang-rename.html</a>
Etheryte将近 8 年前
This is nice, but I don&#x27;t see the upside over using the tools provided by the IDE or editor of your choice. Some of the additional flags are interesting, true, but I can&#x27;t really say I&#x27;ve ever felt a need for something like it.
评论 #15085999 未加载
stringham将近 8 年前
I find the idea of <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;jscodeshift" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;jscodeshift</a> to be really useful.<p>I&#x27;ve started writing small scripts using the TypeScript parser as a library to make meaningful improvements in our codebase. Since JavaScript is valid TypeScript syntax the scripts work on both.<p>For example, I wrote a small script to change var to let or const when possible. It uses the AST to check scoping rules and to check if a variable is ever reassigned.<p>Writing scripts like this is way more effective than doing it by hand.
mygosh将近 8 年前
Or just use a language that supports large scale refactoring, say Java, C#, perhaps even C++ if you are careful. I generally don&#x27;t like dynamic languages for large projects exactly because of this. You can&#x27;t safely and quickly do large scale refactorings, a point that will come back and haunt you sooner or later. No matter how good you are or how much care you take, the code will rot significantly more than in Java&#x2F;C# because you just can&#x27;t quickly refactor stuff across the entire codebase, so you won&#x27;t.
jameslk将近 8 年前
I&#x27;d also recommend checking out <a href="https:&#x2F;&#x2F;github.com&#x2F;Yelp&#x2F;undebt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Yelp&#x2F;undebt</a> which is a bit more robust it seems in the search aspect, since it&#x27;s grammar-based instead of regex-based.
评论 #15086573 未加载
pspeter3将近 8 年前
I think this was open sourced earlier but I just discovered it.<p>As a personal anecdote, I&#x27;ve written many ad hoc code mods while working on Luna2 (Asana&#x27;s next framework) and had no idea one of our founders wrote this. He apparently assumed IDEs would just handle this by now.
评论 #15084782 未加载
amenghra将近 8 年前
This code was open sourced in 2008, with a few improvements here and there until 2010.<p>Codemod is great, but there are better tools out there (pfff by facebook, IntelliJ plugins, etc). It&#x27;s too bad the readme doesn&#x27;t do a great job explaining that.
allendoerfer将近 8 年前
Nice project, but a less powerful version of vim&#x27;s :argdo.
评论 #15085088 未加载