filterNodes function

List filterNodes(
  1. List nodes, {
  2. required bool showPrivateNodes,
})

Filter nodes from the input array based on whether they should be shown.

Implementation

List<Node> filterNodes(
  List<Node> nodes, {
  required bool showPrivateNodes,
}) {
  return nodes.where((node) {
    // 1. Check if it's a node that can't be shown
    if (node is DocNode) {
      if (node.kind == "moduleDoc" || node.kind == "import") {
        return false;
      }
    }
    // 2. Check if the visibility preference filters out the node
    if (node is DocNode && node.declarationKind != null) {
      if (!showPrivateNodes && node.declarationKind == "private") {
        return false;
      }
    }
    // All else failing, allow the node
    return true;
  }).toList();
}