Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's a deprecated package that will be removed from upstream soon.
- Loading branch information
Showing
6 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
// Package analysis provides a routine that determines if a file is generated or handcrafted. | |||
// | |||
// Deprecated: Use github.com/shurcooL/go/generated package instead. This implementation | |||
// was done ad-hoc before a standard was proposed. | |||
package analysis | |||
|
|||
import ( | |||
"bufio" | |||
"io" | |||
"os" | |||
"path/filepath" | |||
"strings" | |||
) | |||
|
|||
// IsFileGenerated returns true if the specified file is generated, or false if it's handcrafted. | |||
// rootDir is the filepath of root directory, but name is a '/'-separated path to file. | |||
// | |||
// It considers vendored files as "generated", in the sense that they are not the canonical | |||
// version of a file. This behavior would ideally be factored out into a higher level utility, | |||
// since it has nothing to do with generated comments. | |||
// | |||
// Deprecated: Use generated.ParseFile instead, which is more well defined because it | |||
// implements a specification. | |||
func IsFileGenerated(rootDir, name string) (bool, error) { | |||
// Detect from name. | |||
switch { | |||
case strings.HasPrefix(name, "vendor/") || strings.Contains(name, "/vendor/"): | |||
return true, nil | |||
case strings.HasPrefix(name, "Godeps/"): | |||
return true, nil | |||
} | |||
|
|||
// Detect from file contents. | |||
f, err := os.Open(filepath.Join(rootDir, filepath.FromSlash(name))) | |||
if err != nil { | |||
return false, err | |||
} | |||
defer f.Close() | |||
r := bufio.NewReader(f) | |||
s, err := r.ReadString('\n') | |||
if err == io.EOF { | |||
// Empty file or exactly 1 line is not considered to be generated. | |||
return false, nil | |||
} else if err != nil { | |||
return false, err | |||
} | |||
if strings.Contains(s, "Code generated by") { // Consistent with https://golang.org/cl/15073. | |||
return true, nil | |||
} | |||
return (strings.Contains(s, "GENERATED") || strings.Contains(s, "generated")) && strings.Contains(s, "DO NOT EDIT"), nil | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package analysis_test | |||
|
|||
import ( | |||
"fmt" | |||
"os" | |||
|
|||
"github.com/shurcooL-legacy/Conception-go/pkg/analysis" | |||
) | |||
|
|||
func ExampleIsFileGenerated() { | |||
cwd, err := os.Getwd() | |||
if err != nil { | |||
panic(err) | |||
} | |||
|
|||
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/generated_0.go.txt")) | |||
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_0.go.txt")) | |||
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_1.go.txt")) | |||
fmt.Println(analysis.IsFileGenerated(cwd, "vendor/github.com/shurcooL/go/analysis/file.go")) | |||
fmt.Println(analysis.IsFileGenerated(cwd, "subpkg/vendor/math/math.go")) | |||
|
|||
// Output: | |||
// true <nil> | |||
// false <nil> | |||
// false <nil> | |||
// true <nil> | |||
// true <nil> | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
// generated by vfsgen; DO NOT EDIT | |||
|
|||
// +build !dev | |||
|
|||
package issues | |||
|
|||
import ( | |||
"bytes" | |||
"compress/gzip" | |||
"fmt" | |||
"io" | |||
"net/http" | |||
"os" | |||
pathpkg "path" | |||
"time" | |||
) | |||
|
|||
// Assets statically implements the virtual filesystem given to vfsgen as input. | |||
var Assets = func() http.FileSystem { | |||
mustUnmarshalTextTime := func(text string) time.Time { | |||
var t time.Time | |||
err := t.UnmarshalText([]byte(text)) | |||
if err != nil { | |||
panic(err) | |||
} | |||
return t | |||
} | |||
|
|||
fs := _vfsgen_fs{ | |||
... | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
// Package foo offers bar. | |||
package foo | |||
|
|||
import "strings" | |||
|
|||
// Bar is bar. | |||
func Bar() string { | |||
return strings.Title("bar") | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
// Code generated by protoc-gen-gogo. Actually it isn't, because it's only 1 line. |