function modifyBabelLoaderRules (rules, modifier = r => r) {
  return rules.map(rule => {
    if (rule.oneOf) {
      rule.oneOf = modifyBabelLoaderRules(rule.oneOf, modifier)
    } else if (rule.use) {
      rule.use = modifyBabelLoaderRules(rule.use, modifier)
    } else {
      rule = modifier(rule)
    }
    return rule
  })
}
This function goes through the loader rules and applies modifier function to the said rule.
Validation can be set within the modifier function.

@param {import('webpack').RuleSetRule[]} rules
@param {function} modifier defaults to identity function
@returns {import('webpack').RuleSetRule[]}