Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mgenware committed Dec 2, 2023
1 parent a07c457 commit 61910a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 45 deletions.
31 changes: 1 addition & 30 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
include: package:mgenware_dart_lints/lints.yaml
28 changes: 14 additions & 14 deletions lib/src/immutable_ordered_map_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ImmutableOrderedMap<K, V> {
/// no such key exists.
V? get(K key) {
final found = find(key);
return found == -1 ? null : _content[found + 1];
return found == -1 ? null : (_content[found + 1] as V);
}

/// Create a new map by replacing the value of `key` with a new
/// value, or adding a binding to the end of the map. If `newKey` is
/// given, the key of the binding will be replaced with that key.
ImmutableOrderedMap<K, V> update(K key, V value, K? newKey) {
final self = newKey != null && newKey != key ? this.remove(newKey) : this;
var found = self.find(key);
final found = self.find(key);
final content = [..._content];
if (found == -1) {
content.add(newKey ?? key);
Expand All @@ -42,11 +42,11 @@ class ImmutableOrderedMap<K, V> {

/// Return a map with the given key removed, if it existed.
ImmutableOrderedMap<K, V> remove(K key) {
var found = this.find(key);
final found = this.find(key);
if (found == -1) {
return this;
}
var content = [..._content];
final content = [..._content];
content.removeRange(found, found + 2);
return ImmutableOrderedMap<K, V>._(content);
}
Expand All @@ -58,8 +58,8 @@ class ImmutableOrderedMap<K, V> {
}

/// Add a new key to the end of the map.
ImmutableOrderedMap<K, V> addToEnd(key, value) {
var content = [...this.remove(key)._content];
ImmutableOrderedMap<K, V> addToEnd(K key, V value) {
final content = [...this.remove(key)._content];
content.add(key);
content.add(value);
return ImmutableOrderedMap<K, V>._(content);
Expand All @@ -68,9 +68,9 @@ class ImmutableOrderedMap<K, V> {
/// Add a key after the given key. If `place` is not found, the new
/// key is added to the end.
ImmutableOrderedMap<K, V> addBefore(K place, K key, V value) {
var without = this.remove(key);
final without = this.remove(key);
final content = [...without._content];
var found = without.find(place);
final found = without.find(place);
content.insert(found == -1 ? content.length : found, key);
content.insert(found == -1 ? content.length : found + 1, value);
return ImmutableOrderedMap<K, V>._(content);
Expand All @@ -80,7 +80,7 @@ class ImmutableOrderedMap<K, V> {
/// order.
void forEach(void Function(K, V) f) {
for (var i = 0; i < _content.length; i += 2) {
f(_content[i], _content[i + 1]);
f(_content[i] as K, _content[i + 1] as V);
}
}

Expand Down Expand Up @@ -112,18 +112,18 @@ class ImmutableOrderedMap<K, V> {
var result = this;
final ioMap = ImmutableOrderedMap.from(map);
for (var i = 0; i < ioMap._content.length; i += 2) {
result = result.remove(ioMap._content[i]);
result = result.remove(ioMap._content[i] as K);
}
return result;
}

/// The amount of keys in this map.
get size {
int get size {
return _content.length >> 1;
}

Map<K, V> toMap() {
Map<K, V> result = {};
final Map<K, V> result = {};
this.forEach((key, value) {
result[key] = value;
});
Expand All @@ -133,14 +133,14 @@ class ImmutableOrderedMap<K, V> {
/// Return a map with the given content. If null, create an empty
/// map. If given an ordered map, return that map itself. If given an
/// object, create a map from the object's properties.
static from<K, V>(Map<K, V>? map) {
static ImmutableOrderedMap<K, V> from<K, V>(Map<K, V>? map) {
final List<dynamic> content = [];
if (map != null) {
map.forEach((key, value) {
content.add(key);
content.add(value);
});
}
return ImmutableOrderedMap._(content);
return ImmutableOrderedMap<K, V>._(content);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:
# path: ^1.8.0

dev_dependencies:
lints: ^2.1.0
mgenware_dart_lints: ^4.1.0
test: ^1.24.0

0 comments on commit 61910a7

Please sign in to comment.