Skip to content

Commit

Permalink
Add even more strict linter rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Sep 23, 2023
1 parent c113d31 commit 5b6aff4
Show file tree
Hide file tree
Showing 56 changed files with 189 additions and 104 deletions.
25 changes: 23 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ linter:
- avoid_dynamic_calls
- avoid_final_parameters
- avoid_print
- avoid_unused_constructor_parameters
- camel_case_types
- combinators_ordering
- comment_references
- dangling_library_doc_comments
- implicit_call_tearoffs
- invalid_case_patterns
- no_self_assignments
Expand All @@ -19,13 +23,30 @@ linter:
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_for_elements_to_map_fromIterable
- prefer_function_declarations_over_variables
- prefer_if_elements_to_conditional_expressions
- prefer_relative_imports
- sort_constructors_first
- type_literal_in_constant_pattern
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_breaks
- unnecessary_const
- unnecessary_constructor_name
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_late
- unnecessary_library_directive
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_null_checks
- unnecessary_null_in_if_null_operators
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_to_list_in_spreads
- unreachable_from_main
- use_super_parameters
21 changes: 21 additions & 0 deletions bin/generate_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Future<void> generateCallback() async {
final out = file.openWrite();

out.writeln('/// Function types for generic callbacks.');
out.writeln('library callback;');
out.writeln();

for (var i = 0; i < max; i++) {
Expand All @@ -58,6 +59,7 @@ Future<void> generateMapping() async {
final out = file.openWrite();

out.writeln('/// Function type for generic mapping functions.');
out.writeln('library mapping;');
out.writeln();

for (var i = 0; i < max; i++) {
Expand All @@ -77,6 +79,7 @@ Future<void> generatePredicate() async {
final out = file.openWrite();

out.writeln('/// Function type for generic predicate functions.');
out.writeln('library predicate;');
out.writeln();

for (var i = 0; i < max; i++) {
Expand All @@ -96,6 +99,7 @@ Future<void> generateEmpty() async {
final out = file.openWrite();

out.writeln('/// Generic empty functions returning nothing.');
out.writeln('library empty;');
out.writeln();

for (var i = 0; i < max; i++) {
Expand All @@ -115,6 +119,7 @@ Future<void> generateIdentity() async {
final out = file.openWrite();

out.writeln('/// Generic identity functions.');
out.writeln('library identity;');
out.writeln();

out.writeln('/// Generic identity function with 1 positional argument.');
Expand All @@ -130,6 +135,9 @@ Future<void> generateConstant() async {
final out = file.openWrite();

out.writeln('/// The constant functions.');
out.writeln('library constant;');
out.writeln();

out.writeln("import 'mapping.dart';");
out.writeln();

Expand All @@ -152,6 +160,9 @@ Future<void> generateThrowing() async {
final out = file.openWrite();

out.writeln('/// The throwing functions.');
out.writeln('library throwing;');
out.writeln();

out.writeln("import 'mapping.dart';");
out.writeln();

Expand All @@ -176,6 +187,9 @@ Future<void> generatePartial() async {

out.writeln('/// Binds positional arguments and returns a new function:');
out.writeln('/// https://en.wikipedia.org/wiki/Partial_application');
out.writeln('library partial;');
out.writeln();

out.writeln("import 'mapping.dart';");
out.writeln();

Expand Down Expand Up @@ -214,6 +228,9 @@ Future<void> generateCurry() async {
'sequence of functions ');
out.writeln('/// taking a single argument: '
'https://en.wikipedia.org/wiki/Currying');
out.writeln('library curry;');
out.writeln();

out.writeln("import 'mapping.dart';");
out.writeln();

Expand Down Expand Up @@ -254,9 +271,13 @@ Future<void> generateTest() async {
out.writeln('});');
}

out.writeln('// ignore_for_file: unnecessary_lambdas');
out.writeln();

out.writeln('import \'package:more/functional.dart\';');
out.writeln('import \'package:test/test.dart\';');
out.writeln();

out.writeln('void main() {');

nest('group', 'constant', () {
Expand Down
2 changes: 2 additions & 0 deletions lib/async.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Helpers to make async code better.
library async;

export 'src/async/buffer.dart' show BufferExtension;
export 'src/async/flat_map.dart' show FlatMapStreamExtension;
export 'src/async/flatten_iterable.dart' show FlattenStreamIterableExtension;
Expand Down
2 changes: 2 additions & 0 deletions lib/cache.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Collection of different caching strategies and their expiry policy.
library cache;

export 'src/cache/cache.dart';
export 'src/cache/delegate.dart';
export 'src/cache/loader.dart';
2 changes: 2 additions & 0 deletions lib/char_matcher.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// A first-class model of character classes, their composition and operations
/// on strings.
library char_matcher;

export 'src/char_matcher/char_matcher.dart';
24 changes: 13 additions & 11 deletions lib/collection.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// A collection of iterable extensions and new collection types: bi-map,
/// bit-list, multi-set, set and list multi-map, range, and string.
library collection;

export 'src/collection/bimap.dart'
show BiMap, BiMapOnMapExtension, BiMapOnIterableExtension;
show BiMap, BiMapOnIterableExtension, BiMapOnMapExtension;
export 'src/collection/bitlist.dart' show BitList, BitListExtension;
export 'src/collection/heap.dart' show Heap;
export 'src/collection/iterable/chunked.dart' show ChunkedIterableExtension;
Expand All @@ -10,19 +12,19 @@ export 'src/collection/iterable/combinations.dart'
export 'src/collection/iterable/count.dart' show CountIterableExtension;
export 'src/collection/iterable/flat_map.dart' show FlatMapIterableExtension;
export 'src/collection/iterable/flatten.dart'
show FlattenIterableExtension, DeepFlattenIterableExtension;
show DeepFlattenIterableExtension, FlattenIterableExtension;
export 'src/collection/iterable/group.dart'
show GroupIterableExtension, GroupMapEntryExtension, Group;
show Group, GroupIterableExtension, GroupMapEntryExtension;
export 'src/collection/iterable/indexed.dart'
show IndexedIterableExtension, IndexedMapEntryExtension, Indexed;
show Indexed, IndexedIterableExtension, IndexedMapEntryExtension;
export 'src/collection/iterable/iterate.dart' show iterate;
export 'src/collection/iterable/operators.dart' show OperatorsIterableExtension;
export 'src/collection/iterable/pairwise.dart' show PairwiseIterableExtension;
export 'src/collection/iterable/permutations.dart'
show PermutationIterableExtension, PermutationComparableListExtension;
show PermutationComparableListExtension, PermutationIterableExtension;
export 'src/collection/iterable/power_set.dart' show PowerSetIterableExtension;
export 'src/collection/iterable/product.dart'
show ProductIterableExtension, Product2IterableExtension;
show Product2IterableExtension, ProductIterableExtension;
export 'src/collection/iterable/random.dart' show RandomIterableExtension;
export 'src/collection/iterable/repeat_element.dart' show repeat;
export 'src/collection/iterable/repeat_iterable.dart'
Expand All @@ -32,7 +34,7 @@ export 'src/collection/iterable/to_map.dart' show ToMapIterableExtension;
export 'src/collection/iterable/unique.dart' show UniqueIterableExtension;
export 'src/collection/iterable/window.dart' show WindowIterableExtension;
export 'src/collection/iterable/zip.dart'
show ZipIterableExtension, Zip2IterableExtension;
show Zip2IterableExtension, ZipIterableExtension;
export 'src/collection/list/rotate.dart'
show RotateListExtension, RotateQueueExtension;
export 'src/collection/list/take_skip.dart' show TakeSkipListExtension;
Expand All @@ -41,18 +43,18 @@ export 'src/collection/map/default.dart'
export 'src/collection/multimap/list.dart'
show
ListMultimap,
ListMultimapOnMapExtension,
ListMultimapOnIterableExtension;
ListMultimapOnIterableExtension,
ListMultimapOnMapExtension;
export 'src/collection/multimap/set.dart'
show SetMultimap, SetMultimapOnMapExtension, SetMultimapOnIterableExtension;
show SetMultimap, SetMultimapOnIterableExtension, SetMultimapOnMapExtension;
export 'src/collection/multiset.dart' show Multiset, MultisetExtension;
export 'src/collection/range.dart' show Range, RangeIterator;
export 'src/collection/range/bigint.dart'
show BigIntRange, BigIntRangeExtension;
export 'src/collection/range/double.dart'
show DoubleRange, DoubleRangeExtension;
export 'src/collection/range/integer.dart'
show IntegerRange, IntegerRangeExtension, IndicesIterableExtension;
show IndicesIterableExtension, IntegerRange, IntegerRangeExtension;
export 'src/collection/rtree.dart' show RTree;
export 'src/collection/rtree/bounds.dart' show Bounds;
export 'src/collection/rtree/entry.dart' show RTreeEntry;
Expand Down
2 changes: 2 additions & 0 deletions lib/comparator.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// Provides default [Comparator] constructors, and various static extension
/// methods to modify and perform common operations on [Comparator] functions.
library comparator;

export 'src/comparator/compare_operators.dart';
export 'src/comparator/constructors/explicit.dart';
export 'src/comparator/constructors/natural.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/feature.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// Information about the runtime environment.
library feature;

/// True, if the code is running in JavaScript.
const bool isJavaScript = identical(1, 1.0);
Expand Down
2 changes: 2 additions & 0 deletions lib/functional.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// A collection of functional programming structures.
library functional;

export 'src/functional/either.dart' show Either;
export 'src/functional/optional.dart' show Optional;
export 'src/functional/types.dart';
2 changes: 2 additions & 0 deletions lib/graph.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Graph-theory objects and algorithms.
library graph;

export 'src/graph/builder.dart' show GraphBuilder;
export 'src/graph/builder/atlas.dart' show AtlasGraphBuilderExtension;
export 'src/graph/builder/collection.dart' show CollectionGraphBuilderExtension;
Expand Down
2 changes: 2 additions & 0 deletions lib/interval.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// Provides a continuous interval over a [Comparable].
library interval;

export 'src/interval/interval.dart';
export 'src/interval/length.dart';
14 changes: 8 additions & 6 deletions lib/math.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/// A collection of common mathematical functions.
library math;

export 'src/math/binomial.dart'
show BinomialIntegerExtension, BinomialBigIntExtension;
show BinomialBigIntExtension, BinomialIntegerExtension;
export 'src/math/bit.dart' show BitUint32Extension;
export 'src/math/digits.dart'
show DigitsIntegerExtension, DigitsBigIntExtension;
show DigitsBigIntExtension, DigitsIntegerExtension;
export 'src/math/factorial.dart'
show FactorialIntegerExtension, FactorialBigIntExtension;
show FactorialBigIntExtension, FactorialIntegerExtension;
export 'src/math/hyperbolic.dart' show HyperbolicNumberExtension;
export 'src/math/is_probably_prime.dart'
show
ProbablyPrimeIntegerExtension,
ProbablyPrimeBigIntExtension,
ProbablyPrimeComplexExtension;
export 'src/math/lcm.dart' show LcmIntegerExtension, LcmBigIntExtension;
ProbablyPrimeComplexExtension,
ProbablyPrimeIntegerExtension;
export 'src/math/lcm.dart' show LcmBigIntExtension, LcmIntegerExtension;
export 'src/math/math.dart' show MathNumberExtension;
export 'src/math/polynomial.dart' show PolynomialIterableExtension;
export 'src/math/primes/atkin.dart' show AtkinPrimeSieve;
Expand Down
2 changes: 2 additions & 0 deletions lib/more.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// More Dart — Literally.
library more;

export 'package:more/async.dart';
export 'package:more/cache.dart';
export 'package:more/char_matcher.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/number.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Support for fractional and complex arithmetic.
library number;

export 'src/number/bigint.dart' show BigIntExtension;
export 'src/number/complex.dart' show Complex;
export 'src/number/fraction.dart' show Fraction;
Expand Down
6 changes: 4 additions & 2 deletions lib/printer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// Provides a first-class model to convert object to strings using composition
/// and highly configurable formatting primitives.
library printer;

export 'src/printer/builder.dart' show BuilderPrinterExtension;
export 'src/printer/empty.dart' show EmptyPrinterExtension;
export 'src/printer/iterable.dart' show IterablePrinterExtension;
Expand All @@ -18,9 +20,9 @@ export 'src/printer/printer.dart' show Printer;
export 'src/printer/result_of.dart' show ResultOfPrinterExtension;
export 'src/printer/sequence.dart'
show
SequencePrinterPrinterExtension,
SequencePrinter,
SequencePrinterIterableExtension,
SequencePrinter;
SequencePrinterPrinterExtension;
export 'src/printer/standard.dart' show StandardPrinter;
export 'src/printer/string/pad.dart' show PadPrinterExtension;
export 'src/printer/string/separate.dart' show SeparatePrinterExtension;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/async/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension WindowStreamExtension<E> on Stream<E> {
checkNonZeroPositive(step, 'step');
var index = 0;
final current = ListQueue<E>(size);
await for (var element in this) {
await for (final element in this) {
while (current.length >= size) {
current.removeFirst();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/src/char_matcher/char_matcher.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// A first-class model of character classes, their composition and operations
/// on strings.
import 'package:meta/meta.dart' show immutable;

import '../../printer.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collection/iterable/flatten.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension DeepFlattenIterableExtension on Iterable<dynamic> {
/// print(input.deepFlatten()); // [1, 2, 3, 4, 5, 6]
///
Iterable<E> deepFlatten<E>() sync* {
for (var value in this) {
for (final value in this) {
if (value is E) {
yield value;
} else if (value is Iterable) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collection/iterable/separated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension SeparatedIterableExtension<E> on Iterable<E> {
Iterable<E> separatedBy(Builder<E> separator,
{Builder<E>? before, Builder<E>? after}) sync* {
var index = 0;
for (var iterator = this.iterator; iterator.moveNext(); index++) {
for (final iterator = this.iterator; iterator.moveNext(); index++) {
if (index == 0 && before != null) yield before();
if (index > 0) yield separator();
yield iterator.current;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collection/iterable/to_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension ToMapIterableExtension<E> on Iterable<E> {
final keyProvider = key ?? (element) => element as K;
final valueProvider = value ?? (element) => element as V;
return {
for (var element in this) keyProvider(element): valueProvider(element),
for (final element in this) keyProvider(element): valueProvider(element),
};
}
}
2 changes: 1 addition & 1 deletion lib/src/collection/rtree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class RTree<T> {
/// The root node of the tree.
late RTreeNode<T> root = RTreeNode<T>(this, isLeaf: true);

/// Associates [data] with the provided [bounds].
/// Associates [data] with the provided [bound].
RTreeEntry<T> insert(Bounds bound, T data) {
final entry = RTreeEntry<T>(bound, data: data);
final node = chooseLeaf(entry);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collection/trie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class TrieNodeMap<K, P extends Comparable<P>, V>

@override
TrieNode<K, P, V> addChild(P part) =>
_children.putIfAbsent(part, () => TrieNodeMap<K, P, V>());
_children.putIfAbsent(part, TrieNodeMap<K, P, V>.new);

@override
TrieNode<K, P, V>? getChild(P part) => _children[part];
Expand Down
2 changes: 1 addition & 1 deletion lib/src/comparator/modifiers/compound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension CompoundIterableComparator<T> on Iterable<Comparator<T>> {
/// iterable in order and returns the first result that doesn't end up
/// in a tie.
Comparator<T> toComparator() => (a, b) {
for (var comparator in this) {
for (final comparator in this) {
final result = comparator(a, b);
if (result != 0) return result;
}
Expand Down
Loading

0 comments on commit 5b6aff4

Please sign in to comment.