-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathfile_option.go
60 lines (50 loc) · 1.7 KB
/
file_option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package reviser
import (
"strings"
)
// SourceFileOption is an int alias for options
type SourceFileOption func(f *SourceFile) error
// SourceFileOptions is a slice of executing options
type SourceFileOptions []SourceFileOption
// WithRemovingUnusedImports is an option to remove unused imports
func WithRemovingUnusedImports(f *SourceFile) error {
f.shouldRemoveUnusedImports = true
return nil
}
// WithUsingAliasForVersionSuffix is an option to set explicit package name in imports
func WithUsingAliasForVersionSuffix(f *SourceFile) error {
f.shouldUseAliasForVersionSuffix = true
return nil
}
// WithCodeFormatting use to format the code
func WithCodeFormatting(f *SourceFile) error {
f.shouldFormatCode = true
return nil
}
// WithCompanyPackagePrefixes option for 3d group(by default), like inter-org or company package prefixes
func WithCompanyPackagePrefixes(s string) SourceFileOption {
return func(f *SourceFile) error {
prefixes := strings.Split(s, stringValueSeparator)
for _, prefix := range prefixes {
f.companyPackagePrefixes = append(f.companyPackagePrefixes, strings.TrimSpace(prefix))
}
return nil
}
}
// WithImportsOrder will sort by needed order. Default order is "std,general,company,project"
func WithImportsOrder(orders []ImportsOrder) SourceFileOption {
return func(f *SourceFile) error {
f.importsOrders = orders
return nil
}
}
// WithSkipGeneratedFile will skip formatting and imports sorting for auto-generated file which starts with
// comment on first line: `// Code generated`
func WithSkipGeneratedFile(f *SourceFile) error {
f.shouldSkipAutoGenerated = true
return nil
}
func WithSeparatedNamedImports(f *SourceFile) error {
f.shouldSeparateNamedImports = true
return nil
}