Skip to content

Commit

Permalink
style: enforce always_put_control_body_on_new_line and curly_braces_i…
Browse files Browse the repository at this point in the history
…n_flow_control_structures (#21)
  • Loading branch information
maelchiotti authored Apr 9, 2024
1 parent 17f04c7 commit deadbd6
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 31 deletions.
7 changes: 6 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ analyzer:
exclude:
- '**.g.dart'
plugins:
- custom_lint
- custom_lint

linter:
rules:
- always_put_control_body_on_new_line
- curly_braces_in_flow_control_structures
4 changes: 3 additions & 1 deletion lib/common/actions/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Future<void> addNote(BuildContext context, WidgetRef ref, {String? content}) asy

ref.read(currentNoteProvider.notifier).set(note);

if (!context.mounted) return;
if (!context.mounted) {
return;
}

final editorRoute = RouterRoute.editor.fullPath!;
final editorParameters = EditorParameters.from({'readonly': false, 'autofocus': true});
Expand Down
8 changes: 6 additions & 2 deletions lib/common/actions/delete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import 'package:localmaterialnotes/providers/selection_mode/selection_mode_provi
import 'package:localmaterialnotes/utils/constants/constants.dart';

Future<bool> deleteNote(BuildContext context, WidgetRef ref, Note? note) async {
if (note == null) return false;
if (note == null) {
return false;
}

if (await showConfirmationDialog(
context,
Expand Down Expand Up @@ -47,7 +49,9 @@ Future<void> deleteNotes(BuildContext context, WidgetRef ref, List<Note> notes)
}

Future<bool> permanentlyDeleteNote(BuildContext context, WidgetRef ref, Note? note) async {
if (note == null) return false;
if (note == null) {
return false;
}

if (await showConfirmationDialog(
context,
Expand Down
4 changes: 3 additions & 1 deletion lib/common/actions/pin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:localmaterialnotes/models/note/note.dart';
import 'package:localmaterialnotes/providers/notes/notes_provider.dart';

Future<bool> togglePinNote(BuildContext context, WidgetRef ref, Note? note) async {
if (note == null) return false;
if (note == null) {
return false;
}

await ref.read(notesProvider.notifier).togglePin(note);

Expand Down
4 changes: 3 additions & 1 deletion lib/common/actions/restore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import 'package:localmaterialnotes/providers/current_note/current_note_provider.
import 'package:localmaterialnotes/utils/constants/constants.dart';

Future<bool> restoreNote(BuildContext context, WidgetRef ref, Note? note) async {
if (note == null) return false;
if (note == null) {
return false;
}

if (await showConfirmationDialog(
context,
Expand Down
8 changes: 6 additions & 2 deletions lib/common/navigation/app_bars/back_menu_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class _BackAppBarState extends ConsumerState<BackMenuAppBar> {
Future<void> _onMenuOptionSelected(MenuOption menuOption) async {
final note = ref.read(currentNoteProvider);

if (note == null) return;
if (note == null) {
return;
}

switch (menuOption) {
case MenuOption.togglePin:
Expand Down Expand Up @@ -53,7 +55,9 @@ class _BackAppBarState extends ConsumerState<BackMenuAppBar> {
void _toggleChecklist() {
final editorController = ref.read(editorControllerProvider);

if (editorController == null) return;
if (editorController == null) {
return;
}

final isToggled = editorController.getSelectionStyle().containsSame(ParchmentAttribute.block.checkList);
editorController.formatSelection(
Expand Down
8 changes: 6 additions & 2 deletions lib/common/navigation/app_bars/search_sort_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class _SearchAppBarState extends ConsumerState<SearchSortAppBar> {
bool sortAscending = SortMethod.ascendingFromPreferences;

List<NoteTile> _filterNotes(String? search, List<Note> notes) {
if (search == null || search.isEmpty) return [];
if (search == null || search.isEmpty) {
return [];
}

return notes.where((note) {
return note.containsText(search);
Expand Down Expand Up @@ -117,7 +119,9 @@ class _SearchAppBarState extends ConsumerState<SearchSortAppBar> {
),
ref.watch(provider).when(
data: (notes) {
if (notes.isEmpty) return searchButtonPlaceholder;
if (notes.isEmpty) {
return searchButtonPlaceholder;
}

return SearchAnchor(
viewHintText: localizations.tooltip_search,
Expand Down
4 changes: 3 additions & 1 deletion lib/common/placeholders/empty_placeholder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class EmptyPlaceholder extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (icon == null || text == null) return Container();
if (icon == null || text == null) {
return Container();
}

return Center(
child: Padding(
Expand Down
4 changes: 3 additions & 1 deletion lib/common/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ PreferredSizeWidget? _getAppBar(BuildContext context) {
}

Widget? _getDrawer() {
if (RouterRoute.currentRoute.drawerIndex == null) return null;
if (RouterRoute.currentRoute.drawerIndex == null) {
return null;
}

return const SideNavigation();
}
Expand Down
8 changes: 6 additions & 2 deletions lib/common/routing/router_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ enum RouterRoute {
static int get currentDrawerIndex {
final drawerIndex = currentRoute.drawerIndex;

if (drawerIndex == null) throw Exception('No current drawer index');
if (drawerIndex == null) {
throw Exception('No current drawer index');
}

return drawerIndex;
}

static RouterRoute getRouteFromIndex(int index) {
final route = values.firstWhereOrNull((route) => route.drawerIndex == index);

if (route == null) throw Exception('No route for index: $index');
if (route == null) {
throw Exception('No route for index: $index');
}

return route;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/common/widgets/note_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class _NoteTileState extends ConsumerState<NoteTile> {
extra: EditorParameters.from({'readonly': widget.note.deleted, 'autofocus': false}),
);

if (widget.searchView) context.pop();
if (widget.searchView) {
context.pop();
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/pages/bin/bin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class _BinPageState extends ConsumerState<BinPage> {
Widget build(BuildContext context) {
return ref.watch(binProvider).when(
data: (notes) {
if (notes.isEmpty) return EmptyPlaceholder.bin();
if (notes.isEmpty) {
return EmptyPlaceholder.bin();
}

final useSeparators =
PreferencesManager().get<bool>(PreferenceKey.separator) ?? PreferenceKey.separator.defaultValue! as bool;
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/editor/about_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class AboutSheet extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final note = ref.watch(currentNoteProvider);

if (note == null) return const ErrorPlaceholder();
if (note == null) {
return const ErrorPlaceholder();
}

return ListView(
shrinkWrap: true,
Expand Down
12 changes: 9 additions & 3 deletions lib/pages/editor/editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class _EditorState extends ConsumerState<EditorPage> {
late FleatherController fleatherController;

void _synchronizeTitle(Note note, String? newTitle) {
if (newTitle == null) return;
if (newTitle == null) {
return;
}

ref.read(notesProvider.notifier).edit(note..title = newTitle);
}
Expand All @@ -42,7 +44,9 @@ class _EditorState extends ConsumerState<EditorPage> {
}

void _launchUrl(String? url) {
if (url == null) return;
if (url == null) {
return;
}

launchUrlString(url);
}
Expand All @@ -51,7 +55,9 @@ class _EditorState extends ConsumerState<EditorPage> {
Widget build(BuildContext context) {
final note = ref.watch(currentNoteProvider);

if (note == null) return const LoadingPlaceholder();
if (note == null) {
return const LoadingPlaceholder();
}

titleController.text = note.title;
fleatherController = FleatherController(document: note.document);
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/notes/notes_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class _NotesPageState extends ConsumerState<NotesPage> {
Widget build(BuildContext context) {
return ref.watch(notesProvider).when(
data: (notes) {
if (notes.isEmpty) return EmptyPlaceholder.notes();
if (notes.isEmpty) {
return EmptyPlaceholder.notes();
}

final useSeparators =
PreferencesManager().get<bool>(PreferenceKey.separator) ?? PreferenceKey.separator.defaultValue! as bool;
Expand Down
12 changes: 9 additions & 3 deletions lib/pages/settings/interactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Interactions {
);
},
).then((locale) async {
if (locale == null) return;
if (locale == null) {
return;
}

LocaleManager().setLocale(locale);
await Restart.restartApp();
Expand Down Expand Up @@ -79,7 +81,9 @@ class Interactions {
);
},
).then((themeMode) {
if (themeMode == null) return;
if (themeMode == null) {
return;
}

ThemeManager().setThemeMode(themeMode);
});
Expand Down Expand Up @@ -118,7 +122,9 @@ class Interactions {
);
},
).then((confirmationsValue) {
if (confirmationsValue == null) return;
if (confirmationsValue == null) {
return;
}

PreferencesManager().set<String>(PreferenceKey.confirmations.name, confirmationsValue.name);
});
Expand Down
12 changes: 9 additions & 3 deletions lib/utils/database_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class DatabaseManager {
Future<bool> _export(String mimeType, String extension, String notesAsString) async {
final exportDirectory = await saf.openDocumentTree();

if (exportDirectory == null) return false;
if (exportDirectory == null) {
return false;
}

final timestamp = DateTime.timestamp();

Expand All @@ -129,11 +131,15 @@ class DatabaseManager {
mimeType: 'application/json',
);

if (importFiles == null || importFiles.isEmpty) return false;
if (importFiles == null || importFiles.isEmpty) {
return false;
}

final importedData = await saf.getDocumentContent(importFiles.first);

if (importedData == null) throw Exception(localizations.error_read_file);
if (importedData == null) {
throw Exception(localizations.error_read_file);
}

final importedString = utf8.decode(importedData);
final notesJson = jsonDecode(importedString) as List;
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/locale_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class LocaleManager {
}

void setLocale(Locale? locale) {
if (locale == null) return;
if (locale == null) {
return;
}

PreferencesManager().set(PreferenceKey.locale.name, locale.languageCode);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/utils/preferences/preferences_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class PreferencesManager {
}

void set<T>(String key, T value) {
if (T == dynamic) throw ArgumentError('The type T is required.');
if (T == dynamic) {
throw ArgumentError('The type T is required.');
}

if (T == bool) {
_preferences.setBool(key, value as bool);
Expand All @@ -33,7 +35,9 @@ class PreferencesManager {
}

T? get<T>(PreferenceKey preferenceKey) {
if (T == dynamic) throw ArgumentError('The type T is required.');
if (T == dynamic) {
throw ArgumentError('The type T is required.');
}

return _preferences.get(preferenceKey.name) as T?;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/theme_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class ThemeManager {
}

void setThemeMode(ThemeMode? themeMode) {
if (themeMode == null) return;
if (themeMode == null) {
return;
}

int value;
switch (themeMode) {
Expand Down

0 comments on commit deadbd6

Please sign in to comment.