From 92a28feb251f0029ddcc92b09072dddb366fbd10 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 2 Jan 2020 14:53:39 -0800 Subject: [PATCH] Replace whitelist/blacklist with safelist/blocklist (#917) Inspired by https://twitter.com/amlyhamm/status/1202684742069604353. --- lib/src/configuration.dart | 4 ++-- lib/src/module/forwarded_view.dart | 22 +++++++++++----------- lib/src/module/shadowed_view.dart | 16 ++++++++-------- lib/src/util/limited_map_view.dart | 16 ++++++++-------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index de532cf41..0c54c2abf 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -63,9 +63,9 @@ class Configuration { newValues = UnprefixedMapView(newValues, forward.prefix); } if (forward.shownVariables != null) { - newValues = LimitedMapView.whitelist(newValues, forward.shownVariables); + newValues = LimitedMapView.safelist(newValues, forward.shownVariables); } else if (forward.hiddenVariables?.isNotEmpty ?? false) { - newValues = LimitedMapView.blacklist(newValues, forward.hiddenVariables); + newValues = LimitedMapView.blocklist(newValues, forward.hiddenVariables); } return Configuration(newValues, isImplicit: isImplicit); } diff --git a/lib/src/module/forwarded_view.dart b/lib/src/module/forwarded_view.dart index 441133b75..606e48048 100644 --- a/lib/src/module/forwarded_view.dart +++ b/lib/src/module/forwarded_view.dart @@ -46,16 +46,16 @@ class ForwardedModuleView implements Module { mixins = _forwardedMap(_inner.mixins, _rule.prefix, _rule.shownMixinsAndFunctions, _rule.hiddenMixinsAndFunctions); - /// Wraps [map] so that it only shows members allowed by [blacklist] or - /// [whitelist], with the given [prefix], if given. + /// Wraps [map] so that it only shows members allowed by [blocklist] or + /// [safelist], with the given [prefix], if given. /// - /// Only one of [blacklist] or [whitelist] may be non-`null`. + /// Only one of [blocklist] or [safelist] may be non-`null`. static Map _forwardedMap(Map map, String prefix, - Set whitelist, Set blacklist) { - assert(whitelist == null || blacklist == null); + Set safelist, Set blocklist) { + assert(safelist == null || blocklist == null); if (prefix == null && - whitelist == null && - (blacklist == null || blacklist.isEmpty)) { + safelist == null && + (blocklist == null || blocklist.isEmpty)) { return map; } @@ -63,10 +63,10 @@ class ForwardedModuleView implements Module { map = PrefixedMapView(map, prefix); } - if (whitelist != null) { - map = LimitedMapView.whitelist(map, whitelist); - } else if (blacklist != null && blacklist.isNotEmpty) { - map = LimitedMapView.blacklist(map, blacklist); + if (safelist != null) { + map = LimitedMapView.safelist(map, safelist); + } else if (blocklist != null && blocklist.isNotEmpty) { + map = LimitedMapView.blocklist(map, blocklist); } return map; diff --git a/lib/src/module/shadowed_view.dart b/lib/src/module/shadowed_view.dart index 10a739dc7..d85710bf4 100644 --- a/lib/src/module/shadowed_view.dart +++ b/lib/src/module/shadowed_view.dart @@ -12,7 +12,7 @@ import '../util/limited_map_view.dart'; import '../value.dart'; /// A [Module] that only exposes members that aren't shadowed by a given -/// blacklist of member names. +/// blocklist of member names. class ShadowedModuleView implements Module { /// The wrapped module. final Module _inner; @@ -55,16 +55,16 @@ class ShadowedModuleView implements Module { ShadowedModuleView._(this._inner, this.variables, this.variableNodes, this.functions, this.mixins); - /// Returns a view of [map] with all keys in [blacklist] omitted. + /// Returns a view of [map] with all keys in [blocklist] omitted. static Map _shadowedMap( - Map map, Set blacklist) { - if (map == null || !_needsBlacklist(map, blacklist)) return map; - return LimitedMapView.blacklist(map, blacklist); + Map map, Set blocklist) { + if (map == null || !_needsBlacklist(map, blocklist)) return map; + return LimitedMapView.blocklist(map, blocklist); } - /// Returns whether any of [map]'s keys are in [blacklist]. - static bool _needsBlacklist(Map map, Set blacklist) => - blacklist != null && map.isNotEmpty && blacklist.any(map.containsKey); + /// Returns whether any of [map]'s keys are in [blocklist]. + static bool _needsBlacklist(Map map, Set blocklist) => + blocklist != null && map.isNotEmpty && blocklist.any(map.containsKey); void setVariable(String name, Value value, AstNode nodeWithSpan) { if (!variables.containsKey(name)) { diff --git a/lib/src/util/limited_map_view.dart b/lib/src/util/limited_map_view.dart index f7c370f35..a8ee88f54 100644 --- a/lib/src/util/limited_map_view.dart +++ b/lib/src/util/limited_map_view.dart @@ -29,17 +29,17 @@ class LimitedMapView extends UnmodifiableMapBase { bool get isEmpty => _keys.isEmpty; bool get isNotEmpty => _keys.isNotEmpty; - /// Returns a [LimitedMapView] that allows only keys in [whitelist]. + /// Returns a [LimitedMapView] that allows only keys in [safelist]. /// - /// The [whitelist] must have the same notion of equality as the [map]. - LimitedMapView.whitelist(this._map, Set whitelist) - : _keys = whitelist.intersection(MapKeySet(_map)); + /// The [safelist] must have the same notion of equality as the [map]. + LimitedMapView.safelist(this._map, Set safelist) + : _keys = safelist.intersection(MapKeySet(_map)); - /// Returns a [LimitedMapView] that doesn't allow keys in [blacklist]. + /// Returns a [LimitedMapView] that doesn't allow keys in [blocklist]. /// - /// The [blacklist] must have the same notion of equality as the [map]. - LimitedMapView.blacklist(this._map, Set blacklist) - : _keys = {for (var key in _map.keys) if (!blacklist.contains(key)) key}; + /// The [blocklist] must have the same notion of equality as the [map]. + LimitedMapView.blocklist(this._map, Set blocklist) + : _keys = {for (var key in _map.keys) if (!blocklist.contains(key)) key}; V operator [](Object key) => _keys.contains(key) ? _map[key] : null; bool containsKey(Object key) => _keys.contains(key);