5
5
package gps
6
6
7
7
import (
8
- "fmt"
9
8
"log"
10
9
"os"
11
10
"path/filepath"
@@ -23,7 +22,8 @@ const (
23
22
// PruneUnusedPackages indicates if unused Go packages should be pruned.
24
23
PruneUnusedPackages
25
24
// PruneNonGoFiles indicates if non-Go files should be pruned.
26
- // LICENSE & COPYING files are kept for convience.
25
+ // Files matching licenseFilePrefixes and legalFileSubstrings are kept in
26
+ // an attempt to comply with legal requirements.
27
27
PruneNonGoFiles
28
28
// PruneGoTestFiles indicates if Go test files should be pruned.
29
29
PruneGoTestFiles
@@ -61,7 +61,7 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
61
61
// TODO(ibrasho) allow passing specific options per project
62
62
for _ , lp := range l .Projects () {
63
63
projectDir := filepath .Join (baseDir , string (lp .Ident ().ProjectRoot ))
64
- err := pruneProject (projectDir , lp , options , logger )
64
+ err := PruneProject (projectDir , lp , options , logger )
65
65
if err != nil {
66
66
return err
67
67
}
@@ -70,9 +70,9 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
70
70
return nil
71
71
}
72
72
73
- // pruneProject remove excess files according to the options passed, from
73
+ // PruneProject remove excess files according to the options passed, from
74
74
// the lp directory in baseDir.
75
- func pruneProject (baseDir string , lp LockedProject , options PruneOptions , logger * log.Logger ) error {
75
+ func PruneProject (baseDir string , lp LockedProject , options PruneOptions , logger * log.Logger ) error {
76
76
projectDir := filepath .Join (baseDir , string (lp .Ident ().ProjectRoot ))
77
77
78
78
if (options & PruneNestedVendorDirs ) != 0 {
@@ -158,8 +158,8 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
158
158
if err != nil {
159
159
return errors .Wrap (err , "unexpected error while calculating unused packages" )
160
160
}
161
- fmt .Println (pkg )
162
161
162
+ filepath .ToSlash (pkg )
163
163
if _ , ok := imported [pkg ]; ! ok {
164
164
unused [pkg ] = struct {}{}
165
165
}
@@ -174,7 +174,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
174
174
func collectUnusedPackagesFiles (projectDir string , unusedPackages map [string ]struct {}) ([]string , error ) {
175
175
// TODO(ibrasho): is this useful?
176
176
files := make ([]string , 0 , len (unusedPackages ))
177
- fmt .Println (unusedPackages )
178
177
179
178
err := filepath .Walk (projectDir , func (path string , info os.FileInfo , err error ) error {
180
179
if err != nil {
@@ -255,10 +254,8 @@ func collectNonGoFiles(baseDir string, logger *log.Logger) ([]string, error) {
255
254
return files , err
256
255
}
257
256
258
- // isPreservedFile checks if the file name idicates that the file should be
259
- // preserved.
260
- // isPreservedFile checks if the file name contains one of the prefixes in
261
- // licenseFilePrefixes or contains one of the legalFileSubstrings entries.
257
+ // isPreservedFile checks if the file name indicates that the file should be
258
+ // preserved based on licenseFilePrefixes or legalFileSubstrings.
262
259
func isPreservedFile (name string ) bool {
263
260
name = strings .ToLower (name )
264
261
@@ -279,7 +276,7 @@ func isPreservedFile(name string) bool {
279
276
280
277
// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDir.
281
278
func pruneGoTestFiles (baseDir string , logger * log.Logger ) error {
282
- files , err := collectGoTestsFile (baseDir )
279
+ files , err := collectGoTestFiles (baseDir )
283
280
if err != nil {
284
281
return errors .Wrap (err , "could not collect Go test files" )
285
282
}
@@ -291,9 +288,9 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
291
288
return nil
292
289
}
293
290
294
- // collectGoTestsFile returns a slice contains all Go test files (any files
291
+ // collectGoTestFiles returns a slice contains all Go test files (any files
295
292
// prefixed with _test.go) in baseDir.
296
- func collectGoTestsFile (baseDir string ) ([]string , error ) {
293
+ func collectGoTestFiles (baseDir string ) ([]string , error ) {
297
294
files := make ([]string , 0 )
298
295
299
296
err := filepath .Walk (baseDir , func (path string , info os.FileInfo , err error ) error {
0 commit comments