Skip to content

Commit

Permalink
Merge pull request #18 from gostaticanalysis/fix-template-delims
Browse files Browse the repository at this point in the history
Fix template delims
  • Loading branch information
tenntenn authored Jul 10, 2020
2 parents 633e0f2 + b565714 commit be8c431
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{.Pkg}}
package @@.Pkg@@

import (
"go/ast"
Expand All @@ -8,11 +8,11 @@ import (
"golang.org/x/tools/go/ast/inspector"
)

const doc = "{{.Pkg}} is ..."
const doc = "@@.Pkg@@ is ..."

// Analyzer is ...
var Analyzer = &analysis.Analyzer{
Name: "{{.Pkg}}",
Name: "@@.Pkg@@",
Doc: doc,
Run: run,
Requires: []*analysis.Analyzer{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package {{.Pkg}}_test
package @@.Pkg@@_test

import (
"testing"

"{{.ImportPath}}"
"@@.ImportPath@@"
"golang.org/x/tools/go/analysis/analysistest"
)

// TestAnalyzer is a test for Analyzer.
func TestAnalyzer(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, {{.Pkg}}.Analyzer, "a")
analysistest.Run(t, testdata, @@.Pkg@@.Analyzer, "a")
}

10 changes: 10 additions & 0 deletions _template/@@.Pkg@@/cmd/@@.Pkg@@/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@@ if .Cmd -@@
package main

import (
"@@.ImportPath@@"
"golang.org/x/tools/go/analysis/@@.Checker@@checker"
)

func main() { @@.Checker@@checker.Main(@@.Pkg@@.Analyzer) }
@@end@@
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{{ if .Plugin -}}
@@ if .Plugin -@@
// This file can build as a plugin for golangci-lint by below command.
// go build -buildmode=plugin -o path_to_plugin_dir {{.ImportPath}}/plugin/{{.Pkg}}
// go build -buildmode=plugin -o path_to_plugin_dir @@.ImportPath@@/plugin/@@.Pkg@@
// See: https://golangci-lint.run/contributing/new-linters/#how-to-add-a-private-linter-to-golangci-lint

package main

import (
"strings"

"{{.ImportPath}}"
"@@.ImportPath@@"
"golang.org/x/tools/go/analysis"
)

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

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

func (analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
if flags != "" {
flagset := {{.Pkg}}.Analyzer.Flags
flagset := @@.Pkg@@.Analyzer.Flags
if err := flagset.Parse(strings.Split(flags, " ")); err != nil {
panic("cannot parse flags of {{.Pkg}}: " + err.Error())
panic("cannot parse flags of @@.Pkg@@: " + err.Error())
}
}
return []*analysis.Analyzer{
{{.Pkg}}.Analyzer,
@@.Pkg@@.Analyzer,
}
}
{{end}}
@@end@@
File renamed without changes.
10 changes: 0 additions & 10 deletions _template/{{.Pkg}}/cmd/{{.Pkg}}/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tools/txtar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ func main() {
fmt.Fprintln(w, "// Code generated by _tools/txtar/main.go; DO NOT EDIT.")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "package main")
fmt.Fprintln(w, )
fmt.Fprintln(w)
fmt.Fprintln(w, `import "text/template"`)
fmt.Fprintln(w, )
fmt.Fprintf(w, "var tmpl = template.Must(template.New(\"template\").Parse(%q))\n", archived)
fmt.Fprintln(w)
fmt.Fprintf(w, "var tmpl = template.Must(template.New"+
"(\"template\").Delims(`@@`, `@@`).Parse(%q))\n", archived)
}

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

0 comments on commit be8c431

Please sign in to comment.