@@ -32,9 +32,24 @@ const (
32
32
)
33
33
34
34
var (
35
- preservedNonGoFiles = []string {
36
- "LICENSE" ,
37
- "COPYING" ,
35
+ // licenseFilePrefixes is a list of name prefixes for licesnse files.
36
+ licenseFilePrefixes = []string {
37
+ "license" ,
38
+ "licence" ,
39
+ "copying" ,
40
+ "unlicense" ,
41
+ "copyright" ,
42
+ "copyleft" ,
43
+ }
44
+ // legalFileSubstrings contains substrings that are likey part of a legal
45
+ // declaration file.
46
+ legalFileSubstrings = []string {
47
+ "legal" ,
48
+ "notice" ,
49
+ "disclaimer" ,
50
+ "patent" ,
51
+ "third-party" ,
52
+ "thirdparty" ,
38
53
}
39
54
)
40
55
@@ -215,22 +230,36 @@ func calculateNonGoFiles(baseDir string) ([]string, error) {
215
230
return nil
216
231
}
217
232
218
- // Ignore preserved non-Go files. We check for prefix incase the file
219
- // has an extension. For example: LICENSE.md.
220
- for _ , prefix := range preservedNonGoFiles {
221
- if strings .HasPrefix (info .Name (), prefix ) {
222
- return nil
223
- }
233
+ if ! isPreservedNonGoFile (info .Name ()) {
234
+ files = append (files , path )
224
235
}
225
236
226
- files = append (files , path )
227
-
228
237
return nil
229
238
})
230
239
231
240
return files , err
232
241
}
233
242
243
+ // isPreservedNonGoFile checks if the file name idicates that the file should be
244
+ // preserved. It assumes the file is not a Go file (doesn't have a .go suffix).
245
+ func isPreservedNonGoFile (name string ) bool {
246
+ name = strings .ToLower (name )
247
+
248
+ for _ , prefix := range licenseFilePrefixes {
249
+ if strings .HasPrefix (name , prefix ) {
250
+ return true
251
+ }
252
+ }
253
+
254
+ for _ , substring := range legalFileSubstrings {
255
+ if strings .Contains (name , substring ) {
256
+ return true
257
+ }
258
+ }
259
+
260
+ return false
261
+ }
262
+
234
263
// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDirr.
235
264
func pruneGoTestFiles (baseDir string , logger * log.Logger ) error {
236
265
files , err := calculateGoTestFiles (baseDir )
0 commit comments