Browse Source

Added pedantic to Notus and fixed lint warnings

Anatoly Pulyaevskiy 5 years ago
parent
commit
c021f294e2

+ 1
- 19
packages/notus/analysis_options.yaml View File

@@ -1,19 +1 @@
1
-analyzer:
2
-  strong-mode:
3
-    implicit-dynamic: false
4
-
5
-# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
6
-linter:
7
-  rules:
8
-    - avoid_init_to_null
9
-    - cancel_subscriptions
10
-    - close_sinks
11
-    - directives_ordering
12
-    - hash_and_equals
13
-    - iterable_contains_unrelated_type
14
-    - list_remove_unrelated_type
15
-    - prefer_final_fields
16
-    - prefer_is_not_empty
17
-    - test_types_in_equals
18
-    - unrelated_type_equality_checks
19
-    - valid_regexps
1
+include: package:pedantic/analysis_options.yaml

+ 2
- 2
packages/notus/example/main.dart View File

@@ -5,7 +5,7 @@
5 5
 import 'package:notus/notus.dart';
6 6
 
7 7
 void main() {
8
-  final doc = new NotusDocument();
8
+  final doc = NotusDocument();
9 9
   // Modify this document with insert, delete and format operations
10 10
   doc.insert(
11 11
       0, 'Notus package provides rich text document model for Zefyr editor');
@@ -17,7 +17,7 @@ void main() {
17 17
   doc.collectStyle(1, 0); // returned style would include "bold" and "h1".
18 18
 
19 19
   // Listen to all changes applied to this document.
20
-  doc.changes.listen((change){
20
+  doc.changes.listen((change) {
21 21
     print(change);
22 22
   });
23 23
 

+ 1
- 1
packages/notus/lib/convert.dart View File

@@ -10,4 +10,4 @@ import 'src/convert/markdown.dart';
10 10
 export 'src/convert/markdown.dart';
11 11
 
12 12
 /// Markdown codec for Notus documents.
13
-const NotusMarkdownCodec notusMarkdown = const NotusMarkdownCodec();
13
+const NotusMarkdownCodec notusMarkdown = NotusMarkdownCodec();

+ 12
- 12
packages/notus/lib/src/convert/markdown.dart View File

@@ -12,10 +12,10 @@ class NotusMarkdownCodec extends Codec<Delta, String> {
12 12
 
13 13
   @override
14 14
   Converter<String, Delta> get decoder =>
15
-      throw new UnimplementedError('Decoding is not implemented yet.');
15
+      throw UnimplementedError('Decoding is not implemented yet.');
16 16
 
17 17
   @override
18
-  Converter<Delta, String> get encoder => new _NotusMarkdownEncoder();
18
+  Converter<Delta, String> get encoder => _NotusMarkdownEncoder();
19 19
 }
20 20
 
21 21
 class _NotusMarkdownEncoder extends Converter<Delta, String> {
@@ -29,11 +29,11 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
29 29
 
30 30
   @override
31 31
   String convert(Delta input) {
32
-    final iterator = new DeltaIterator(input);
33
-    final buffer = new StringBuffer();
34
-    final lineBuffer = new StringBuffer();
32
+    final iterator = DeltaIterator(input);
33
+    final buffer = StringBuffer();
34
+    final lineBuffer = StringBuffer();
35 35
     NotusAttribute<String> currentBlockStyle;
36
-    NotusStyle currentInlineStyle = new NotusStyle();
36
+    NotusStyle currentInlineStyle = NotusStyle();
37 37
     List<String> currentBlockLines = [];
38 38
 
39 39
     void _handleBlock(NotusAttribute<String> blockStyle) {
@@ -86,7 +86,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
86 86
       if (lf == -1) {
87 87
         _handleSpan(op.data, op.attributes);
88 88
       } else {
89
-        StringBuffer span = new StringBuffer();
89
+        StringBuffer span = StringBuffer();
90 90
         for (var i = 0; i < op.data.length; i++) {
91 91
           if (op.data.codeUnitAt(i) == 0x0A) {
92 92
             if (span.isNotEmpty) {
@@ -112,7 +112,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
112 112
   }
113 113
 
114 114
   String _writeLine(String text, NotusStyle style) {
115
-    StringBuffer buffer = new StringBuffer();
115
+    StringBuffer buffer = StringBuffer();
116 116
     if (style.contains(NotusAttribute.heading)) {
117 117
       _writeAttribute(buffer, style.get<int>(NotusAttribute.heading));
118 118
     }
@@ -157,7 +157,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
157 157
   }
158 158
 
159 159
   void _writeAttribute(StringBuffer buffer, NotusAttribute attribute,
160
-      {bool close: false}) {
160
+      {bool close = false}) {
161 161
     if (attribute == NotusAttribute.bold) {
162 162
       _writeBoldTag(buffer);
163 163
     } else if (attribute == NotusAttribute.italic) {
@@ -169,7 +169,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
169 169
     } else if (attribute.key == NotusAttribute.block.key) {
170 170
       _writeBlockTag(buffer, attribute as NotusAttribute<String>, close: close);
171 171
     } else {
172
-      throw new ArgumentError('Cannot handle $attribute');
172
+      throw ArgumentError('Cannot handle $attribute');
173 173
     }
174 174
   }
175 175
 
@@ -182,7 +182,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
182 182
   }
183 183
 
184 184
   void _writeLinkTag(StringBuffer buffer, NotusAttribute<String> link,
185
-      {bool close: false}) {
185
+      {bool close = false}) {
186 186
     if (close) {
187 187
       buffer.write('](${link.value})');
188 188
     } else {
@@ -196,7 +196,7 @@ class _NotusMarkdownEncoder extends Converter<Delta, String> {
196 196
   }
197 197
 
198 198
   void _writeBlockTag(StringBuffer buffer, NotusAttribute<String> block,
199
-      {bool close: false}) {
199
+      {bool close = false}) {
200 200
     if (block == NotusAttribute.code) {
201 201
       if (close) {
202 202
         buffer.write('\n```');

+ 9
- 9
packages/notus/lib/src/document.dart View File

@@ -40,7 +40,7 @@ class NotusDocument {
40 40
   /// Creates new empty Notus document.
41 41
   NotusDocument()
42 42
       : _heuristics = NotusHeuristics.fallback,
43
-        _delta = new Delta()..insert('\n') {
43
+        _delta = Delta()..insert('\n') {
44 44
     _loadDocument(_delta);
45 45
   }
46 46
 
@@ -61,7 +61,7 @@ class NotusDocument {
61 61
 
62 62
   /// The root node of this document tree.
63 63
   RootNode get root => _root;
64
-  final RootNode _root = new RootNode();
64
+  final RootNode _root = RootNode();
65 65
 
66 66
   /// Length of this document.
67 67
   int get length => _root.length;
@@ -70,10 +70,10 @@ class NotusDocument {
70 70
   Stream<NotusChange> get changes => _controller.stream;
71 71
 
72 72
   final StreamController<NotusChange> _controller =
73
-      new StreamController.broadcast();
73
+      StreamController.broadcast();
74 74
 
75 75
   /// Returns contents of this document as [Delta].
76
-  Delta toDelta() => new Delta.from(_delta);
76
+  Delta toDelta() => Delta.from(_delta);
77 77
   Delta _delta;
78 78
 
79 79
   /// Returns plain text representation of this document.
@@ -104,7 +104,7 @@ class NotusDocument {
104 104
     assert(index >= 0);
105 105
     assert(text.isNotEmpty);
106 106
     text = _sanitizeString(text);
107
-    if (text.isEmpty) return new Delta();
107
+    if (text.isEmpty) return Delta();
108 108
     final change = _heuristics.applyInsertRules(this, index, text);
109 109
     compose(change, ChangeSource.local);
110 110
     return change;
@@ -136,7 +136,7 @@ class NotusDocument {
136 136
   Delta replace(int index, int length, String text) {
137 137
     assert(index >= 0 && (text.isNotEmpty || length > 0),
138 138
         'With index $index, length $length and text "$text"');
139
-    Delta delta = new Delta();
139
+    Delta delta = Delta();
140 140
     // We have to compose before applying delete rules
141 141
     // Otherwise delete would be operating on stale document snapshot.
142 142
     if (text.isNotEmpty) {
@@ -239,10 +239,10 @@ class NotusDocument {
239 239
     _delta = _delta.compose(change);
240 240
 
241 241
     if (_delta != _root.toDelta()) {
242
-      throw new StateError('Compose produced inconsistent results. '
242
+      throw StateError('Compose produced inconsistent results. '
243 243
           'This is likely due to a bug in the library. Tried to compose change $change from $source.');
244 244
     }
245
-    _controller.add(new NotusChange(before, change, source));
245
+    _controller.add(NotusChange(before, change, source));
246 246
   }
247 247
 
248 248
   //
@@ -279,7 +279,7 @@ class NotusDocument {
279 279
       if (op.isInsert) {
280 280
         _root.insert(offset, op.data, style);
281 281
       } else {
282
-        throw new ArgumentError.value(doc,
282
+        throw ArgumentError.value(doc,
283 283
             "Document Delta can only contain insert operations but ${op.key} found.");
284 284
       }
285 285
       offset += op.length;

+ 39
- 34
packages/notus/lib/src/document/attributes.dart View File

@@ -40,9 +40,9 @@ abstract class NotusAttributeBuilder<T> implements NotusAttributeKey<T> {
40 40
 
41 41
   final String key;
42 42
   final NotusAttributeScope scope;
43
-  NotusAttribute<T> get unset => new NotusAttribute<T>._(key, scope, null);
43
+  NotusAttribute<T> get unset => NotusAttribute<T>._(key, scope, null);
44 44
   NotusAttribute<T> withValue(T value) =>
45
-      new NotusAttribute<T>._(key, scope, value);
45
+      NotusAttribute<T>._(key, scope, value);
46 46
 }
47 47
 
48 48
 /// Style attribute applicable to a segment of a Notus document.
@@ -82,18 +82,20 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
82 82
   // Inline attributes
83 83
 
84 84
   /// Bold style attribute.
85
-  static const bold = const _BoldAttribute();
85
+  static const bold = _BoldAttribute();
86 86
 
87 87
   /// Italic style attribute.
88
-  static const italic = const _ItalicAttribute();
88
+  static const italic = _ItalicAttribute();
89 89
 
90 90
   /// Link style attribute.
91
-  static const link = const LinkAttributeBuilder._();
91
+  // ignore: const_eval_throws_exception
92
+  static const link = LinkAttributeBuilder._();
92 93
 
93 94
   // Line attributes
94 95
 
95 96
   /// Heading style attribute.
96
-  static const heading = const HeadingAttributeBuilder._();
97
+  // ignore: const_eval_throws_exception
98
+  static const heading = HeadingAttributeBuilder._();
97 99
 
98 100
   /// Alias for [NotusAttribute.heading.level1].
99 101
   static NotusAttribute<int> get h1 => heading.level1;
@@ -105,7 +107,8 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
105 107
   static NotusAttribute<int> get h3 => heading.level3;
106 108
 
107 109
   /// Block attribute
108
-  static const block = const BlockAttributeBuilder._();
110
+  // ignore: const_eval_throws_exception
111
+  static const block = BlockAttributeBuilder._();
109 112
 
110 113
   /// Alias for [NotusAttribute.block.bulletList].
111 114
   static NotusAttribute<String> get ul => block.bulletList;
@@ -120,12 +123,14 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
120 123
   static NotusAttribute<String> get code => block.code;
121 124
 
122 125
   /// Embed style attribute.
123
-  static const embed = const EmbedAttributeBuilder._();
126
+  // ignore: const_eval_throws_exception
127
+  static const embed = EmbedAttributeBuilder._();
124 128
 
125 129
   static NotusAttribute _fromKeyValue(String key, dynamic value) {
126
-    if (!_registry.containsKey(key))
127
-      throw new ArgumentError.value(
130
+    if (!_registry.containsKey(key)) {
131
+      throw ArgumentError.value(
128 132
           key, 'No attribute with key "$key" registered.');
133
+    }
129 134
     final builder = _registry[key];
130 135
     return builder.withValue(value);
131 136
   }
@@ -154,7 +159,7 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
154 159
   ///
155 160
   /// When composed into a rich text document, unset attributes remove
156 161
   /// associated style.
157
-  NotusAttribute<T> get unset => new NotusAttribute<T>._(key, scope, null);
162
+  NotusAttribute<T> get unset => NotusAttribute<T>._(key, scope, null);
158 163
 
159 164
   /// Returns `true` if this attribute is an unset attribute.
160 165
   bool get isUnset => value == null;
@@ -163,7 +168,7 @@ class NotusAttribute<T> implements NotusAttributeBuilder<T> {
163 168
   bool get isInline => scope == NotusAttributeScope.inline;
164 169
 
165 170
   NotusAttribute<T> withValue(T value) =>
166
-      new NotusAttribute<T>._(key, scope, value);
171
+      NotusAttribute<T>._(key, scope, value);
167 172
 
168 173
   @override
169 174
   bool operator ==(Object other) {
@@ -191,16 +196,16 @@ class NotusStyle {
191 196
   final Map<String, NotusAttribute> _data;
192 197
 
193 198
   static NotusStyle fromJson(Map<String, dynamic> data) {
194
-    if (data == null) return new NotusStyle();
199
+    if (data == null) return NotusStyle();
195 200
 
196 201
     final result = data.map((String key, dynamic value) {
197 202
       var attr = NotusAttribute._fromKeyValue(key, value);
198
-      return new MapEntry<String, NotusAttribute>(key, attr);
203
+      return MapEntry<String, NotusAttribute>(key, attr);
199 204
     });
200
-    return new NotusStyle._(result);
205
+    return NotusStyle._(result);
201 206
   }
202 207
 
203
-  NotusStyle() : _data = new Map<String, NotusAttribute>();
208
+  NotusStyle() : _data = Map<String, NotusAttribute>();
204 209
 
205 210
   /// Returns `true` if this attribute set is empty.
206 211
   bool get isEmpty => _data.isEmpty;
@@ -246,9 +251,9 @@ class NotusStyle {
246 251
 
247 252
   /// Puts [attribute] into this attribute set and returns result as a new set.
248 253
   NotusStyle put(NotusAttribute attribute) {
249
-    final result = new Map<String, NotusAttribute>.from(_data);
254
+    final result = Map<String, NotusAttribute>.from(_data);
250 255
     result[attribute.key] = attribute;
251
-    return new NotusStyle._(result);
256
+    return NotusStyle._(result);
252 257
   }
253 258
 
254 259
   /// Merges this attribute set with [attribute] and returns result as a new
@@ -260,19 +265,19 @@ class NotusStyle {
260 265
   /// See also [put] method which does not perform compaction and allows
261 266
   /// constructing styles with "unset" values.
262 267
   NotusStyle merge(NotusAttribute attribute) {
263
-    final merged = new Map<String, NotusAttribute>.from(_data);
268
+    final merged = Map<String, NotusAttribute>.from(_data);
264 269
     if (attribute.isUnset) {
265 270
       merged.remove(attribute.key);
266 271
     } else {
267 272
       merged[attribute.key] = attribute;
268 273
     }
269
-    return new NotusStyle._(merged);
274
+    return NotusStyle._(merged);
270 275
   }
271 276
 
272 277
   /// Merges all attributes from [other] into this style and returns result
273 278
   /// as a new instance of [NotusStyle].
274 279
   NotusStyle mergeAll(NotusStyle other) {
275
-    var result = new NotusStyle._(_data);
280
+    var result = NotusStyle._(_data);
276 281
     for (var value in other.values) {
277 282
       result = result.merge(value);
278 283
     }
@@ -282,16 +287,16 @@ class NotusStyle {
282 287
   /// Removes [attributes] from this style and returns new instance of
283 288
   /// [NotusStyle] containing result.
284 289
   NotusStyle removeAll(Iterable<NotusAttribute> attributes) {
285
-    final merged = new Map<String, NotusAttribute>.from(_data);
290
+    final merged = Map<String, NotusAttribute>.from(_data);
286 291
     attributes.map((item) => item.key).forEach(merged.remove);
287
-    return new NotusStyle._(merged);
292
+    return NotusStyle._(merged);
288 293
   }
289 294
 
290 295
   /// Returns JSON-serializable representation of this style.
291 296
   Map<String, dynamic> toJson() => _data.isEmpty
292 297
       ? null
293 298
       : _data.map<String, dynamic>((String _, NotusAttribute value) =>
294
-          new MapEntry<String, dynamic>(value.key, value.value));
299
+          MapEntry<String, dynamic>(value.key, value.value));
295 300
 
296 301
   @override
297 302
   bool operator ==(Object other) {
@@ -332,7 +337,7 @@ class LinkAttributeBuilder extends NotusAttributeBuilder<String> {
332 337
 
333 338
   /// Creates a link attribute with specified link [value].
334 339
   NotusAttribute<String> fromString(String value) =>
335
-      new NotusAttribute<String>._(key, scope, value);
340
+      NotusAttribute<String>._(key, scope, value);
336 341
 }
337 342
 
338 343
 /// Builder for heading attribute styles.
@@ -345,13 +350,13 @@ class HeadingAttributeBuilder extends NotusAttributeBuilder<int> {
345 350
       : super._(_kHeading, NotusAttributeScope.line);
346 351
 
347 352
   /// Level 1 heading, equivalent of `H1` in HTML.
348
-  NotusAttribute<int> get level1 => new NotusAttribute<int>._(key, scope, 1);
353
+  NotusAttribute<int> get level1 => NotusAttribute<int>._(key, scope, 1);
349 354
 
350 355
   /// Level 2 heading, equivalent of `H2` in HTML.
351
-  NotusAttribute<int> get level2 => new NotusAttribute<int>._(key, scope, 2);
356
+  NotusAttribute<int> get level2 => NotusAttribute<int>._(key, scope, 2);
352 357
 
353 358
   /// Level 3 heading, equivalent of `H3` in HTML.
354
-  NotusAttribute<int> get level3 => new NotusAttribute<int>._(key, scope, 3);
359
+  NotusAttribute<int> get level3 => NotusAttribute<int>._(key, scope, 3);
355 360
 }
356 361
 
357 362
 /// Builder for block attribute styles (number/bullet lists, code and quote).
@@ -364,19 +369,19 @@ class BlockAttributeBuilder extends NotusAttributeBuilder<String> {
364 369
 
365 370
   /// Formats a block of lines as a bullet list.
366 371
   NotusAttribute<String> get bulletList =>
367
-      new NotusAttribute<String>._(key, scope, 'ul');
372
+      NotusAttribute<String>._(key, scope, 'ul');
368 373
 
369 374
   /// Formats a block of lines as a number list.
370 375
   NotusAttribute<String> get numberList =>
371
-      new NotusAttribute<String>._(key, scope, 'ol');
376
+      NotusAttribute<String>._(key, scope, 'ol');
372 377
 
373 378
   /// Formats a block of lines as a code snippet, using monospace font.
374 379
   NotusAttribute<String> get code =>
375
-      new NotusAttribute<String>._(key, scope, 'code');
380
+      NotusAttribute<String>._(key, scope, 'code');
376 381
 
377 382
   /// Formats a block of lines as a quote.
378 383
   NotusAttribute<String> get quote =>
379
-      new NotusAttribute<String>._(key, scope, 'quote');
384
+      NotusAttribute<String>._(key, scope, 'quote');
380 385
 }
381 386
 
382 387
 class EmbedAttributeBuilder
@@ -401,7 +406,7 @@ class EmbedAttributeBuilder
401 406
 enum EmbedType { horizontalRule, image }
402 407
 
403 408
 class EmbedAttribute extends NotusAttribute<Map<String, dynamic>> {
404
-  static const _kValueEquality = const MapEquality<String, dynamic>();
409
+  static const _kValueEquality = MapEquality<String, dynamic>();
405 410
   static const _kEmbed = 'embed';
406 411
   static const _kHorizontalRuleEmbed = 'hr';
407 412
   static const _kImageEmbed = 'image';
@@ -424,7 +429,7 @@ class EmbedAttribute extends NotusAttribute<Map<String, dynamic>> {
424 429
   }
425 430
 
426 431
   @override
427
-  NotusAttribute<Map<String, dynamic>> get unset => new EmbedAttribute._(null);
432
+  NotusAttribute<Map<String, dynamic>> get unset => EmbedAttribute._(null);
428 433
 
429 434
   @override
430 435
   bool operator ==(other) {

+ 4
- 4
packages/notus/lib/src/document/block.dart View File

@@ -16,7 +16,7 @@ class BlockNode extends ContainerNode<LineNode>
16 16
     implements StyledNode {
17 17
   /// Creates new unmounted [BlockNode] with the same attributes.
18 18
   BlockNode clone() {
19
-    final node = new BlockNode();
19
+    final node = BlockNode();
20 20
     node.applyStyle(style);
21 21
     return node;
22 22
   }
@@ -49,20 +49,20 @@ class BlockNode extends ContainerNode<LineNode>
49 49
   }
50 50
 
51 51
   @override
52
-  LineNode get defaultChild => new LineNode();
52
+  LineNode get defaultChild => LineNode();
53 53
 
54 54
   @override
55 55
   Delta toDelta() {
56 56
     // Line nodes take care of incorporating block style into their delta.
57 57
     return children
58 58
         .map((child) => child.toDelta())
59
-        .fold(new Delta(), (a, b) => a.concat(b));
59
+        .fold(Delta(), (a, b) => a.concat(b));
60 60
   }
61 61
 
62 62
   @override
63 63
   String toString() {
64 64
     final block = style.value(NotusAttribute.block);
65
-    final buffer = new StringBuffer('§ {$block}\n');
65
+    final buffer = StringBuffer('§ {$block}\n');
66 66
     for (var child in children) {
67 67
       final tree = child.isLast ? '└' : '├';
68 68
       buffer.write('  $tree $child');

+ 7
- 7
packages/notus/lib/src/document/leaf.dart View File

@@ -22,13 +22,13 @@ abstract class LeafNode extends Node
22 22
     LeafNode node;
23 23
     if (value == kZeroWidthSpace) {
24 24
       // Zero-width space is reserved for embed nodes.
25
-      node = new EmbedNode();
25
+      node = EmbedNode();
26 26
     } else {
27 27
       assert(
28 28
           !value.contains(kZeroWidthSpace),
29 29
           'Zero-width space is reserved for embed leaf nodes and cannot be used '
30 30
           'inside regular text nodes.');
31
-      node = new TextNode(value);
31
+      node = TextNode(value);
32 32
     }
33 33
     return node;
34 34
   }
@@ -56,7 +56,7 @@ abstract class LeafNode extends Node
56 56
 
57 57
     String text = _value;
58 58
     _value = text.substring(0, index);
59
-    final split = new LeafNode(text.substring(index));
59
+    final split = LeafNode(text.substring(index));
60 60
     split.applyStyle(style);
61 61
     insertAfter(split);
62 62
     return split;
@@ -131,7 +131,7 @@ abstract class LeafNode extends Node
131 131
 
132 132
   @override
133 133
   Delta toDelta() {
134
-    return new Delta()..insert(_value, style.toJson());
134
+    return Delta()..insert(_value, style.toJson());
135 135
   }
136 136
 
137 137
   @override
@@ -141,7 +141,7 @@ abstract class LeafNode extends Node
141 141
   void insert(int index, String value, NotusStyle style) {
142 142
     assert(index >= 0 && (index <= length), 'Index: $index, Length: $length.');
143 143
     assert(value.isNotEmpty);
144
-    final node = new LeafNode(value);
144
+    final node = LeafNode(value);
145 145
     if (index == length) {
146 146
       insertAfter(node);
147 147
     } else {
@@ -231,7 +231,7 @@ class TextNode extends LeafNode {
231 231
   TextNode([String content = '']) : super._(content);
232 232
 }
233 233
 
234
-final kZeroWidthSpace = new String.fromCharCode(0x200b);
234
+final kZeroWidthSpace = String.fromCharCode(0x200b);
235 235
 
236 236
 /// An embed node inside of a line in a Notus document.
237 237
 ///
@@ -248,7 +248,7 @@ final kZeroWidthSpace = new String.fromCharCode(0x200b);
248 248
 /// applying "bold" style to an image gives no effect, while adding a "link" to
249 249
 /// an image actually makes the image react to user's action.
250 250
 class EmbedNode extends LeafNode {
251
-  static final kPlainTextPlaceholder = new String.fromCharCode(0x200b);
251
+  static final kPlainTextPlaceholder = String.fromCharCode(0x200b);
252 252
 
253 253
   EmbedNode() : super._(kPlainTextPlaceholder);
254 254
 }

+ 13
- 11
packages/notus/lib/src/document/line.dart View File

@@ -38,8 +38,9 @@ class LineNode extends ContainerNode<LeafNode>
38 38
             ? (parent.next as BlockNode).first
39 39
             : parent.next;
40 40
         return line;
41
-      } else
41
+      } else {
42 42
         return null;
43
+      }
43 44
     } else {
44 45
       LineNode line = (next is BlockNode) ? (next as BlockNode).first : next;
45 46
       return line;
@@ -48,7 +49,7 @@ class LineNode extends ContainerNode<LeafNode>
48 49
 
49 50
   /// Creates new empty [LineNode] with the same style.
50 51
   LineNode clone() {
51
-    final node = new LineNode();
52
+    final node = LineNode();
52 53
     node.applyStyle(style);
53 54
     return node;
54 55
   }
@@ -107,8 +108,8 @@ class LineNode extends ContainerNode<LeafNode>
107 108
   NotusStyle collectStyle(int offset, int length) {
108 109
     int local = math.min(this.length - offset, length);
109 110
 
110
-    NotusStyle result = new NotusStyle();
111
-    Set<NotusAttribute> excluded = new Set();
111
+    NotusStyle result = NotusStyle();
112
+    Set<NotusAttribute> excluded = Set();
112 113
 
113 114
     void _handle(NotusStyle style) {
114 115
       if (result.isEmpty) {
@@ -153,7 +154,7 @@ class LineNode extends ContainerNode<LeafNode>
153 154
   }
154 155
 
155 156
   @override
156
-  LeafNode get defaultChild => new TextNode();
157
+  LeafNode get defaultChild => TextNode();
157 158
 
158 159
   // TODO: should be able to cache length and invalidate on any child-related operation
159 160
   @override
@@ -163,7 +164,7 @@ class LineNode extends ContainerNode<LeafNode>
163 164
   Delta toDelta() {
164 165
     final Delta delta = children
165 166
         .map((text) => text.toDelta())
166
-        .fold(new Delta(), (a, b) => a.concat(b));
167
+        .fold(Delta(), (a, b) => a.concat(b));
167 168
     var attributes = style;
168 169
     if (parent is BlockNode) {
169 170
       BlockNode block = parent;
@@ -293,8 +294,9 @@ class LineNode extends ContainerNode<LeafNode>
293 294
     if (newStyle == null || newStyle.isEmpty) return;
294 295
 
295 296
     applyStyle(newStyle);
296
-    if (!newStyle.contains(NotusAttribute.block))
297
-      return; // no block-level changes
297
+    if (!newStyle.contains(NotusAttribute.block)) {
298
+      return;
299
+    } // no block-level changes
298 300
 
299 301
     final blockStyle = newStyle.get(NotusAttribute.block);
300 302
     if (parent is BlockNode) {
@@ -303,14 +305,14 @@ class LineNode extends ContainerNode<LeafNode>
303 305
         unwrap();
304 306
       } else if (blockStyle != parentStyle) {
305 307
         unwrap();
306
-        BlockNode block = new BlockNode();
308
+        BlockNode block = BlockNode();
307 309
         block.applyAttribute(blockStyle);
308 310
         wrap(block);
309 311
         block.optimize();
310 312
       } // else the same style, no-op.
311 313
     } else if (blockStyle != NotusAttribute.block.unset) {
312 314
       // Only wrap with a new block if this is not an unset
313
-      BlockNode block = new BlockNode();
315
+      BlockNode block = BlockNode();
314 316
       block.applyAttribute(blockStyle);
315 317
       wrap(block);
316 318
       block.optimize();
@@ -323,7 +325,7 @@ class LineNode extends ContainerNode<LeafNode>
323 325
     if (text.isEmpty) return;
324 326
 
325 327
     if (isEmpty) {
326
-      final child = new LeafNode(text);
328
+      final child = LeafNode(text);
327 329
       add(child);
328 330
       child.formatAndOptimize(style);
329 331
     } else {

+ 8
- 8
packages/notus/lib/src/document/node.dart View File

@@ -136,7 +136,7 @@ class LookupResult {
136 136
 /// Most of the operation handling logic is implemented by [LineNode] and
137 137
 /// [TextNode].
138 138
 abstract class ContainerNode<T extends Node> extends Node {
139
-  final LinkedList<Node> _children = new LinkedList<Node>();
139
+  final LinkedList<Node> _children = LinkedList<Node>();
140 140
 
141 141
   /// List of children.
142 142
   LinkedList<Node> get children => _children;
@@ -207,17 +207,17 @@ abstract class ContainerNode<T extends Node> extends Node {
207 207
   /// [LookupResult.offset] is set to relative offset within returned child node
208 208
   /// which points at the same character position in the document as the
209 209
   /// original [offset].
210
-  LookupResult lookup(int offset, {bool inclusive: false}) {
210
+  LookupResult lookup(int offset, {bool inclusive = false}) {
211 211
     assert(offset >= 0 && offset <= this.length);
212 212
 
213 213
     for (Node node in children) {
214 214
       final int length = node.length;
215 215
       if (offset < length || (inclusive && offset == length && (node.isLast))) {
216
-        return new LookupResult(node, offset);
216
+        return LookupResult(node, offset);
217 217
       }
218 218
       offset -= length;
219 219
     }
220
-    return new LookupResult(null, 0);
220
+    return LookupResult(null, 0);
221 221
   }
222 222
 
223 223
   //
@@ -275,7 +275,7 @@ abstract class StyledNode implements Node {
275 275
 abstract class StyledNodeMixin implements StyledNode {
276 276
   @override
277 277
   NotusStyle get style => _style;
278
-  NotusStyle _style = new NotusStyle();
278
+  NotusStyle _style = NotusStyle();
279 279
 
280 280
   /// Applies style [attribute] to this node.
281 281
   void applyAttribute(NotusAttribute attribute) {
@@ -291,14 +291,14 @@ abstract class StyledNodeMixin implements StyledNode {
291 291
 
292 292
   /// Clears style of this node.
293 293
   void clearStyle() {
294
-    _style = new NotusStyle();
294
+    _style = NotusStyle();
295 295
   }
296 296
 }
297 297
 
298 298
 /// Root node of document tree.
299 299
 class RootNode extends ContainerNode<ContainerNode<Node>> {
300 300
   @override
301
-  ContainerNode<Node> get defaultChild => new LineNode();
301
+  ContainerNode<Node> get defaultChild => LineNode();
302 302
 
303 303
   @override
304 304
   void optimize() {/* no-op */}
@@ -306,5 +306,5 @@ class RootNode extends ContainerNode<ContainerNode<Node>> {
306 306
   @override
307 307
   Delta toDelta() => children
308 308
       .map((child) => child.toDelta())
309
-      .fold(new Delta(), (a, b) => a.concat(b));
309
+      .fold(Delta(), (a, b) => a.concat(b));
310 310
 }

+ 3
- 6
packages/notus/lib/src/heuristics.dart View File

@@ -62,8 +62,7 @@ class NotusHeuristics {
62 62
       final result = rule.apply(delta, index, insert);
63 63
       if (result != null) return result..trim();
64 64
     }
65
-    throw new StateError(
66
-        'Failed to apply insert heuristic rules: none applied.');
65
+    throw StateError('Failed to apply insert heuristic rules: none applied.');
67 66
   }
68 67
 
69 68
   /// Applies heuristic rules to specified format operation based on current
@@ -75,8 +74,7 @@ class NotusHeuristics {
75 74
       final result = rule.apply(delta, index, length, value);
76 75
       if (result != null) return result..trim();
77 76
     }
78
-    throw new StateError(
79
-        'Failed to apply format heuristic rules: none applied.');
77
+    throw StateError('Failed to apply format heuristic rules: none applied.');
80 78
   }
81 79
 
82 80
   /// Applies heuristic rules to specified delete operation based on current
@@ -87,7 +85,6 @@ class NotusHeuristics {
87 85
       final result = rule.apply(delta, index, length);
88 86
       if (result != null) return result..trim();
89 87
     }
90
-    throw new StateError(
91
-        'Failed to apply delete heuristic rules: none applied.');
88
+    throw StateError('Failed to apply delete heuristic rules: none applied.');
92 89
   }
93 90
 }

+ 7
- 7
packages/notus/lib/src/heuristics/delete_rules.dart View File

@@ -22,7 +22,7 @@ class CatchAllDeleteRule extends DeleteRule {
22 22
 
23 23
   @override
24 24
   Delta apply(Delta document, int index, int length) {
25
-    return new Delta()
25
+    return Delta()
26 26
       ..retain(index)
27 27
       ..delete(length);
28 28
   }
@@ -39,12 +39,12 @@ class PreserveLineStyleOnMergeRule extends DeleteRule {
39 39
 
40 40
   @override
41 41
   Delta apply(Delta document, int index, int length) {
42
-    DeltaIterator iter = new DeltaIterator(document);
42
+    DeltaIterator iter = DeltaIterator(document);
43 43
     iter.skip(index);
44 44
     final target = iter.next(1);
45 45
     if (target.data != '\n') return null;
46 46
     iter.skip(length - 1);
47
-    final Delta result = new Delta()
47
+    final Delta result = Delta()
48 48
       ..retain(index)
49 49
       ..delete(length);
50 50
 
@@ -69,8 +69,8 @@ class PreserveLineStyleOnMergeRule extends DeleteRule {
69 69
 
70 70
   Map<String, dynamic> _unsetAttributes(Map<String, dynamic> attributes) {
71 71
     if (attributes == null) return null;
72
-    return attributes.map<String, dynamic>((String key, dynamic value) =>
73
-        new MapEntry<String, dynamic>(key, null));
72
+    return attributes.map<String, dynamic>(
73
+        (String key, dynamic value) => MapEntry<String, dynamic>(key, null));
74 74
   }
75 75
 }
76 76
 
@@ -80,7 +80,7 @@ class EnsureEmbedLineRule extends DeleteRule {
80 80
 
81 81
   @override
82 82
   Delta apply(Delta document, int index, int length) {
83
-    DeltaIterator iter = new DeltaIterator(document);
83
+    DeltaIterator iter = DeltaIterator(document);
84 84
 
85 85
     // First, check if line-break deleted after an embed.
86 86
     Operation op = iter.skip(index);
@@ -123,7 +123,7 @@ class EnsureEmbedLineRule extends DeleteRule {
123 123
     }
124 124
 
125 125
     if (foundEmbed) {
126
-      return new Delta()
126
+      return Delta()
127 127
         ..retain(index + indexDelta)
128 128
         ..delete(length + lengthDelta);
129 129
     }

+ 11
- 11
packages/notus/lib/src/heuristics/format_rules.dart View File

@@ -24,8 +24,8 @@ class ResolveLineFormatRule extends FormatRule {
24 24
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
25 25
     if (attribute.scope != NotusAttributeScope.line) return null;
26 26
 
27
-    Delta result = new Delta()..retain(index);
28
-    final iter = new DeltaIterator(document);
27
+    Delta result = Delta()..retain(index);
28
+    final iter = DeltaIterator(document);
29 29
     iter.skip(index);
30 30
 
31 31
     // Apply line styles to all line-break characters within range of this
@@ -56,7 +56,7 @@ class ResolveLineFormatRule extends FormatRule {
56 56
   }
57 57
 
58 58
   Delta _applyAttribute(String text, NotusAttribute attribute) {
59
-    final result = new Delta();
59
+    final result = Delta();
60 60
     int offset = 0;
61 61
     int lf = text.indexOf('\n');
62 62
     while (lf >= 0) {
@@ -79,8 +79,8 @@ class ResolveInlineFormatRule extends FormatRule {
79 79
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
80 80
     if (attribute.scope != NotusAttributeScope.inline) return null;
81 81
 
82
-    Delta result = new Delta()..retain(index);
83
-    final iter = new DeltaIterator(document);
82
+    Delta result = Delta()..retain(index);
83
+    final iter = DeltaIterator(document);
84 84
     iter.skip(index);
85 85
 
86 86
     // Apply inline styles to all non-line-break characters within range of this
@@ -122,8 +122,8 @@ class FormatLinkAtCaretPositionRule extends FormatRule {
122 122
     // edge cases.
123 123
     if (length != 0) return null;
124 124
 
125
-    Delta result = new Delta();
126
-    final iter = new DeltaIterator(document);
125
+    Delta result = Delta();
126
+    final iter = DeltaIterator(document);
127 127
     final before = iter.skip(index);
128 128
     final after = iter.next();
129 129
     int startIndex = index;
@@ -157,7 +157,7 @@ class FormatEmbedsRule extends FormatRule {
157 157
 
158 158
     if (length == 1 && embed.isUnset) {
159 159
       // Remove the embed.
160
-      return new Delta()
160
+      return Delta()
161 161
         ..retain(index)
162 162
         ..delete(length);
163 163
     } else {
@@ -171,8 +171,8 @@ class FormatEmbedsRule extends FormatRule {
171 171
 
172 172
   Delta _insertEmbed(
173 173
       Delta document, int index, int length, EmbedAttribute embed) {
174
-    Delta result = new Delta()..retain(index);
175
-    final iter = new DeltaIterator(document);
174
+    Delta result = Delta()..retain(index);
175
+    final iter = DeltaIterator(document);
176 176
     final previous = iter.skip(index);
177 177
     iter.skip(length); // ignore deleted part.
178 178
     final target = iter.next();
@@ -200,7 +200,7 @@ class FormatEmbedsRule extends FormatRule {
200 200
 
201 201
   Map<String, dynamic> _getLineStyle(
202 202
       DeltaIterator iterator, Operation current) {
203
-    if (current.data.indexOf('\n') >= 0) {
203
+    if (current.data.contains('\n')) {
204 204
       return current.attributes;
205 205
     }
206 206
     // Continue looking for line-break.

+ 18
- 18
packages/notus/lib/src/heuristics/insert_rules.dart View File

@@ -21,7 +21,7 @@ class CatchAllInsertRule extends InsertRule {
21 21
 
22 22
   @override
23 23
   Delta apply(Delta document, int index, String text) {
24
-    return new Delta()
24
+    return Delta()
25 25
       ..retain(index)
26 26
       ..insert(text);
27 27
   }
@@ -43,12 +43,12 @@ class PreserveLineStyleOnSplitRule extends InsertRule {
43 43
   Delta apply(Delta document, int index, String text) {
44 44
     if (text != '\n') return null;
45 45
 
46
-    DeltaIterator iter = new DeltaIterator(document);
46
+    DeltaIterator iter = DeltaIterator(document);
47 47
     final before = iter.skip(index);
48 48
     final after = iter.next();
49 49
     if (isEdgeLineSplit(before, after)) return null;
50
-    Delta result = new Delta()..retain(index);
51
-    if (after.data.indexOf('\n') >= 0) {
50
+    Delta result = Delta()..retain(index);
51
+    if (after.data.contains('\n')) {
52 52
       // It is not allowed to combine line and inline styles in insert
53 53
       // operation containing line-break together with other characters.
54 54
       // The only scenario we get such operation is when the text is plain.
@@ -82,7 +82,7 @@ class ResetLineFormatOnNewLineRule extends InsertRule {
82 82
   Delta apply(Delta document, int index, String text) {
83 83
     if (text != '\n') return null;
84 84
 
85
-    DeltaIterator iter = new DeltaIterator(document);
85
+    DeltaIterator iter = DeltaIterator(document);
86 86
     iter.skip(index);
87 87
     final target = iter.next();
88 88
 
@@ -92,7 +92,7 @@ class ResetLineFormatOnNewLineRule extends InsertRule {
92 92
           target.attributes.containsKey(NotusAttribute.heading.key)) {
93 93
         resetStyle = NotusAttribute.heading.unset.toJson();
94 94
       }
95
-      return new Delta()
95
+      return Delta()
96 96
         ..retain(index)
97 97
         ..insert('\n', target.attributes)
98 98
         ..retain(1, resetStyle)
@@ -117,7 +117,7 @@ class AutoExitBlockRule extends InsertRule {
117 117
   Delta apply(Delta document, int index, String text) {
118 118
     if (text != '\n') return null;
119 119
 
120
-    DeltaIterator iter = new DeltaIterator(document);
120
+    DeltaIterator iter = DeltaIterator(document);
121 121
     final previous = iter.skip(index);
122 122
     final target = iter.next();
123 123
     final isInBlock = target.isNotPlain &&
@@ -129,7 +129,7 @@ class AutoExitBlockRule extends InsertRule {
129 129
       var attributes =
130 130
           target.attributes != null ? target.attributes : <String, dynamic>{};
131 131
       attributes.addAll(NotusAttribute.block.unset.toJson());
132
-      return new Delta()..retain(index)..retain(1, attributes);
132
+      return Delta()..retain(index)..retain(1, attributes);
133 133
     }
134 134
     return null;
135 135
   }
@@ -144,7 +144,7 @@ class PreserveInlineStylesRule extends InsertRule {
144 144
     // This rule is only applicable to characters other than line-break.
145 145
     if (text.contains('\n')) return null;
146 146
 
147
-    DeltaIterator iter = new DeltaIterator(document);
147
+    DeltaIterator iter = DeltaIterator(document);
148 148
     final previous = iter.skip(index);
149 149
     // If there is a line-break in previous chunk, there should be no inline
150 150
     // styles. Also if there is no previous operation we are at the beginning
@@ -155,7 +155,7 @@ class PreserveInlineStylesRule extends InsertRule {
155 155
     final hasLink =
156 156
         (attributes != null && attributes.containsKey(NotusAttribute.link.key));
157 157
     if (!hasLink) {
158
-      return new Delta()
158
+      return Delta()
159 159
         ..retain(index)
160 160
         ..insert(text, attributes);
161 161
     }
@@ -164,7 +164,7 @@ class PreserveInlineStylesRule extends InsertRule {
164 164
     // Link style should NOT be preserved on the boundaries.
165 165
     var noLinkAttributes = previous.attributes;
166 166
     noLinkAttributes.remove(NotusAttribute.link.key);
167
-    final noLinkResult = new Delta()
167
+    final noLinkResult = Delta()
168 168
       ..retain(index)
169 169
       ..insert(text, noLinkAttributes.isEmpty ? null : noLinkAttributes);
170 170
     final next = iter.next();
@@ -180,7 +180,7 @@ class PreserveInlineStylesRule extends InsertRule {
180 180
     // We must make sure links are identical in previous and next operations.
181 181
     if (attributes[NotusAttribute.link.key] ==
182 182
         nextAttributes[NotusAttribute.link.key]) {
183
-      return new Delta()
183
+      return Delta()
184 184
         ..retain(index)
185 185
         ..insert(text, attributes);
186 186
     } else {
@@ -200,7 +200,7 @@ class AutoFormatLinksRule extends InsertRule {
200 200
     // everything else.
201 201
     if (text != ' ') return null;
202 202
 
203
-    DeltaIterator iter = new DeltaIterator(document);
203
+    DeltaIterator iter = DeltaIterator(document);
204 204
     final previous = iter.skip(index);
205 205
     // No previous operation means no link.
206 206
     if (previous == null) return null;
@@ -220,7 +220,7 @@ class AutoFormatLinksRule extends InsertRule {
220 220
 
221 221
       attributes
222 222
           .addAll(NotusAttribute.link.fromString(link.toString()).toJson());
223
-      return new Delta()
223
+      return Delta()
224 224
         ..retain(index - candidate.length)
225 225
         ..retain(candidate.length, attributes)
226 226
         ..insert(text, previous.attributes);
@@ -239,13 +239,13 @@ class ForceNewlineForInsertsAroundEmbedRule extends InsertRule {
239 239
 
240 240
   @override
241 241
   Delta apply(Delta document, int index, String text) {
242
-    DeltaIterator iter = new DeltaIterator(document);
242
+    DeltaIterator iter = DeltaIterator(document);
243 243
     final previous = iter.skip(index);
244 244
     final target = iter.next();
245 245
     final beforeEmbed = target.data == EmbedNode.kPlainTextPlaceholder;
246 246
     final afterEmbed = previous?.data == EmbedNode.kPlainTextPlaceholder;
247 247
     if (beforeEmbed || afterEmbed) {
248
-      final delta = new Delta()..retain(index);
248
+      final delta = Delta()..retain(index);
249 249
       if (beforeEmbed && !text.endsWith('\n')) {
250 250
         return delta..insert(text)..insert('\n');
251 251
       }
@@ -276,7 +276,7 @@ class PreserveBlockStyleOnPasteRule extends InsertRule {
276 276
       return null;
277 277
     }
278 278
 
279
-    DeltaIterator iter = new DeltaIterator(document);
279
+    DeltaIterator iter = DeltaIterator(document);
280 280
     iter.skip(index);
281 281
 
282 282
     // Look for next line-break.
@@ -305,7 +305,7 @@ class PreserveBlockStyleOnPasteRule extends InsertRule {
305 305
     }
306 306
 
307 307
     final lines = text.split('\n');
308
-    Delta result = new Delta()..retain(index);
308
+    Delta result = Delta()..retain(index);
309 309
     for (int i = 0; i < lines.length; i++) {
310 310
       final line = lines[i];
311 311
       if (line.isNotEmpty) {

+ 1
- 0
packages/notus/pubspec.yaml View File

@@ -14,5 +14,6 @@ dependencies:
14 14
   quiver_hashcode: ^2.0.0
15 15
 
16 16
 dev_dependencies:
17
+  pedantic: ^1.0.0
17 18
   test: ^1.0.0
18 19
   test_coverage: ^0.2.1

+ 9
- 13
packages/notus/test/convert/markdown_test.dart View File

@@ -19,14 +19,14 @@ void main() {
19 19
 
20 20
   group('$NotusMarkdownCodec.encode', () {
21 21
     test('split adjacent paragraphs', () {
22
-      final delta = new Delta()..insert('First line\nSecond line\n');
22
+      final delta = Delta()..insert('First line\nSecond line\n');
23 23
       final result = notusMarkdown.encode(delta);
24 24
       expect(result, 'First line\n\nSecond line\n\n');
25 25
     });
26 26
 
27 27
     test('bold italic', () {
28 28
       runFor(NotusAttribute<bool> attribute, String expected) {
29
-        final delta = new Delta()
29
+        final delta = Delta()
30 30
           ..insert('This ')
31 31
           ..insert('house', attribute.toJson())
32 32
           ..insert(' is a ')
@@ -44,10 +44,10 @@ void main() {
44 44
     test('intersecting inline styles', () {
45 45
       final b = NotusAttribute.bold.toJson();
46 46
       final i = NotusAttribute.italic.toJson();
47
-      final bi = new Map<String, dynamic>.from(b);
47
+      final bi = Map<String, dynamic>.from(b);
48 48
       bi.addAll(i);
49 49
 
50
-      final delta = new Delta()
50
+      final delta = Delta()
51 51
         ..insert('This ')
52 52
         ..insert('house', b)
53 53
         ..insert(' is a ', bi)
@@ -61,7 +61,7 @@ void main() {
61 61
     test('normalize inline styles', () {
62 62
       final b = NotusAttribute.bold.toJson();
63 63
       final i = NotusAttribute.italic.toJson();
64
-      final delta = new Delta()
64
+      final delta = Delta()
65 65
         ..insert('This')
66 66
         ..insert(' house ', b)
67 67
         ..insert('is a')
@@ -75,7 +75,7 @@ void main() {
75 75
     test('links', () {
76 76
       final b = NotusAttribute.bold.toJson();
77 77
       final link = NotusAttribute.link.fromString('https://github.com');
78
-      final delta = new Delta()
78
+      final delta = Delta()
79 79
         ..insert('This')
80 80
         ..insert(' house ', b)
81 81
         ..insert('is a')
@@ -88,9 +88,7 @@ void main() {
88 88
 
89 89
     test('heading styles', () {
90 90
       runFor(NotusAttribute<int> attribute, String source, String expected) {
91
-        final delta = new Delta()
92
-          ..insert(source)
93
-          ..insert('\n', attribute.toJson());
91
+        final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
94 92
         final result = notusMarkdown.encode(delta);
95 93
         expect(result, expected);
96 94
       }
@@ -102,9 +100,7 @@ void main() {
102 100
 
103 101
     test('block styles', () {
104 102
       runFor(NotusAttribute<String> attribute, String source, String expected) {
105
-        final delta = new Delta()
106
-          ..insert(source)
107
-          ..insert('\n', attribute.toJson());
103
+        final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
108 104
         final result = notusMarkdown.encode(delta);
109 105
         expect(result, expected);
110 106
       }
@@ -117,7 +113,7 @@ void main() {
117 113
 
118 114
     test('multiline blocks', () {
119 115
       runFor(NotusAttribute<String> attribute, String source, String expected) {
120
-        final delta = new Delta()
116
+        final delta = Delta()
121 117
           ..insert(source)
122 118
           ..insert('\n', attribute.toJson())
123 119
           ..insert(source)

+ 16
- 19
packages/notus/test/document/block_test.dart View File

@@ -5,28 +5,28 @@ import 'package:notus/notus.dart';
5 5
 import 'package:test/test.dart';
6 6
 import 'package:quill_delta/quill_delta.dart';
7 7
 
8
-final ulAttrs = new NotusStyle().merge(NotusAttribute.ul);
9
-final olAttrs = new NotusStyle().merge(NotusAttribute.ol);
10
-final h1Attrs = new NotusStyle().merge(NotusAttribute.h1);
8
+final ulAttrs = NotusStyle().merge(NotusAttribute.ul);
9
+final olAttrs = NotusStyle().merge(NotusAttribute.ol);
10
+final h1Attrs = NotusStyle().merge(NotusAttribute.h1);
11 11
 
12 12
 void main() {
13 13
   group('$BlockNode', () {
14 14
     ContainerNode root;
15 15
     setUp(() {
16
-      root = new RootNode();
16
+      root = RootNode();
17 17
     });
18 18
 
19 19
     test('empty', () {
20
-      BlockNode node = new BlockNode();
20
+      BlockNode node = BlockNode();
21 21
       expect(node, isEmpty);
22 22
       expect(node.length, 0);
23
-      expect(node.style, new NotusStyle());
23
+      expect(node.style, NotusStyle());
24 24
     });
25 25
 
26 26
     test('toString', () {
27
-      LineNode line = new LineNode();
28
-      line.add(new TextNode('London "Grammar"'));
29
-      BlockNode block = new BlockNode();
27
+      LineNode line = LineNode();
28
+      line.add(TextNode('London "Grammar"'));
29
+      BlockNode block = BlockNode();
30 30
       block.applyAttribute(NotusAttribute.ul);
31 31
       block.add(line);
32 32
       final expected = '§ {ul}\n  └ ¶ ⟨London "Grammar"⟩ ⏎';
@@ -54,13 +54,12 @@ void main() {
54 54
 
55 55
       expect(root.childCount, 1);
56 56
       BlockNode block = root.first;
57
-      expect(block.style.get(NotusAttribute.block),
58
-          NotusAttribute.ul);
57
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
59 58
       expect(block.childCount, 1);
60 59
       expect(block.first, const TypeMatcher<LineNode>());
61 60
 
62 61
       LineNode line = block.first;
63
-      Delta delta = new Delta()
62
+      Delta delta = Delta()
64 63
         ..insert('Hello world')
65 64
         ..insert('\n', ulAttrs.toJson());
66 65
       expect(line.toDelta(), delta);
@@ -72,8 +71,7 @@ void main() {
72 71
 
73 72
       expect(root.childCount, 2);
74 73
       BlockNode block = root.last;
75
-      expect(block.style.get(NotusAttribute.block),
76
-          NotusAttribute.ul);
74
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
77 75
       expect(block.childCount, 1);
78 76
       expect(block.first, const TypeMatcher<LineNode>());
79 77
     });
@@ -85,8 +83,7 @@ void main() {
85 83
 
86 84
       expect(root.childCount, 1);
87 85
       BlockNode block = root.first;
88
-      expect(block.style.get(NotusAttribute.block),
89
-          NotusAttribute.ul);
86
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
90 87
       expect(block.childCount, 2);
91 88
       expect(block.first, const TypeMatcher<LineNode>());
92 89
       expect(block.last, const TypeMatcher<LineNode>());
@@ -102,7 +99,7 @@ void main() {
102 99
       expect(root.childCount, 2);
103 100
       root.retain(28, 1, olAttrs);
104 101
       expect(root.childCount, 3);
105
-      final expected = new Delta()
102
+      final expected = Delta()
106 103
         ..insert('London Grammar Songs')
107 104
         ..insert('\n', NotusAttribute.h1.toJson())
108 105
         ..insert('Hey now')
@@ -124,7 +121,7 @@ void main() {
124 121
       expect(root.childCount, 2);
125 122
       root.retain(47, 1, olAttrs);
126 123
       expect(root.childCount, 3);
127
-      final expected = new Delta()
124
+      final expected = Delta()
128 125
         ..insert('London Grammar Songs')
129 126
         ..insert('\n', NotusAttribute.h1.toJson())
130 127
         ..insert('Hey now')
@@ -146,7 +143,7 @@ void main() {
146 143
       expect(root.childCount, 2);
147 144
       root.retain(35, 1, olAttrs);
148 145
       expect(root.childCount, 4);
149
-      final expected = new Delta()
146
+      final expected = Delta()
150 147
         ..insert('London Grammar Songs')
151 148
         ..insert('\n', NotusAttribute.h1.toJson())
152 149
         ..insert('Hey now')

+ 28
- 32
packages/notus/test/document/line_test.dart View File

@@ -5,31 +5,31 @@ import 'package:test/test.dart';
5 5
 import 'package:quill_delta/quill_delta.dart';
6 6
 import 'package:notus/notus.dart';
7 7
 
8
-final boldStyle = new NotusStyle().merge(NotusAttribute.bold);
9
-final h1Style = new NotusStyle().merge(NotusAttribute.h1);
10
-final h2Style = new NotusStyle().merge(NotusAttribute.h2);
11
-final ulStyle = new NotusStyle().merge(NotusAttribute.ul);
12
-final bqStyle = new NotusStyle().merge(NotusAttribute.bq);
8
+final boldStyle = NotusStyle().merge(NotusAttribute.bold);
9
+final h1Style = NotusStyle().merge(NotusAttribute.h1);
10
+final h2Style = NotusStyle().merge(NotusAttribute.h2);
11
+final ulStyle = NotusStyle().merge(NotusAttribute.ul);
12
+final bqStyle = NotusStyle().merge(NotusAttribute.bq);
13 13
 
14 14
 void main() {
15 15
   group('$LineNode', () {
16 16
     ContainerNode root;
17 17
     setUp(() {
18
-      root = new RootNode();
18
+      root = RootNode();
19 19
     });
20 20
 
21 21
     test('empty', () {
22
-      LineNode node = new LineNode();
22
+      LineNode node = LineNode();
23 23
       expect(node, isEmpty);
24 24
       expect(node.length, 1);
25
-      expect(node.style, new NotusStyle());
26
-      expect(node.toDelta().toList(), [new Operation.insert('\n')]);
25
+      expect(node.style, NotusStyle());
26
+      expect(node.toDelta().toList(), [Operation.insert('\n')]);
27 27
     });
28 28
 
29 29
     test('hasEmbed', () {
30
-      LineNode node = new LineNode();
30
+      LineNode node = LineNode();
31 31
       expect(node.hasEmbed, isFalse);
32
-      node.add(new EmbedNode());
32
+      node.add(EmbedNode());
33 33
       expect(node.hasEmbed, isTrue);
34 34
     });
35 35
 
@@ -50,7 +50,7 @@ void main() {
50 50
     });
51 51
 
52 52
     test('toString', () {
53
-      LineNode node = new LineNode();
53
+      LineNode node = LineNode();
54 54
       node.insert(0, 'London "Grammar" - Hey Now', null);
55 55
       node.retain(0, 16, boldStyle);
56 56
       node.applyAttribute(NotusAttribute.h1);
@@ -68,22 +68,21 @@ void main() {
68 68
     });
69 69
 
70 70
     test('insert into empty line', () {
71
-      LineNode node = new LineNode();
71
+      LineNode node = LineNode();
72 72
       node.insert(0, 'London "Grammar" - Hey Now', null);
73 73
       expect(node, hasLength(27));
74
-      expect(
75
-          node.toDelta(), new Delta()..insert('London "Grammar" - Hey Now\n'));
74
+      expect(node.toDelta(), Delta()..insert('London "Grammar" - Hey Now\n'));
76 75
     });
77 76
 
78 77
     test('insert into empty line with styles', () {
79
-      LineNode node = new LineNode();
78
+      LineNode node = LineNode();
80 79
       node.insert(0, 'London "Grammar" - Hey Now', null);
81 80
       node.retain(0, 16, boldStyle);
82 81
       node.applyAttribute(NotusAttribute.h1);
83 82
       expect(node, hasLength(27));
84 83
       expect(node.childCount, 2);
85 84
 
86
-      final delta = new Delta()
85
+      final delta = Delta()
87 86
         ..insert('London "Grammar"', boldStyle.toJson())
88 87
         ..insert(' - Hey Now')
89 88
         ..insert('\n', NotusAttribute.h1.toJson());
@@ -91,12 +90,12 @@ void main() {
91 90
     });
92 91
 
93 92
     test('insert into non-empty line', () {
94
-      LineNode node = new LineNode();
93
+      LineNode node = LineNode();
95 94
       node.insert(0, 'Hello world', null);
96 95
       node.insert(11, '!!!', null);
97 96
       expect(node, hasLength(15));
98 97
       expect(node.childCount, 1);
99
-      expect(node.toDelta(), new Delta()..insert('Hello world!!!\n'));
98
+      expect(node.toDelta(), Delta()..insert('Hello world!!!\n'));
100 99
     });
101 100
 
102 101
     test('insert text with line-break at the end of line', () {
@@ -106,11 +105,11 @@ void main() {
106 105
 
107 106
       LineNode line = root.first;
108 107
       expect(line, hasLength(15));
109
-      expect(line.toDelta(), new Delta()..insert('Hello world!!!\n'));
108
+      expect(line.toDelta(), Delta()..insert('Hello world!!!\n'));
110 109
 
111 110
       LineNode line2 = root.last;
112 111
       expect(line2, hasLength(1));
113
-      expect(line2.toDelta(), new Delta()..insert('\n'));
112
+      expect(line2.toDelta(), Delta()..insert('\n'));
114 113
     });
115 114
 
116 115
     test('insert into second text segment', () {
@@ -120,7 +119,7 @@ void main() {
120 119
 
121 120
       LineNode line = root.first;
122 121
       expect(line, hasLength(15));
123
-      Delta delta = new Delta()
122
+      Delta delta = Delta()
124 123
         ..insert('Hello ')
125 124
         ..insert('world', boldStyle.toJson())
126 125
         ..insert('!!!\n');
@@ -134,7 +133,7 @@ void main() {
134 133
       LineNode line = root.first;
135 134
       expect(line, hasLength(12));
136 135
 
137
-      Delta delta = new Delta()
136
+      Delta delta = Delta()
138 137
         ..insert('Hello world')
139 138
         ..insert('\n', NotusAttribute.h1.toJson());
140 139
       expect(line.toDelta(), delta);
@@ -155,7 +154,7 @@ void main() {
155 154
     });
156 155
 
157 156
     test('format root line to unset block style', () {
158
-      final unsetBlock = new NotusStyle().put(NotusAttribute.block.unset);
157
+      final unsetBlock = NotusStyle().put(NotusAttribute.block.unset);
159 158
       root.insert(0, 'Hello world', null);
160 159
       root.retain(11, 1, unsetBlock);
161 160
       expect(root.childCount, 1);
@@ -188,7 +187,7 @@ void main() {
188 187
       LineNode line = root.first;
189 188
       expect(line, hasLength(8));
190 189
       expect(line.childCount, 1);
191
-      Delta lineDelta = new Delta()..insert('Hellord\n');
190
+      Delta lineDelta = Delta()..insert('Hellord\n');
192 191
       expect(line.toDelta(), lineDelta);
193 192
     });
194 193
 
@@ -199,7 +198,7 @@ void main() {
199 198
       expect(root.childCount, 1);
200 199
       LineNode line = root.first;
201 200
       expect(line, hasLength(18));
202
-      Delta lineDelta = new Delta()
201
+      Delta lineDelta = Delta()
203 202
         ..insert('Hello ')
204 203
         ..insert('worl', boldStyle.toJson())
205 204
         ..insert(' cd ef!\n');
@@ -213,9 +212,7 @@ void main() {
213 212
       expect(root.childCount, 1);
214 213
       LineNode line = root.first;
215 214
       expect(line.childCount, 1);
216
-      final delta = new Delta()
217
-        ..insert('delnes')
218
-        ..insert('\n', h2Style.toJson());
215
+      final delta = Delta()..insert('delnes')..insert('\n', h2Style.toJson());
219 216
       expect(line.toDelta(), delta);
220 217
     });
221 218
 
@@ -252,8 +249,7 @@ void main() {
252 249
       root.delete(37, 1);
253 250
       expect(root.childCount, 3);
254 251
       LineNode line = root.children.elementAt(1);
255
-      expect(
256
-          line.toDelta(), new Delta()..insert('This is my first multilin\n'));
252
+      expect(line.toDelta(), Delta()..insert('This is my first multilin\n'));
257 253
     });
258 254
 
259 255
     test('collectStyle', () {
@@ -270,7 +266,7 @@ void main() {
270 266
 
271 267
     test('collectStyle with embed nodes', () {
272 268
       root.insert(0, 'Hello world\n\nMore text.\n', null);
273
-      NotusStyle style = new NotusStyle();
269
+      NotusStyle style = NotusStyle();
274 270
       style = style.put(NotusAttribute.embed.horizontalRule);
275 271
       root.insert(12, EmbedNode.kPlainTextPlaceholder, style);
276 272
 

+ 3
- 3
packages/notus/test/document/node_test.dart View File

@@ -8,12 +8,12 @@ void main() {
8 8
   group('$Node', () {
9 9
     RootNode root;
10 10
     setUp(() {
11
-      root = new RootNode();
11
+      root = RootNode();
12 12
     });
13 13
 
14 14
     test('mounted', () {
15
-      LineNode line = new LineNode();
16
-      TextNode text = new TextNode();
15
+      LineNode line = LineNode();
16
+      TextNode text = TextNode();
17 17
       expect(text.mounted, isFalse);
18 18
       line.add(text);
19 19
       expect(text.mounted, isTrue);

+ 11
- 12
packages/notus/test/document/text_test.dart View File

@@ -5,9 +5,9 @@ import 'package:test/test.dart';
5 5
 import 'package:quill_delta/quill_delta.dart';
6 6
 import 'package:notus/notus.dart';
7 7
 
8
-final boldStyle = new NotusStyle().merge(NotusAttribute.bold);
9
-final boldUnsetStyle = new NotusStyle().put(NotusAttribute.bold.unset);
10
-final italicStyle = new NotusStyle().merge(NotusAttribute.italic);
8
+final boldStyle = NotusStyle().merge(NotusAttribute.bold);
9
+final boldUnsetStyle = NotusStyle().put(NotusAttribute.bold.unset);
10
+final italicStyle = NotusStyle().merge(NotusAttribute.italic);
11 11
 
12 12
 void main() {
13 13
   group('$TextNode', () {
@@ -15,16 +15,16 @@ void main() {
15 15
     TextNode node;
16 16
 
17 17
     setUp(() {
18
-      line = new LineNode();
19
-      node = new TextNode('London "Grammar"');
18
+      line = LineNode();
19
+      node = TextNode('London "Grammar"');
20 20
       line.add(node);
21 21
     });
22 22
 
23 23
     test('new empty text', () {
24
-      final node = new TextNode();
24
+      final node = TextNode();
25 25
       expect(node.value, isEmpty);
26 26
       expect(node.length, 0);
27
-      expect(node.style, new NotusStyle());
27
+      expect(node.style, NotusStyle());
28 28
       expect(node.toDelta(), isEmpty);
29 29
     });
30 30
 
@@ -37,8 +37,7 @@ void main() {
37 37
     test('new text with contents', () {
38 38
       expect(node.value, isNotEmpty);
39 39
       expect(node.length, 16);
40
-      expect(
41
-          node.toDelta().toList(), [new Operation.insert('London "Grammar"')]);
40
+      expect(node.toDelta().toList(), [Operation.insert('London "Grammar"')]);
42 41
     });
43 42
 
44 43
     test('insert at the end', () {
@@ -99,15 +98,15 @@ void main() {
99 98
       final b = boldStyle.toJson();
100 99
       expect(
101 100
         line.children.elementAt(0).toDelta(),
102
-        new Delta()..insert('Lon', b),
101
+        Delta()..insert('Lon', b),
103 102
       );
104 103
       expect(
105 104
         line.children.elementAt(1).toDelta(),
106
-        new Delta()..insert('don'),
105
+        Delta()..insert('don'),
107 106
       );
108 107
       expect(
109 108
         line.children.elementAt(2).toDelta(),
110
-        new Delta()..insert('don', b),
109
+        Delta()..insert('don', b),
111 110
       );
112 111
     });
113 112
   });

+ 19
- 19
packages/notus/test/document_test.dart View File

@@ -9,18 +9,18 @@ import 'package:notus/notus.dart';
9 9
 import 'matchers.dart';
10 10
 
11 11
 NotusDocument dartconfDoc() {
12
-  Delta delta = new Delta()..insert('DartConf\nLos Angeles\n');
13
-  return new NotusDocument.fromDelta(delta);
12
+  Delta delta = Delta()..insert('DartConf\nLos Angeles\n');
13
+  return NotusDocument.fromDelta(delta);
14 14
 }
15 15
 
16 16
 NotusDocument dartconfEmbedDoc() {
17 17
   final hr = NotusAttribute.embed.horizontalRule.toJson();
18
-  Delta delta = new Delta()
18
+  Delta delta = Delta()
19 19
     ..insert('DartConf\n')
20 20
     ..insert(kZeroWidthSpace, hr)
21 21
     ..insert('\n')
22 22
     ..insert('Los Angeles\n');
23
-  return new NotusDocument.fromDelta(delta);
23
+  return NotusDocument.fromDelta(delta);
24 24
 }
25 25
 
26 26
 final ul = NotusAttribute.ul.toJson();
@@ -29,17 +29,17 @@ final h1 = NotusAttribute.h1.toJson();
29 29
 void main() {
30 30
   group('$NotusDocument', () {
31 31
     test('validates for doc delta', () {
32
-      var badDelta = new Delta()
32
+      var badDelta = Delta()
33 33
         ..insert('Text')
34 34
         ..retain(5)
35 35
         ..insert('\n');
36 36
       expect(() {
37
-        new NotusDocument.fromDelta(badDelta);
37
+        NotusDocument.fromDelta(badDelta);
38 38
       }, throwsArgumentError);
39 39
     });
40 40
 
41 41
     test('empty document contains single empty line', () {
42
-      NotusDocument doc = new NotusDocument();
42
+      NotusDocument doc = NotusDocument();
43 43
       expect(doc.toPlainText(), '\n');
44 44
     });
45 45
 
@@ -67,9 +67,9 @@ void main() {
67 67
     });
68 68
 
69 69
     test('document delta must end with line-break character', () {
70
-      Delta delta = new Delta()..insert('DartConf\nLos Angeles');
70
+      Delta delta = Delta()..insert('DartConf\nLos Angeles');
71 71
       expect(() {
72
-        new NotusDocument.fromDelta(delta);
72
+        NotusDocument.fromDelta(delta);
73 73
       }, throwsA(const TypeMatcher<AssertionError>()));
74 74
     });
75 75
 
@@ -105,7 +105,7 @@ void main() {
105 105
     test('format returns actual change delta', () {
106 106
       NotusDocument doc = dartconfDoc();
107 107
       final change = doc.format(0, 15, NotusAttribute.ul);
108
-      final expectedChange = new Delta()
108
+      final expectedChange = Delta()
109 109
         ..retain(8)
110 110
         ..retain(1, ul)
111 111
         ..retain(11)
@@ -116,7 +116,7 @@ void main() {
116 116
     test('format updates document delta', () {
117 117
       NotusDocument doc = dartconfDoc();
118 118
       doc.format(0, 15, NotusAttribute.ul);
119
-      final expectedDoc = new Delta()
119
+      final expectedDoc = Delta()
120 120
         ..insert('DartConf')
121 121
         ..insert('\n', ul)
122 122
         ..insert('Los Angeles')
@@ -127,7 +127,7 @@ void main() {
127 127
     test('format allows zero-length updates', () {
128 128
       NotusDocument doc = dartconfDoc();
129 129
       doc.format(0, 0, NotusAttribute.ul);
130
-      final expectedDoc = new Delta()
130
+      final expectedDoc = Delta()
131 131
         ..insert('DartConf')
132 132
         ..insert('\n', ul)
133 133
         ..insert('Los Angeles')
@@ -147,7 +147,7 @@ void main() {
147 147
       NotusDocument doc = dartconfDoc();
148 148
       doc.format(0, 15, NotusAttribute.ul);
149 149
       final change = doc.insert(8, '\n');
150
-      final expectedChange = new Delta()
150
+      final expectedChange = Delta()
151 151
         ..retain(8)
152 152
         ..insert('\n', ul);
153 153
       expect(change, expectedChange);
@@ -157,7 +157,7 @@ void main() {
157 157
       NotusDocument doc = dartconfDoc();
158 158
       doc.format(0, 15, NotusAttribute.ul);
159 159
       doc.insert(8, '\n');
160
-      final expectedDoc = new Delta()
160
+      final expectedDoc = Delta()
161 161
         ..insert('DartConf')
162 162
         ..insert('\n\n', ul)
163 163
         ..insert('Los Angeles')
@@ -182,7 +182,7 @@ void main() {
182 182
     test('compose throws assert error if change is empty', () {
183 183
       NotusDocument doc = dartconfDoc();
184 184
       expect(() {
185
-        doc.compose(new Delta()..retain(1), ChangeSource.local);
185
+        doc.compose(Delta()..retain(1), ChangeSource.local);
186 186
       }, throwsA(const TypeMatcher<AssertionError>()));
187 187
     });
188 188
 
@@ -219,7 +219,7 @@ void main() {
219 219
       doc.close();
220 220
       expect(doc.isClosed, isTrue);
221 221
       expect(() {
222
-        doc.compose(new Delta()..insert('a'), ChangeSource.local);
222
+        doc.compose(Delta()..insert('a'), ChangeSource.local);
223 223
       }, throwsAssertionError);
224 224
       expect(() {
225 225
         doc.insert(0, 'a');
@@ -247,7 +247,7 @@ void main() {
247 247
       LineNode line = doc.root.children.elementAt(1);
248 248
       EmbedNode embed = line.first;
249 249
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
250
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
250
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
251 251
       expect(embed.style, style);
252 252
     });
253 253
 
@@ -260,7 +260,7 @@ void main() {
260 260
       LineNode line = doc.root.children.elementAt(1);
261 261
       EmbedNode embed = line.first;
262 262
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
263
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
263
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
264 264
       expect(embed.style, style);
265 265
     });
266 266
 
@@ -276,7 +276,7 @@ void main() {
276 276
       LineNode line = doc.root.children.elementAt(1);
277 277
       EmbedNode embed = line.first;
278 278
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
279
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
279
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
280 280
       expect(embed.style, style);
281 281
     });
282 282
 

+ 18
- 18
packages/notus/test/heuristics/delete_rules_test.dart View File

@@ -10,15 +10,15 @@ final bold = NotusAttribute.bold.toJson();
10 10
 
11 11
 void main() {
12 12
   group('$PreserveLineStyleOnMergeRule', () {
13
-    final rule = new PreserveLineStyleOnMergeRule();
13
+    final rule = PreserveLineStyleOnMergeRule();
14 14
     test('preserves block style', () {
15 15
       final ul = NotusAttribute.ul.toJson();
16
-      final doc = new Delta()
16
+      final doc = Delta()
17 17
         ..insert('Title\nOne')
18 18
         ..insert('\n', ul)
19 19
         ..insert('Two\n');
20 20
       final actual = rule.apply(doc, 9, 1);
21
-      final expected = new Delta()
21
+      final expected = Delta()
22 22
         ..retain(9)
23 23
         ..delete(1)
24 24
         ..retain(3)
@@ -28,12 +28,12 @@ void main() {
28 28
 
29 29
     test('resets block style', () {
30 30
       final unsetUl = NotusAttribute.block.unset.toJson();
31
-      final doc = new Delta()
31
+      final doc = Delta()
32 32
         ..insert('Title\nOne')
33 33
         ..insert('\n', NotusAttribute.ul.toJson())
34 34
         ..insert('Two\n');
35 35
       final actual = rule.apply(doc, 5, 1);
36
-      final expected = new Delta()
36
+      final expected = Delta()
37 37
         ..retain(5)
38 38
         ..delete(1)
39 39
         ..retain(3)
@@ -43,12 +43,12 @@ void main() {
43 43
   });
44 44
 
45 45
   group('$CatchAllDeleteRule', () {
46
-    final rule = new CatchAllDeleteRule();
46
+    final rule = CatchAllDeleteRule();
47 47
 
48 48
     test('applies change as-is', () {
49
-      final doc = new Delta()..insert('Document\n');
49
+      final doc = Delta()..insert('Document\n');
50 50
       final actual = rule.apply(doc, 3, 5);
51
-      final expected = new Delta()
51
+      final expected = Delta()
52 52
         ..retain(3)
53 53
         ..delete(5);
54 54
       expect(actual, expected);
@@ -56,40 +56,40 @@ void main() {
56 56
   });
57 57
 
58 58
   group('$EnsureEmbedLineRule', () {
59
-    final rule = new EnsureEmbedLineRule();
59
+    final rule = EnsureEmbedLineRule();
60 60
 
61 61
     test('ensures line-break before embed', () {
62 62
       final hr = NotusAttribute.embed.horizontalRule;
63
-      final doc = new Delta()
63
+      final doc = Delta()
64 64
         ..insert('Document\n')
65 65
         ..insert(kZeroWidthSpace, hr.toJson())
66 66
         ..insert('\n');
67 67
       final actual = rule.apply(doc, 8, 1);
68
-      final expected = new Delta()..retain(8);
68
+      final expected = Delta()..retain(8);
69 69
       expect(actual, expected);
70 70
     });
71 71
 
72 72
     test('ensures line-break after embed', () {
73 73
       final hr = NotusAttribute.embed.horizontalRule;
74
-      final doc = new Delta()
74
+      final doc = Delta()
75 75
         ..insert('Document\n')
76 76
         ..insert(kZeroWidthSpace, hr.toJson())
77 77
         ..insert('\n');
78 78
       final actual = rule.apply(doc, 10, 1);
79
-      final expected = new Delta()..retain(11);
79
+      final expected = Delta()..retain(11);
80 80
       expect(actual, expected);
81 81
     });
82 82
 
83 83
     test('still deletes everything between embeds', () {
84 84
       final hr = NotusAttribute.embed.horizontalRule;
85
-      final doc = new Delta()
85
+      final doc = Delta()
86 86
         ..insert('Document\n')
87 87
         ..insert(kZeroWidthSpace, hr.toJson())
88 88
         ..insert('\nSome text\n')
89 89
         ..insert(kZeroWidthSpace, hr.toJson())
90 90
         ..insert('\n');
91 91
       final actual = rule.apply(doc, 10, 11);
92
-      final expected = new Delta()
92
+      final expected = Delta()
93 93
         ..retain(11)
94 94
         ..delete(9);
95 95
       expect(actual, expected);
@@ -97,7 +97,7 @@ void main() {
97 97
 
98 98
     test('allows deleting empty line after embed', () {
99 99
       final hr = NotusAttribute.embed.horizontalRule;
100
-      final doc = new Delta()
100
+      final doc = Delta()
101 101
         ..insert('Document\n')
102 102
         ..insert(kZeroWidthSpace, hr.toJson())
103 103
         ..insert('\n')
@@ -105,7 +105,7 @@ void main() {
105 105
         ..insert('Text')
106 106
         ..insert('\n');
107 107
       final actual = rule.apply(doc, 10, 1);
108
-      final expected = new Delta()
108
+      final expected = Delta()
109 109
         ..retain(11)
110 110
         ..delete(1);
111 111
       expect(actual, expected);
@@ -113,7 +113,7 @@ void main() {
113 113
 
114 114
     test('allows deleting empty line(s) before embed', () {
115 115
       final hr = NotusAttribute.embed.horizontalRule;
116
-      final doc = new Delta()
116
+      final doc = Delta()
117 117
         ..insert('Document\n')
118 118
         ..insert('\n')
119 119
         ..insert('\n')

+ 13
- 13
packages/notus/test/heuristics/format_rules_test.dart View File

@@ -10,15 +10,15 @@ final bold = NotusAttribute.bold.toJson();
10 10
 
11 11
 void main() {
12 12
   group('$ResolveLineFormatRule', () {
13
-    final rule = new ResolveLineFormatRule();
13
+    final rule = ResolveLineFormatRule();
14 14
 
15 15
     test('apply', () {
16
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
16
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
17 17
 
18 18
       final actual = rule.apply(doc, 0, 20, NotusAttribute.ul);
19 19
       expect(actual, isNotNull);
20 20
       final ul = NotusAttribute.ul.toJson();
21
-      final expected = new Delta()
21
+      final expected = Delta()
22 22
         ..retain(7)
23 23
         ..retain(1, ul)
24 24
         ..retain(4)
@@ -31,38 +31,38 @@ void main() {
31 31
     });
32 32
 
33 33
     test('apply with zero length (collapsed selection)', () {
34
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
34
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
35 35
       final actual = rule.apply(doc, 0, 0, NotusAttribute.ul);
36 36
       expect(actual, isNotNull);
37 37
       final ul = NotusAttribute.ul.toJson();
38
-      final expected = new Delta()..retain(7)..retain(1, ul);
38
+      final expected = Delta()..retain(7)..retain(1, ul);
39 39
       expect(actual, expected);
40 40
     });
41 41
 
42 42
     test('apply with zero length in the middle of a line', () {
43 43
       final ul = NotusAttribute.ul.toJson();
44
-      final doc = new Delta()
44
+      final doc = Delta()
45 45
         ..insert('Title\nOne')
46 46
         ..insert('\n', ul)
47 47
         ..insert('Two')
48 48
         ..insert('\n', ul)
49 49
         ..insert('Three!\n');
50 50
       final actual = rule.apply(doc, 7, 0, NotusAttribute.ul);
51
-      final expected = new Delta()..retain(9)..retain(1, ul);
51
+      final expected = Delta()..retain(9)..retain(1, ul);
52 52
       expect(actual, expected);
53 53
     });
54 54
   });
55 55
 
56 56
   group('$ResolveInlineFormatRule', () {
57
-    final rule = new ResolveInlineFormatRule();
57
+    final rule = ResolveInlineFormatRule();
58 58
 
59 59
     test('apply', () {
60
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
60
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
61 61
 
62 62
       final actual = rule.apply(doc, 0, 20, NotusAttribute.bold);
63 63
       expect(actual, isNotNull);
64 64
       final b = NotusAttribute.bold.toJson();
65
-      final expected = new Delta()
65
+      final expected = Delta()
66 66
         ..retain(7, b)
67 67
         ..retain(1)
68 68
         ..retain(4, b)
@@ -75,21 +75,21 @@ void main() {
75 75
   });
76 76
 
77 77
   group('$FormatLinkAtCaretPositionRule', () {
78
-    final rule = new FormatLinkAtCaretPositionRule();
78
+    final rule = FormatLinkAtCaretPositionRule();
79 79
 
80 80
     test('apply', () {
81 81
       final link =
82 82
           NotusAttribute.link.fromString('https://github.com/memspace/bold');
83 83
       final newLink =
84 84
           NotusAttribute.link.fromString('https://github.com/memspace/zefyr');
85
-      final doc = new Delta()
85
+      final doc = Delta()
86 86
         ..insert('Visit our ')
87 87
         ..insert('website', link.toJson())
88 88
         ..insert(' for more details.\n');
89 89
 
90 90
       final actual = rule.apply(doc, 13, 0, newLink);
91 91
       expect(actual, isNotNull);
92
-      final expected = new Delta()..retain(10)..retain(7, newLink.toJson());
92
+      final expected = Delta()..retain(10)..retain(7, newLink.toJson());
93 93
       expect(actual, expected);
94 94
     });
95 95
   });

+ 38
- 39
packages/notus/test/heuristics/insert_rules_test.dart View File

@@ -10,12 +10,12 @@ final bold = NotusAttribute.bold.toJson();
10 10
 
11 11
 void main() {
12 12
   group('$CatchAllInsertRule', () {
13
-    final rule = new CatchAllInsertRule();
13
+    final rule = CatchAllInsertRule();
14 14
 
15 15
     test('applies change as-is', () {
16
-      final doc = new Delta()..insert('Document\n');
16
+      final doc = Delta()..insert('Document\n');
17 17
       final actual = rule.apply(doc, 8, '!');
18
-      final expected = new Delta()
18
+      final expected = Delta()
19 19
         ..retain(8)
20 20
         ..insert('!');
21 21
       expect(actual, expected);
@@ -23,22 +23,22 @@ void main() {
23 23
   });
24 24
 
25 25
   group('$PreserveLineStyleOnSplitRule', () {
26
-    final rule = new PreserveLineStyleOnSplitRule();
26
+    final rule = PreserveLineStyleOnSplitRule();
27 27
 
28 28
     test('skips at the beginning of a document', () {
29
-      final doc = new Delta()..insert('One\n');
29
+      final doc = Delta()..insert('One\n');
30 30
       final actual = rule.apply(doc, 0, '\n');
31 31
       expect(actual, isNull);
32 32
     });
33 33
 
34 34
     test('applies in a block', () {
35
-      final doc = new Delta()
35
+      final doc = Delta()
36 36
         ..insert('One and two')
37 37
         ..insert('\n', ul)
38 38
         ..insert('Three')
39 39
         ..insert('\n', ul);
40 40
       final actual = rule.apply(doc, 8, '\n');
41
-      final expected = new Delta()
41
+      final expected = Delta()
42 42
         ..retain(8)
43 43
         ..insert('\n', ul);
44 44
       expect(actual, isNotNull);
@@ -50,12 +50,12 @@ void main() {
50 50
     final rule = const ResetLineFormatOnNewLineRule();
51 51
 
52 52
     test('applies when line-break is inserted at the end of line', () {
53
-      final doc = new Delta()
53
+      final doc = Delta()
54 54
         ..insert('Hello world')
55 55
         ..insert('\n', NotusAttribute.h1.toJson());
56 56
       final actual = rule.apply(doc, 11, '\n');
57 57
       expect(actual, isNotNull);
58
-      final expected = new Delta()
58
+      final expected = Delta()
59 59
         ..retain(11)
60 60
         ..insert('\n', NotusAttribute.h1.toJson())
61 61
         ..retain(1, NotusAttribute.heading.unset.toJson());
@@ -63,20 +63,20 @@ void main() {
63 63
     });
64 64
 
65 65
     test('applies without style reset if not needed', () {
66
-      final doc = new Delta()..insert('Hello world\n');
66
+      final doc = Delta()..insert('Hello world\n');
67 67
       final actual = rule.apply(doc, 11, '\n');
68 68
       expect(actual, isNotNull);
69
-      final expected = new Delta()
69
+      final expected = Delta()
70 70
         ..retain(11)
71 71
         ..insert('\n');
72 72
       expect(actual, expected);
73 73
     });
74 74
 
75 75
     test('applies at the beginning of a document', () {
76
-      final doc = new Delta()..insert('\n', NotusAttribute.h1.toJson());
76
+      final doc = Delta()..insert('\n', NotusAttribute.h1.toJson());
77 77
       final actual = rule.apply(doc, 0, '\n');
78 78
       expect(actual, isNotNull);
79
-      final expected = new Delta()
79
+      final expected = Delta()
80 80
         ..insert('\n', NotusAttribute.h1.toJson())
81 81
         ..retain(1, NotusAttribute.heading.unset.toJson());
82 82
       expect(actual, expected);
@@ -85,10 +85,10 @@ void main() {
85 85
     test('applies and keeps block style', () {
86 86
       final style = NotusAttribute.ul.toJson();
87 87
       style.addAll(NotusAttribute.h1.toJson());
88
-      final doc = new Delta()..insert('Hello world')..insert('\n', style);
88
+      final doc = Delta()..insert('Hello world')..insert('\n', style);
89 89
       final actual = rule.apply(doc, 11, '\n');
90 90
       expect(actual, isNotNull);
91
-      final expected = new Delta()
91
+      final expected = Delta()
92 92
         ..retain(11)
93 93
         ..insert('\n', style)
94 94
         ..retain(1, NotusAttribute.heading.unset.toJson());
@@ -96,12 +96,12 @@ void main() {
96 96
     });
97 97
 
98 98
     test('applies to a line in the middle of a document', () {
99
-      final doc = new Delta()
99
+      final doc = Delta()
100 100
         ..insert('Hello \nworld!\nMore lines here.')
101 101
         ..insert('\n', NotusAttribute.h2.toJson());
102 102
       final actual = rule.apply(doc, 30, '\n');
103 103
       expect(actual, isNotNull);
104
-      final expected = new Delta()
104
+      final expected = Delta()
105 105
         ..retain(30)
106 106
         ..insert('\n', NotusAttribute.h2.toJson())
107 107
         ..retain(1, NotusAttribute.heading.unset.toJson());
@@ -110,18 +110,18 @@ void main() {
110 110
   });
111 111
 
112 112
   group('$AutoExitBlockRule', () {
113
-    final rule = new AutoExitBlockRule();
113
+    final rule = AutoExitBlockRule();
114 114
 
115 115
     test('applies when line-break is inserted on empty line in a block', () {
116 116
       final ul = NotusAttribute.ul.toJson();
117
-      final doc = new Delta()
117
+      final doc = Delta()
118 118
         ..insert('Item 1')
119 119
         ..insert('\n', ul)
120 120
         ..insert('Item 2')
121 121
         ..insert('\n\n', ul);
122 122
       final actual = rule.apply(doc, 14, '\n');
123 123
       expect(actual, isNotNull);
124
-      final expected = new Delta()
124
+      final expected = Delta()
125 125
         ..retain(14)
126 126
         ..retain(1, NotusAttribute.block.unset.toJson());
127 127
       expect(actual, expected);
@@ -129,58 +129,57 @@ void main() {
129 129
 
130 130
     test('applies only on empty line', () {
131 131
       final ul = NotusAttribute.ul.toJson();
132
-      final doc = new Delta()..insert('Item 1')..insert('\n', ul);
132
+      final doc = Delta()..insert('Item 1')..insert('\n', ul);
133 133
       final actual = rule.apply(doc, 6, '\n');
134 134
       expect(actual, isNull);
135 135
     });
136 136
 
137 137
     test('applies at the beginning of a document', () {
138 138
       final ul = NotusAttribute.ul.toJson();
139
-      final doc = new Delta()..insert('\n', ul);
139
+      final doc = Delta()..insert('\n', ul);
140 140
       final actual = rule.apply(doc, 0, '\n');
141 141
       expect(actual, isNotNull);
142
-      final expected = new Delta()
143
-        ..retain(1, NotusAttribute.block.unset.toJson());
142
+      final expected = Delta()..retain(1, NotusAttribute.block.unset.toJson());
144 143
       expect(actual, expected);
145 144
     });
146 145
 
147 146
     test('ignores non-empty line at the beginning of a document', () {
148 147
       final ul = NotusAttribute.ul.toJson();
149
-      final doc = new Delta()..insert('Text\n', ul);
148
+      final doc = Delta()..insert('Text\n', ul);
150 149
       final actual = rule.apply(doc, 0, '\n');
151 150
       expect(actual, isNull);
152 151
     });
153 152
   });
154 153
 
155 154
   group('$PreserveInlineStylesRule', () {
156
-    final rule = new PreserveInlineStylesRule();
155
+    final rule = PreserveInlineStylesRule();
157 156
     test('apply', () {
158
-      final doc = new Delta()
157
+      final doc = Delta()
159 158
         ..insert('Doc with ')
160 159
         ..insert('bold', bold)
161 160
         ..insert(' text');
162 161
       final actual = rule.apply(doc, 13, 'er');
163
-      final expected = new Delta()
162
+      final expected = Delta()
164 163
         ..retain(13)
165 164
         ..insert('er', bold);
166 165
       expect(expected, actual);
167 166
     });
168 167
 
169 168
     test('apply at the beginning of a document', () {
170
-      final doc = new Delta()..insert('Doc with ');
169
+      final doc = Delta()..insert('Doc with ');
171 170
       final actual = rule.apply(doc, 0, 'A ');
172 171
       expect(actual, isNull);
173 172
     });
174 173
   });
175 174
 
176 175
   group('$AutoFormatLinksRule', () {
177
-    final rule = new AutoFormatLinksRule();
176
+    final rule = AutoFormatLinksRule();
178 177
     final link = NotusAttribute.link.fromString('https://example.com').toJson();
179 178
 
180 179
     test('apply simple', () {
181
-      final doc = new Delta()..insert('Doc with link https://example.com');
180
+      final doc = Delta()..insert('Doc with link https://example.com');
182 181
       final actual = rule.apply(doc, 33, ' ');
183
-      final expected = new Delta()
182
+      final expected = Delta()
184 183
         ..retain(14)
185 184
         ..retain(19, link)
186 185
         ..insert(' ');
@@ -188,15 +187,15 @@ void main() {
188 187
     });
189 188
 
190 189
     test('applies only to insert of single space', () {
191
-      final doc = new Delta()..insert('Doc with link https://example.com');
190
+      final doc = Delta()..insert('Doc with link https://example.com');
192 191
       final actual = rule.apply(doc, 33, '/');
193 192
       expect(actual, isNull);
194 193
     });
195 194
 
196 195
     test('applies for links at the beginning of line', () {
197
-      final doc = new Delta()..insert('Doc with link\nhttps://example.com');
196
+      final doc = Delta()..insert('Doc with link\nhttps://example.com');
198 197
       final actual = rule.apply(doc, 33, ' ');
199
-      final expected = new Delta()
198
+      final expected = Delta()
200 199
         ..retain(14)
201 200
         ..retain(19, link)
202 201
         ..insert(' ');
@@ -204,7 +203,7 @@ void main() {
204 203
     });
205 204
 
206 205
     test('ignores if already formatted as link', () {
207
-      final doc = new Delta()
206
+      final doc = Delta()
208 207
         ..insert('Doc with link\n')
209 208
         ..insert('https://example.com', link);
210 209
       final actual = rule.apply(doc, 33, ' ');
@@ -213,16 +212,16 @@ void main() {
213 212
   });
214 213
 
215 214
   group('$PreserveBlockStyleOnPasteRule', () {
216
-    final rule = new PreserveBlockStyleOnPasteRule();
215
+    final rule = PreserveBlockStyleOnPasteRule();
217 216
 
218 217
     test('applies in a block', () {
219
-      final doc = new Delta()
218
+      final doc = Delta()
220 219
         ..insert('One and two')
221 220
         ..insert('\n', ul)
222 221
         ..insert('Three')
223 222
         ..insert('\n', ul);
224 223
       final actual = rule.apply(doc, 8, 'also \n');
225
-      final expected = new Delta()
224
+      final expected = Delta()
226 225
         ..retain(8)
227 226
         ..insert('also ')
228 227
         ..insert('\n', ul);

+ 3
- 3
packages/notus/test/heuristics_test.dart View File

@@ -7,8 +7,8 @@ import 'package:quill_delta/quill_delta.dart';
7 7
 import 'package:test/test.dart';
8 8
 
9 9
 NotusDocument dartconfDoc() {
10
-  Delta delta = new Delta()..insert('DartConf\nLos Angeles\n');
11
-  return new NotusDocument.fromDelta(delta);
10
+  Delta delta = Delta()..insert('DartConf\nLos Angeles\n');
11
+  return NotusDocument.fromDelta(delta);
12 12
 }
13 13
 
14 14
 final ul = NotusAttribute.ul.toJson();
@@ -18,7 +18,7 @@ void main() {
18 18
   group('$NotusHeuristics', () {
19 19
     test('ensures heuristics are applied', () {
20 20
       final doc = dartconfDoc();
21
-      final heuristics = new NotusHeuristics(
21
+      final heuristics = NotusHeuristics(
22 22
         formatRules: [],
23 23
         insertRules: [],
24 24
         deleteRules: [],

+ 3
- 4
packages/notus/test/matchers.dart View File

@@ -4,8 +4,7 @@
4 4
 
5 5
 import 'package:test/test.dart';
6 6
 
7
-const isAssertionError = const TypeMatcher<AssertionError>();
7
+const isAssertionError = TypeMatcher<AssertionError>();
8 8
 
9
-const Matcher throwsAssertionError =
10
-    // ignore: deprecated_member_use
11
-    const Throws(isAssertionError);
9
+// ignore: deprecated_member_use
10
+const Matcher throwsAssertionError = Throws(isAssertionError);