Skip to content

Commit be8c431

Browse files
authored
Merge pull request #18 from gostaticanalysis/fix-template-delims
Fix template delims
2 parents 633e0f2 + b565714 commit be8c431

File tree

8 files changed

+29
-28
lines changed

8 files changed

+29
-28
lines changed

_template/{{.Pkg}}/{{.Pkg}}.go renamed to _template/@@.Pkg@@/@@.Pkg@@.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package {{.Pkg}}
1+
package @@.Pkg@@
22

33
import (
44
"go/ast"
@@ -8,11 +8,11 @@ import (
88
"golang.org/x/tools/go/ast/inspector"
99
)
1010

11-
const doc = "{{.Pkg}} is ..."
11+
const doc = "@@.Pkg@@ is ..."
1212

1313
// Analyzer is ...
1414
var Analyzer = &analysis.Analyzer{
15-
Name: "{{.Pkg}}",
15+
Name: "@@.Pkg@@",
1616
Doc: doc,
1717
Run: run,
1818
Requires: []*analysis.Analyzer{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package {{.Pkg}}_test
1+
package @@.Pkg@@_test
22

33
import (
44
"testing"
55

6-
"{{.ImportPath}}"
6+
"@@.ImportPath@@"
77
"golang.org/x/tools/go/analysis/analysistest"
88
)
99

1010
// TestAnalyzer is a test for Analyzer.
1111
func TestAnalyzer(t *testing.T) {
1212
testdata := analysistest.TestData()
13-
analysistest.Run(t, testdata, {{.Pkg}}.Analyzer, "a")
13+
analysistest.Run(t, testdata, @@.Pkg@@.Analyzer, "a")
1414
}
1515

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@ if .Cmd -@@
2+
package main
3+
4+
import (
5+
"@@.ImportPath@@"
6+
"golang.org/x/tools/go/analysis/@@.Checker@@checker"
7+
)
8+
9+
func main() { @@.Checker@@checker.Main(@@.Pkg@@.Analyzer) }
10+
@@end@@
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
{{ if .Plugin -}}
1+
@@ if .Plugin -@@
22
// This file can build as a plugin for golangci-lint by below command.
3-
// go build -buildmode=plugin -o path_to_plugin_dir {{.ImportPath}}/plugin/{{.Pkg}}
3+
// go build -buildmode=plugin -o path_to_plugin_dir @@.ImportPath@@/plugin/@@.Pkg@@
44
// See: https://golangci-lint.run/contributing/new-linters/#how-to-add-a-private-linter-to-golangci-lint
55

66
package main
77

88
import (
99
"strings"
1010

11-
"{{.ImportPath}}"
11+
"@@.ImportPath@@"
1212
"golang.org/x/tools/go/analysis"
1313
)
1414

1515
// flags for Analyzer.Flag.
1616
// If you would like to specify flags for your plugin, you can put them via 'ldflags' as below.
17-
// $ go build -buildmode=plugin -ldflags "-X 'main.flags=-opt val'" {{.ImportPath}}/plugin/{{.Pkg}}
17+
// $ go build -buildmode=plugin -ldflags "-X 'main.flags=-opt val'" @@.ImportPath@@/plugin/@@.Pkg@@
1818
var flags string
1919

2020
// AnalyzerPlugin provides analyzers as a plugin.
@@ -25,13 +25,13 @@ type analyzerPlugin struct{}
2525

2626
func (analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
2727
if flags != "" {
28-
flagset := {{.Pkg}}.Analyzer.Flags
28+
flagset := @@.Pkg@@.Analyzer.Flags
2929
if err := flagset.Parse(strings.Split(flags, " ")); err != nil {
30-
panic("cannot parse flags of {{.Pkg}}: " + err.Error())
30+
panic("cannot parse flags of @@.Pkg@@: " + err.Error())
3131
}
3232
}
3333
return []*analysis.Analyzer{
34-
{{.Pkg}}.Analyzer,
34+
@@.Pkg@@.Analyzer,
3535
}
3636
}
37-
{{end}}
37+
@@end@@

_template/{{.Pkg}}/cmd/{{.Pkg}}/main.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

template.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/txtar/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ func main() {
8080
fmt.Fprintln(w, "// Code generated by _tools/txtar/main.go; DO NOT EDIT.")
8181
fmt.Fprintln(w, "")
8282
fmt.Fprintln(w, "package main")
83-
fmt.Fprintln(w, )
83+
fmt.Fprintln(w)
8484
fmt.Fprintln(w, `import "text/template"`)
85-
fmt.Fprintln(w, )
86-
fmt.Fprintf(w, "var tmpl = template.Must(template.New(\"template\").Parse(%q))\n", archived)
85+
fmt.Fprintln(w)
86+
fmt.Fprintf(w, "var tmpl = template.Must(template.New"+
87+
"(\"template\").Delims(`@@`, `@@`).Parse(%q))\n", archived)
8788
}
8889

8990
if err := w.Close(); err != nil {

0 commit comments

Comments
 (0)