MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / Parse

Function Parse

config/config.go:22–64  ·  view source on GitHub ↗

Parse parse given file in confPath, and return Config instance, error if any

(confPath string)

Source from the content-addressed store, hash-verified

20
21// Parse parse given file in confPath, and return Config instance, error if any
22func Parse(confPath string) (*lint.Config, error) {
23 confPath = filepath.Clean(confPath)
24 confBytes, err := os.ReadFile(confPath)
25 if err != nil {
26 return nil, fmt.Errorf("config file error: %w", err)
27 }
28
29 conf := &lint.Config{
30 Formatter: (&formatter.DefaultFormatter{}).Name(),
31 Severity: lint.SeverityConfig{
32 Default: lint.SeverityError,
33 },
34 }
35
36 err = yaml.UnmarshalStrict(confBytes, conf)
37 if err != nil {
38 return nil, fmt.Errorf("config file error: %w", err)
39 }
40
41 // Backward compatibility: accept old "version" key
42 if conf.MinVersion == "" && conf.DeprecatedVersion != "" {
43 conf.MinVersion = conf.DeprecatedVersion
44 }
45 conf.DeprecatedVersion = ""
46
47 // Default to current version if neither key was provided
48 if conf.MinVersion == "" {
49 conf.MinVersion = internal.Version()
50 }
51
52 // Always set the built-in default patterns
53 conf.DefaultIgnorePatterns = DefaultIgnorePatterns()
54
55 if conf.Formatter == "" {
56 return nil, errors.New("config error: formatter is empty")
57 }
58
59 err = isValidVersion(conf.MinVersion)
60 if err != nil {
61 return nil, err
62 }
63 return conf, nil
64}
65
66// Validate validates given config instance, it checks the following
67// If formatters, rules are registered/known

Calls 4

VersionFunction · 0.92
DefaultIgnorePatternsFunction · 0.85
isValidVersionFunction · 0.85
NameMethod · 0.65