int? constrain()

in lib/src/rule/argument.dart [182:237]


  int? constrain(int value, Rule other) {
    var constrained = super.constrain(value, other);
    if (constrained != null) return constrained;

    // Handle the relationship between the positional and named args.
    if (other == _namedArgsRule) {
      // If the positional args are one-per-line, the named args are too.
      if (value == fullySplitValue) return _namedArgsRule!.fullySplitValue;

      // Otherwise, if there is any split in the positional arguments, don't
      // allow the named arguments on the same line as them.
      if (value != 0) return -1;
    }

    // Decide how to constrain the collection rule.
    if (other != _collectionRule) return null;

    // If all of the collections are in the named arguments, [_collectionRule]
    // will not be null, but we don't have to handle it.
    if (_leadingCollections == 0 && _trailingCollections == 0) return null;

    // If we aren't splitting any args, we can split the collection.
    if (value == Rule.unsplit) return null;

    // Split only before the first argument.
    if (value == 1) {
      if (_leadingCollections > 0) {
        // We are splitting before a collection, so don't let it split
        // internally.
        return Rule.unsplit;
      } else {
        // The split is outside of the collections so they can split or not.
        return null;
      }
    }

    // Split before a single argument. If it's in the middle of the collection
    // arguments, don't allow them to split.
    if (value <= _arguments.length) {
      var argument = _arguments.length - value + 1;
      if (argument < _leadingCollections ||
          argument >= _arguments.length - _trailingCollections) {
        return Rule.unsplit;
      }

      return null;
    }

    // Only split before the non-collection arguments. This case only comes into
    // play when we do want to split the collection, so force that here.
    if (value == _arguments.length + 1) return 1;

    // Split before all of the arguments, even the collections. We'll allow
    // them to split but indent their bodies if they do.
    return null;
  }