func validator_componentValid()

in internal/changelog/linter.go [85:118]


func validator_componentValid(configComponents []string) entryValidationFn {
	return func(entry Entry) error {
		switch len(configComponents) {
		case 0:
			return nil
		case 1:
			c := configComponents[0]

			if c != entry.Component && len(entry.Component) > 0 {
				return fmt.Errorf("changelog entry: %s -> component [%s] not found in config: %s", entry.File.Name, entry.Component, configComponents)
			}
		default:
			var match string

			if entry.Component == "" {
				return fmt.Errorf("changelog entry: %s -> component cannot be assumed, choose it from config: %s", entry.File.Name, configComponents)
			}

			match = ""
			for _, c := range configComponents {
				if entry.Component != c {
					continue
				}
				match = entry.Component
			}

			if match == "" {
				return fmt.Errorf("changelog entry: %s -> component [%s] not found in config: %s", entry.File.Name, entry.Component, configComponents)
			}
		}

		return nil
	}
}