doubangzhang6992 2015-10-18 10:37
浏览 659
已采纳

如何使用重写规则在gofmt工具中用空格替换制表符?

gofmt command supports -r flag to use rewrite rule during formatting the code. How to use it to replace tabs indentation with the spaces indentation?

  • 写回答

2条回答 默认 最新

  • dsn46282 2015-10-18 17:33
    关注

    Command gofmt

    The rewrite rule specified with the -r flag must be a string of the form:

    pattern -> replacement
    

    Both pattern and replacement must be valid Go expressions.

    The tab and space characters are not valid Go expressions. It won't work.

    The Go Programming Language

    Alan A. A. Donovan & Brian W. Kernighan

    ISBN: 978-0134190440

    gopl.io

    Go takes a strong stance on code formatting. The gofmt tool rewrites code into the standard format, and the go tool’s fmt subcommand applies gofmt to all the files in the specified package, or the ones in the current directory by default. All Go source files in the book have been run through gofmt, and you should get into the habit of doing the same for your own code. Declaring a standard format by fiat eliminates a lot of pointless debate about trivia and, more importantly, enables a variety of automated source code transformations that would be infeasible if arbitrary formatting were allowed.

    Always use gofmt code formatting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备