bool _shouldSkipLinkedHashLint()

in lib/src/rules/prefer_collection_literals.dart [147:188]


  bool _shouldSkipLinkedHashLint(
      InstanceCreationExpression node, bool Function(DartType node) typeCheck) {
    if (_isHashMap(node) || _isHashSet(node)) {
      // Skip: LinkedHashSet<int> s =  ...; or LinkedHashMap<int> s =  ...;
      var parent = node.parent;
      if (parent is VariableDeclaration) {
        var parent2 = parent.parent;
        if (parent2 is VariableDeclarationList) {
          var assignmentType = parent2.type?.type;
          if (assignmentType != null && typeCheck(assignmentType)) {
            return true;
          }
        }
      }
      // Skip: function(LinkedHashSet()); when function(LinkedHashSet mySet) or
      // function(LinkedHashMap()); when function(LinkedHashMap myMap)
      if (parent is ArgumentList) {
        var paramType = node.staticParameterElement?.type;
        if (paramType == null || typeCheck(paramType)) {
          return true;
        }
      }

      // Skip: void f({required LinkedHashSet<Foo> s})
      if (parent is NamedExpression) {
        var paramType = parent.staticParameterElement?.type;
        if (paramType != null && typeCheck(paramType)) {
          return true;
        }
      }

      // Skip: <int, LinkedHashSet>{}.putIfAbsent(3, () => LinkedHashSet());
      // or <int, LinkedHashMap>{}.putIfAbsent(3, () => LinkedHashMap());
      if (parent is ExpressionFunctionBody) {
        var expressionType = parent.expression.staticType;
        if (expressionType != null && typeCheck(expressionType)) {
          return true;
        }
      }
    }
    return false;
  }