Is there a way to run go fmt on all files of a git commit only?

agolangf · · 153 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>our review system keeps ask individual file needs go fmt before sending peer review. this is annoying</p> <hr/>**评论:**<br/><br/>: <pre><p>[deleted]</p></pre>marksteve4: <pre><p>this is a corporation. dude</p></pre>carsncode: <pre><p>What does that have to do with it? Just format all your source files.</p></pre>VanPepe: <pre><p>Because you don&#39;t just fmt a giant repo at once in an issue unrelated. You either do it in a dedicated task or step by step.</p> <p>Who would want to review a PR with thousands of files in the diff? </p></pre>carsncode: <pre><p>No one. Who is failing to gofmt the files they change when they change them? Every editor out there will let you format on save. There is no excuse for winding up in a situation where you have thousands of files modified just for gofmt.</p></pre>VanPepe: <pre><p>out of the box not a lot run go fmt by itself. Visual Studio Code is the perfect example. If you don&#39;t have the Go plugin it won&#39;t fmt on its own for you.</p> <p>And running personally i tend to forget it aswell a lot, when I&#39;m not using the on save feature.</p> <p>So yeah there are decent excuses for that.</p></pre>marksteve4: <pre><p>you know these days. internet companies usually have a single repo for a language with all projects in it</p></pre>carsncode: <pre><p>So? Gofmt will only format .go files, and it will only format files in the directory you point it at. Whether or not you use a monorepo is just as irrelevant as whether or not &#34;this is a corporation&#34;.</p></pre>spunt41: <pre><p>Could you use a pre-commit hook? </p> <p>We use the excellent <a href="https://github.com/pre-commit/pre-commit" rel="nofollow">https://github.com/pre-commit/pre-commit</a>, which we&#39;ve configured to run go fmt (and linters, license checks, etc.) before each commit. By default, the pre-commit tool only operates on files which are included in the commit (although I share the perspective of other commenters - go fmt all the things!)</p> <p><a href="https://github.com/dnephin/pre-commit-golang" rel="nofollow">https://github.com/dnephin/pre-commit-golang</a> has some great hooks you can use out of the box, including one for go fmt.</p></pre>ofpiyush: <pre><p>Do it in a dedicated step.</p> <p>Go fmt can&#39;t break your code as it parses the source, builds AST and builds the source back.</p> <p>i.e. review isn&#39;t required on that step.</p> <p>Merge your master back into all your feature branches.</p> <p>Source: We&#39;re also a company.</p> <p>If you really want, point go fmt at individual files...</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:701969077

153 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传