Skip to content

Commit 92a28fe

Browse files
authored
Replace whitelist/blacklist with safelist/blocklist (#917)
Inspired by https://twitter.com/amlyhamm/status/1202684742069604353.
1 parent 7113a72 commit 92a28fe

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

lib/src/configuration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class Configuration {
6363
newValues = UnprefixedMapView(newValues, forward.prefix);
6464
}
6565
if (forward.shownVariables != null) {
66-
newValues = LimitedMapView.whitelist(newValues, forward.shownVariables);
66+
newValues = LimitedMapView.safelist(newValues, forward.shownVariables);
6767
} else if (forward.hiddenVariables?.isNotEmpty ?? false) {
68-
newValues = LimitedMapView.blacklist(newValues, forward.hiddenVariables);
68+
newValues = LimitedMapView.blocklist(newValues, forward.hiddenVariables);
6969
}
7070
return Configuration(newValues, isImplicit: isImplicit);
7171
}

lib/src/module/forwarded_view.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ class ForwardedModuleView<T extends AsyncCallable> implements Module<T> {
4646
mixins = _forwardedMap(_inner.mixins, _rule.prefix,
4747
_rule.shownMixinsAndFunctions, _rule.hiddenMixinsAndFunctions);
4848

49-
/// Wraps [map] so that it only shows members allowed by [blacklist] or
50-
/// [whitelist], with the given [prefix], if given.
49+
/// Wraps [map] so that it only shows members allowed by [blocklist] or
50+
/// [safelist], with the given [prefix], if given.
5151
///
52-
/// Only one of [blacklist] or [whitelist] may be non-`null`.
52+
/// Only one of [blocklist] or [safelist] may be non-`null`.
5353
static Map<String, V> _forwardedMap<V>(Map<String, V> map, String prefix,
54-
Set<String> whitelist, Set<String> blacklist) {
55-
assert(whitelist == null || blacklist == null);
54+
Set<String> safelist, Set<String> blocklist) {
55+
assert(safelist == null || blocklist == null);
5656
if (prefix == null &&
57-
whitelist == null &&
58-
(blacklist == null || blacklist.isEmpty)) {
57+
safelist == null &&
58+
(blocklist == null || blocklist.isEmpty)) {
5959
return map;
6060
}
6161

6262
if (prefix != null) {
6363
map = PrefixedMapView(map, prefix);
6464
}
6565

66-
if (whitelist != null) {
67-
map = LimitedMapView.whitelist(map, whitelist);
68-
} else if (blacklist != null && blacklist.isNotEmpty) {
69-
map = LimitedMapView.blacklist(map, blacklist);
66+
if (safelist != null) {
67+
map = LimitedMapView.safelist(map, safelist);
68+
} else if (blocklist != null && blocklist.isNotEmpty) {
69+
map = LimitedMapView.blocklist(map, blocklist);
7070
}
7171

7272
return map;

lib/src/module/shadowed_view.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../util/limited_map_view.dart';
1212
import '../value.dart';
1313

1414
/// A [Module] that only exposes members that aren't shadowed by a given
15-
/// blacklist of member names.
15+
/// blocklist of member names.
1616
class ShadowedModuleView<T extends AsyncCallable> implements Module<T> {
1717
/// The wrapped module.
1818
final Module<T> _inner;
@@ -55,16 +55,16 @@ class ShadowedModuleView<T extends AsyncCallable> implements Module<T> {
5555
ShadowedModuleView._(this._inner, this.variables, this.variableNodes,
5656
this.functions, this.mixins);
5757

58-
/// Returns a view of [map] with all keys in [blacklist] omitted.
58+
/// Returns a view of [map] with all keys in [blocklist] omitted.
5959
static Map<String, V> _shadowedMap<V>(
60-
Map<String, V> map, Set<String> blacklist) {
61-
if (map == null || !_needsBlacklist(map, blacklist)) return map;
62-
return LimitedMapView.blacklist(map, blacklist);
60+
Map<String, V> map, Set<String> blocklist) {
61+
if (map == null || !_needsBlacklist(map, blocklist)) return map;
62+
return LimitedMapView.blocklist(map, blocklist);
6363
}
6464

65-
/// Returns whether any of [map]'s keys are in [blacklist].
66-
static bool _needsBlacklist(Map<String, Object> map, Set<String> blacklist) =>
67-
blacklist != null && map.isNotEmpty && blacklist.any(map.containsKey);
65+
/// Returns whether any of [map]'s keys are in [blocklist].
66+
static bool _needsBlacklist(Map<String, Object> map, Set<String> blocklist) =>
67+
blocklist != null && map.isNotEmpty && blocklist.any(map.containsKey);
6868

6969
void setVariable(String name, Value value, AstNode nodeWithSpan) {
7070
if (!variables.containsKey(name)) {

lib/src/util/limited_map_view.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class LimitedMapView<K, V> extends UnmodifiableMapBase<K, V> {
2929
bool get isEmpty => _keys.isEmpty;
3030
bool get isNotEmpty => _keys.isNotEmpty;
3131

32-
/// Returns a [LimitedMapView] that allows only keys in [whitelist].
32+
/// Returns a [LimitedMapView] that allows only keys in [safelist].
3333
///
34-
/// The [whitelist] must have the same notion of equality as the [map].
35-
LimitedMapView.whitelist(this._map, Set<K> whitelist)
36-
: _keys = whitelist.intersection(MapKeySet(_map));
34+
/// The [safelist] must have the same notion of equality as the [map].
35+
LimitedMapView.safelist(this._map, Set<K> safelist)
36+
: _keys = safelist.intersection(MapKeySet(_map));
3737

38-
/// Returns a [LimitedMapView] that doesn't allow keys in [blacklist].
38+
/// Returns a [LimitedMapView] that doesn't allow keys in [blocklist].
3939
///
40-
/// The [blacklist] must have the same notion of equality as the [map].
41-
LimitedMapView.blacklist(this._map, Set<K> blacklist)
42-
: _keys = {for (var key in _map.keys) if (!blacklist.contains(key)) key};
40+
/// The [blocklist] must have the same notion of equality as the [map].
41+
LimitedMapView.blocklist(this._map, Set<K> blocklist)
42+
: _keys = {for (var key in _map.keys) if (!blocklist.contains(key)) key};
4343

4444
V operator [](Object key) => _keys.contains(key) ? _map[key] : null;
4545
bool containsKey(Object key) => _keys.contains(key);

0 commit comments

Comments
 (0)