Skip to content

Commit

Permalink
chore: add linters conforming to style guide (#59)
Browse files Browse the repository at this point in the history
Relates: #56 #57
  • Loading branch information
Xazin authored Apr 12, 2023
1 parent fd13ad4 commit cf5e83d
Show file tree
Hide file tree
Showing 60 changed files with 1,875 additions and 1,198 deletions.
10 changes: 10 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
linter:
rules:
- always_declare_return_types
- require_trailing_commas
- unnecessary_raw_strings
- use_decorated_box

analyzer:
exclude:
- lib/src/l10n/**
3 changes: 2 additions & 1 deletion lib/src/commands/text/text_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ extension TextCommands on EditorState {
if (BuiltInAttributeKey.globalStyleKeys.contains(key)) {
final attr = n.attributes
..removeWhere(
(key, _) => BuiltInAttributeKey.globalStyleKeys.contains(key))
(key, _) => BuiltInAttributeKey.globalStyleKeys.contains(key),
)
..addAll(attributes)
..addAll({
BuiltInAttributeKey.subtype: key,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/core/document/text_delta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ class Delta extends Iterable<TextOperation> {
@override
int get length {
return _operations.fold(
0, (previousValue, element) => previousValue + element.length);
0,
(previousValue, element) => previousValue + element.length,
);
}

/// Returns a Delta that is equivalent to applying the operations of own Delta, followed by another Delta.
Expand Down
32 changes: 19 additions & 13 deletions lib/src/core/transform/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ class Transaction {
/// The [attributes] will be merged into the existing attributes.
void updateNode(Node node, Attributes attributes) {
final inverted = invertAttributes(node.attributes, attributes);
add(UpdateOperation(
node.path,
{...attributes},
inverted,
));
add(
UpdateOperation(
node.path,
{...attributes},
inverted,
),
);
}

/// Deletes the [Node] in the document.
Expand Down Expand Up @@ -170,10 +172,12 @@ extension TextTransaction on Transaction {
..delete(firstLength - firstOffset)
..addAll(second.delta.slice(secondOffset, secondLength)),
);
afterSelection = Selection.collapsed(Position(
path: first.path,
offset: firstOffset,
));
afterSelection = Selection.collapsed(
Position(
path: first.path,
offset: firstOffset,
),
);
}

void splitText(TextNode textNode, int offset) {
Expand All @@ -188,10 +192,12 @@ extension TextTransaction on Transaction {
delta: second,
),
);
afterSelection = Selection.collapsed(Position(
path: path,
offset: 0,
));
afterSelection = Selection.collapsed(
Position(
path: path,
offset: 0,
),
);
}

/// Inserts the text content at a specified index.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/extensions/attributes_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ extension DeltaAttributesExtensions on Attributes {
if (containsKey(BuiltInAttributeKey.backgroundColor) &&
this[BuiltInAttributeKey.backgroundColor] is String) {
return Color(
int.tryParse(this[BuiltInAttributeKey.backgroundColor]) ?? whiteInt);
int.tryParse(this[BuiltInAttributeKey.backgroundColor]) ?? whiteInt,
);
}
return null;
}
Expand Down
116 changes: 77 additions & 39 deletions lib/src/flutter/overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,20 @@ class Overlay extends StatefulWidget {
final List<DiagnosticsNode> information = <DiagnosticsNode>[
ErrorSummary('No Overlay widget found.'),
ErrorDescription(
'${debugRequiredFor.runtimeType} widgets require an Overlay widget ancestor for correct operation.'),
'${debugRequiredFor.runtimeType} widgets require an Overlay widget ancestor for correct operation.',
),
ErrorHint(
'The most common way to add an Overlay to an application is to include a MaterialApp or Navigator widget in the runApp() call.'),
'The most common way to add an Overlay to an application is to include a MaterialApp or Navigator widget in the runApp() call.',
),
DiagnosticsProperty<Widget>(
'The specific widget that failed to find an overlay was',
debugRequiredFor,
style: DiagnosticsTreeStyle.errorProperty),
'The specific widget that failed to find an overlay was',
debugRequiredFor,
style: DiagnosticsTreeStyle.errorProperty,
),
if (context.widget != debugRequiredFor)
context.describeElement(
'The context from which that widget was searching for an overlay was'),
'The context from which that widget was searching for an overlay was',
),
];

throw FlutterError.fromParts(information);
Expand Down Expand Up @@ -352,10 +356,14 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
/// It is an error to specify both `above` and `below`.
void insert(OverlayEntry entry, {OverlayEntry? below, OverlayEntry? above}) {
assert(_debugVerifyInsertPosition(above, below));
assert(!_entries.contains(entry),
'The specified entry is already present in the Overlay.');
assert(entry._overlay == null,
'The specified entry is already present in another Overlay.');
assert(
!_entries.contains(entry),
'The specified entry is already present in the Overlay.',
);
assert(
entry._overlay == null,
'The specified entry is already present in another Overlay.',
);
entry._overlay = this;
setState(() {
_entries.insert(_insertionIndex(below, above), entry);
Expand All @@ -369,8 +377,11 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
/// Otherwise, the entries are inserted on top.
///
/// It is an error to specify both `above` and `below`.
void insertAll(Iterable<OverlayEntry> entries,
{OverlayEntry? below, OverlayEntry? above}) {
void insertAll(
Iterable<OverlayEntry> entries, {
OverlayEntry? below,
OverlayEntry? above,
}) {
assert(_debugVerifyInsertPosition(above, below));
assert(
entries.every((OverlayEntry entry) => !_entries.contains(entry)),
Expand All @@ -390,8 +401,11 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
});
}

bool _debugVerifyInsertPosition(OverlayEntry? above, OverlayEntry? below,
{Iterable<OverlayEntry>? newEntries}) {
bool _debugVerifyInsertPosition(
OverlayEntry? above,
OverlayEntry? below, {
Iterable<OverlayEntry>? newEntries,
}) {
assert(
above == null || below == null,
'Only one of `above` and `below` may be specified.',
Expand Down Expand Up @@ -430,21 +444,29 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
/// below.
///
/// It is an error to specify both `above` and `below`.
void rearrange(Iterable<OverlayEntry> newEntries,
{OverlayEntry? below, OverlayEntry? above}) {
void rearrange(
Iterable<OverlayEntry> newEntries, {
OverlayEntry? below,
OverlayEntry? above,
}) {
final List<OverlayEntry> newEntriesList = newEntries is List<OverlayEntry>
? newEntries
: newEntries.toList(growable: false);
assert(
_debugVerifyInsertPosition(above, below, newEntries: newEntriesList));
_debugVerifyInsertPosition(above, below, newEntries: newEntriesList),
);
assert(
newEntriesList.every((OverlayEntry entry) =>
entry._overlay == null || entry._overlay == this),
newEntriesList.every(
(OverlayEntry entry) =>
entry._overlay == null || entry._overlay == this,
),
'One or more of the specified entries are already present in another Overlay.',
);
assert(
newEntriesList.every((OverlayEntry entry) =>
_entries.indexOf(entry) == _entries.lastIndexOf(entry)),
newEntriesList.every(
(OverlayEntry entry) =>
_entries.indexOf(entry) == _entries.lastIndexOf(entry),
),
'One or more of the specified entries are specified multiple times.',
);
if (newEntriesList.isEmpty) return;
Expand Down Expand Up @@ -509,17 +531,21 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
final OverlayEntry entry = _entries[i];
if (onstage) {
onstageCount += 1;
children.add(_OverlayEntryWidget(
key: entry._key,
entry: entry,
));
children.add(
_OverlayEntryWidget(
key: entry._key,
entry: entry,
),
);
if (entry.opaque) onstage = false;
} else if (entry.maintainState) {
children.add(_OverlayEntryWidget(
key: entry._key,
entry: entry,
tickerEnabled: false,
));
children.add(
_OverlayEntryWidget(
key: entry._key,
entry: entry,
tickerEnabled: false,
),
);
}
}
return _Theatre(
Expand Down Expand Up @@ -684,26 +710,34 @@ class _RenderTheatre extends RenderBox

@override
double computeMinIntrinsicWidth(double height) {
return RenderStack.getIntrinsicDimension(_firstOnstageChild,
(RenderBox child) => child.getMinIntrinsicWidth(height));
return RenderStack.getIntrinsicDimension(
_firstOnstageChild,
(RenderBox child) => child.getMinIntrinsicWidth(height),
);
}

@override
double computeMaxIntrinsicWidth(double height) {
return RenderStack.getIntrinsicDimension(_firstOnstageChild,
(RenderBox child) => child.getMaxIntrinsicWidth(height));
return RenderStack.getIntrinsicDimension(
_firstOnstageChild,
(RenderBox child) => child.getMaxIntrinsicWidth(height),
);
}

@override
double computeMinIntrinsicHeight(double width) {
return RenderStack.getIntrinsicDimension(_firstOnstageChild,
(RenderBox child) => child.getMinIntrinsicHeight(width));
return RenderStack.getIntrinsicDimension(
_firstOnstageChild,
(RenderBox child) => child.getMinIntrinsicHeight(width),
);
}

@override
double computeMaxIntrinsicHeight(double width) {
return RenderStack.getIntrinsicDimension(_firstOnstageChild,
(RenderBox child) => child.getMaxIntrinsicHeight(width));
return RenderStack.getIntrinsicDimension(
_firstOnstageChild,
(RenderBox child) => child.getMaxIntrinsicHeight(width),
);
}

@override
Expand Down Expand Up @@ -764,7 +798,11 @@ class _RenderTheatre extends RenderBox
_resolvedAlignment!.alongOffset(size - child.size as Offset);
} else {
_hasVisualOverflow = RenderStack.layoutPositionedChild(
child, childParentData, size, _resolvedAlignment!) ||
child,
childParentData,
size,
_resolvedAlignment!,
) ||
_hasVisualOverflow;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/src/history/undo_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class HistoryItem extends LinkedListEntry<HistoryItem> {
/// to the item.
///
/// The caller should create a new [HistoryItem].
seal() {
void seal() {
_sealed = true;
}

bool get sealed => _sealed;

add(Operation op) {
void add(Operation op) {
operations.add(op);
}

addAll(Iterable<Operation> iterable) {
void addAll(Iterable<Operation> iterable) {
operations.addAll(iterable);
}

Expand All @@ -56,7 +56,7 @@ class FixedSizeStack {

FixedSizeStack(this.maxSize);

push(HistoryItem stackItem) {
void push(HistoryItem stackItem) {
if (_list.length >= maxSize) {
_list.remove(_list.first);
}
Expand All @@ -74,7 +74,7 @@ class FixedSizeStack {
return last;
}

clear() {
void clear() {
_list.clear();
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class UndoManager {
return last;
}

undo() {
void undo() {
Log.editor.debug('undo');
final s = state;
if (s == null) {
Expand All @@ -130,7 +130,7 @@ class UndoManager {
);
}

redo() {
void redo() {
Log.editor.debug('redo');
final s = state;
if (s == null) {
Expand Down
Loading

0 comments on commit cf5e83d

Please sign in to comment.