treewide: add and fix some lints
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
|
||||
# The following line activates a set of recommended lints for Flutter apps,
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
include:
|
||||
- package:flutter_lints/flutter.yaml
|
||||
|
||||
linter:
|
||||
# The lint rules applied to this project can be customized in the
|
||||
@@ -21,8 +22,20 @@ linter:
|
||||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||
# producing the lint.
|
||||
rules:
|
||||
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||
always_declare_return_types: true
|
||||
annotate_redeclares: true
|
||||
avoid_print: false
|
||||
avoid_setters_without_getters: true
|
||||
avoid_slow_async_io: true
|
||||
directives_ordering: true
|
||||
eol_at_end_of_file: true
|
||||
prefer_const_declarations: true
|
||||
prefer_contains: true
|
||||
prefer_final_fields: true
|
||||
prefer_final_locals: true
|
||||
prefer_single_quotes: true
|
||||
use_key_in_widget_constructors: true
|
||||
use_null_aware_elements: true
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
|
||||
@@ -102,7 +102,7 @@ class _SearchResultCardState extends State<SearchResultCard> {
|
||||
icon: Icons.star,
|
||||
onPressed: (_) =>
|
||||
GetIt.instance.get<Database>().libraryListToggleEntry(
|
||||
"favourites",
|
||||
'favourites',
|
||||
jmdictEntryId: widget.result.entryId,
|
||||
kanji: null,
|
||||
),
|
||||
|
||||
@@ -27,7 +27,7 @@ Future<String> databasePath() async {
|
||||
Future<bool> databaseNeedsInitialization() async {
|
||||
final String dbPath = await databasePath();
|
||||
|
||||
if (!await File(dbPath).exists()) {
|
||||
if (!File(dbPath).existsSync()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ Future<void> setupDatabase() async {
|
||||
final String dbPath = await databasePath();
|
||||
|
||||
assert(
|
||||
await File(dbPath).exists(),
|
||||
File(dbPath).existsSync(),
|
||||
'Database file should exist at this point',
|
||||
);
|
||||
|
||||
@@ -231,11 +231,9 @@ Future<void> resetDatabase() async {
|
||||
Future<void> extractJadbFromAssets(String path) async {
|
||||
final File jadbFile = File(path);
|
||||
|
||||
if (!await jadbFile.exists()) {
|
||||
jadbFile.createSync();
|
||||
}
|
||||
jadbFile.createSync();
|
||||
|
||||
ByteData data = await rootBundle.load('assets/jadb.sqlite');
|
||||
final ByteData data = await rootBundle.load('assets/jadb.sqlite');
|
||||
await jadbFile.writeAsBytes(
|
||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ extension HistoryEntryExt on DatabaseExecutor {
|
||||
)
|
||||
.toList();
|
||||
|
||||
KanjiSearchResult? kanjiSearchResult = includeSearchResult
|
||||
final KanjiSearchResult? kanjiSearchResult = includeSearchResult
|
||||
? await jadbSearchKanji(kanji)
|
||||
: null;
|
||||
|
||||
@@ -118,7 +118,7 @@ extension HistoryEntryExt on DatabaseExecutor {
|
||||
${pageSize != null ? 'LIMIT ?' : ''}
|
||||
${page != null ? 'OFFSET ?' : ''}
|
||||
''',
|
||||
[if (pageSize != null) pageSize, if (page != null) page * pageSize!],
|
||||
[?pageSize, if (page != null) page * pageSize!],
|
||||
);
|
||||
|
||||
final List<HistoryEntry> entries = result.map((e) {
|
||||
|
||||
@@ -25,7 +25,7 @@ extension LibraryListExt on DatabaseExecutor {
|
||||
${pageSize != null ? 'LIMIT ?' : ''}
|
||||
${page != null ? 'OFFSET ?' : ''}
|
||||
''',
|
||||
[if (pageSize != null) pageSize, if (page != null) page * pageSize!],
|
||||
[?pageSize, if (page != null) page * pageSize!],
|
||||
);
|
||||
|
||||
// COUNT(*) AS "count"
|
||||
@@ -137,7 +137,7 @@ extension LibraryListExt on DatabaseExecutor {
|
||||
[
|
||||
listName,
|
||||
listName,
|
||||
if (pageSize != null) pageSize,
|
||||
?pageSize,
|
||||
if (page != null) page * pageSize!,
|
||||
],
|
||||
);
|
||||
@@ -289,7 +289,7 @@ extension LibraryListExt on DatabaseExecutor {
|
||||
bool doesNotExistOk = false,
|
||||
}) async {
|
||||
assert(listName.isNotEmpty, 'Library list name must not be empty.');
|
||||
assert(listName != "favourites", 'Cannot delete the "favourites" list.');
|
||||
assert(listName != 'favourites', 'Cannot delete the "favourites" list.');
|
||||
|
||||
if (!doesNotExistOk && !(await libraryListExists(listName))) {
|
||||
return false;
|
||||
@@ -602,7 +602,7 @@ extension LibraryListExt on DatabaseExecutor {
|
||||
String listName,
|
||||
List<Map<String, Object?>> jsonEntries,
|
||||
) async {
|
||||
List<LibraryListEntry> entries = jsonEntries
|
||||
final List<LibraryListEntry> entries = jsonEntries
|
||||
.map((e) => LibraryListEntry.fromJson(e))
|
||||
.toList();
|
||||
|
||||
@@ -699,7 +699,7 @@ class LibraryListEntry {
|
||||
);
|
||||
assert(
|
||||
json.containsKey('lastModified'),
|
||||
"Library entry must have a lastModified timestamp",
|
||||
'Library entry must have a lastModified timestamp',
|
||||
);
|
||||
|
||||
if (json.containsKey('kanji') && json['kanji'] != null) {
|
||||
|
||||
@@ -48,7 +48,7 @@ class InitializationView extends StatelessWidget {
|
||||
case CheckDatabase _:
|
||||
return const Text('Checking for database updates...');
|
||||
|
||||
case BackupUserData s:
|
||||
case final BackupUserData s:
|
||||
return Column(
|
||||
children: [
|
||||
const Text('Backing up user data...'),
|
||||
@@ -56,7 +56,7 @@ class InitializationView extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
|
||||
case MigrateDatabase s:
|
||||
case final MigrateDatabase s:
|
||||
return Column(
|
||||
children: [
|
||||
const Text('Performing database migrations...'),
|
||||
@@ -64,7 +64,7 @@ class InitializationView extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
|
||||
case RestoreUserData s:
|
||||
case final RestoreUserData s:
|
||||
return Column(
|
||||
children: [
|
||||
const Text('Restoring user data...'),
|
||||
|
||||
@@ -96,7 +96,7 @@ class _KanjiSearchResultPageState extends State<KanjiSearchResultPage> {
|
||||
final String charcode = kanji.characters.first.codeUnits
|
||||
.map((c) => c.toRadixString(16))
|
||||
.join();
|
||||
return "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/$charcode.gif";
|
||||
return 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/$charcode.gif';
|
||||
}
|
||||
|
||||
Widget _body(KanjiSearchResult result) {
|
||||
@@ -116,7 +116,7 @@ class _KanjiSearchResultPageState extends State<KanjiSearchResultPage> {
|
||||
GetIt.instance
|
||||
.get<Database>()
|
||||
.libraryListToggleEntry(
|
||||
"favourites",
|
||||
'favourites',
|
||||
jmdictEntryId: null,
|
||||
kanji: result.kanji,
|
||||
)
|
||||
@@ -169,7 +169,7 @@ class _KanjiSearchResultPageState extends State<KanjiSearchResultPage> {
|
||||
|
||||
GetIt.instance
|
||||
.get<Database>()
|
||||
.libraryListListContains("favourites", kanji: widget.kanji)
|
||||
.libraryListListContains('favourites', kanji: widget.kanji)
|
||||
.then((value) => setState(() => isFavourite = value));
|
||||
|
||||
if (!incognitoModeEnabled && !addedToDatabase) {
|
||||
|
||||
@@ -37,7 +37,7 @@ class InitializationCubit extends Cubit<InitializationStatus> {
|
||||
emit(CheckDatabase());
|
||||
if (deleteDatabase || await databaseNeedsInitialization()) {
|
||||
final String dbPath = await databasePath();
|
||||
final databaseAlreadyExists = await File(dbPath).exists();
|
||||
final databaseAlreadyExists = File(dbPath).existsSync();
|
||||
|
||||
late final File? tmpdirDataDump;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ Future<Database> createDatabaseCopy({
|
||||
}) async {
|
||||
final jadbFile = File(jadbPath);
|
||||
if (!jadbFile.existsSync()) {
|
||||
throw Exception("JADB_PATH does not exist: $jadbPath");
|
||||
throw Exception('JADB_PATH does not exist: $jadbPath');
|
||||
}
|
||||
|
||||
// Make a copy of jadbPath
|
||||
@@ -25,12 +25,12 @@ Future<Database> createDatabaseCopy({
|
||||
.nextInt((pow(2, 32) - 1) as int)
|
||||
.toRadixString(16);
|
||||
final jadbCopyPath = jadbFile.parent.uri
|
||||
.resolve("jadb_copy_$random_suffix.sqlite")
|
||||
.resolve('jadb_copy_$random_suffix.sqlite')
|
||||
.path;
|
||||
|
||||
await jadbFile.copy(jadbCopyPath);
|
||||
|
||||
print("Using database copy: $jadbCopyPath");
|
||||
print('Using database copy: $jadbCopyPath');
|
||||
|
||||
// Initialize FFI
|
||||
sqfliteFfiInit();
|
||||
@@ -48,19 +48,19 @@ Future<Database> createDatabaseCopy({
|
||||
}
|
||||
|
||||
Future<void> insertTestData(Database db) async {
|
||||
final libraryList1 = await db.libraryListInsertList("Test Library 1");
|
||||
final libraryList1 = await db.libraryListInsertList('Test Library 1');
|
||||
assert(libraryList1 == true);
|
||||
|
||||
await db.libraryListInsertEntry(
|
||||
"Test Library 1",
|
||||
'Test Library 1',
|
||||
jmdictEntryId: null,
|
||||
kanji: "漢",
|
||||
kanji: '漢',
|
||||
);
|
||||
|
||||
await db.libraryListInsertEntry(
|
||||
"Test Library 1",
|
||||
'Test Library 1',
|
||||
jmdictEntryId: null,
|
||||
kanji: "字",
|
||||
kanji: '字',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,19 +70,19 @@ void main() {
|
||||
late final Database database;
|
||||
|
||||
setUpAll(() {
|
||||
if (!Platform.environment.containsKey("LIBSQLITE_PATH")) {
|
||||
throw Exception("LIBSQLITE_PATH environment variable is not set.");
|
||||
if (!Platform.environment.containsKey('LIBSQLITE_PATH')) {
|
||||
throw Exception('LIBSQLITE_PATH environment variable is not set.');
|
||||
}
|
||||
|
||||
if (!Platform.environment.containsKey("JADB_PATH")) {
|
||||
throw Exception("JADB_PATH environment variable is not set.");
|
||||
if (!Platform.environment.containsKey('JADB_PATH')) {
|
||||
throw Exception('JADB_PATH environment variable is not set.');
|
||||
}
|
||||
|
||||
libsqlitePath = File(
|
||||
Platform.environment["LIBSQLITE_PATH"]!,
|
||||
Platform.environment['LIBSQLITE_PATH']!,
|
||||
).resolveSymbolicLinksSync();
|
||||
jadbPath = File(
|
||||
Platform.environment["JADB_PATH"]!,
|
||||
Platform.environment['JADB_PATH']!,
|
||||
).resolveSymbolicLinksSync();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user