例如,Ruby中有一个-c
选项,在运行代码之前判断语法:
C:\>ruby --help
Usage: ruby [switches] [--] [programfile] [arguments]
-c check syntax only
C:\>ruby -c C:\foo\ruby\my_source_code.rb
Syntax OK
Go中有没有类似的功能?
另外,Ruby的一个例子只是因为我在Ruby中了解它.不是因为玩拖拉之类的.
例如,Ruby中有一个-c
选项,在运行代码之前判断语法:
C:\>ruby --help
Usage: ruby [switches] [--] [programfile] [arguments]
-c check syntax only
C:\>ruby -c C:\foo\ruby\my_source_code.rb
Syntax OK
Go中有没有类似的功能?
另外,Ruby的一个例子只是因为我在Ruby中了解它.不是因为玩拖拉之类的.
您可以使用gofmt
判断语法错误,而无需实际构建项目.
gofmt -e my_file.go > /dev/null
以后可以使用$?bash变量,返回代码0表示成功,2表示语法判断/dev/null将吃掉代码,但错误将转到stderr
-e
选项定义为:
报告所有错误(不只是不同行上的前10个错误)
gofmt --help usage: gofmt [flags] [path ...] -comments=true: print comments -cpuprofile="": write cpu profile to this file -d=false: display diffs instead of rewriting files -e=false: 报告所有错误(不只是不同行上的前10个错误) -l=false: list files whose formatting differs from gofmt's -r="": rewrite rule (e.g., 'a[b:len(a)] -> a[b:]') -s=false: simplify code -tabs=true: indent with tabs -tabwidth=8: tab width -w=false: write result to (source) file instead of stdout