Skip to content

Commit

Permalink
Apply stricter linting
Browse files Browse the repository at this point in the history
  • Loading branch information
petlyh committed Sep 24, 2024
1 parent d6b8e1c commit c03e09b
Show file tree
Hide file tree
Showing 66 changed files with 1,634 additions and 1,284 deletions.
31 changes: 7 additions & 24 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# 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:lint/strict.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
- prefer_double_quotes
- avoid_final_parameters
Expand All @@ -31,11 +11,14 @@ linter:
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- unawaited_futures

analyzer:
language:
strict-casts: true
strict-raw-types: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
errors:
todo: info
exclude: [
lib/**.g.dart,
]
17 changes: 11 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ void main() async {
}

void registerKanjivgLicense() => LicenseRegistry.addLicense(() async* {
yield LicenseEntryWithLineBreaks(["KanjiVg"],
await rootBundle.loadString("assets/kanjivg/LICENSE.kanjivg.txt"));
yield LicenseEntryWithLineBreaks(
["KanjiVg"],
await rootBundle.loadString("assets/kanjivg/LICENSE.kanjivg.txt"),
);
});

const mainColor = Color(0xFF27CA27);
Expand All @@ -26,8 +28,9 @@ class JsDictApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DynamicColorBuilder(builder: (lightDynamic, darkDynamic) {
return MultiProvider(
return DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => QueryProvider()),
ChangeNotifierProvider(create: (_) => ThemeProvider()),
Expand Down Expand Up @@ -57,8 +60,10 @@ class JsDictApp extends StatelessWidget {
),
home: const SearchScreen(),
);
});
});
},
);
},
);
}

// Adds a "Debug" suffix if the app is running in debug mode.
Expand Down
34 changes: 18 additions & 16 deletions lib/models/kanji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ class Kanji implements SearchType {
static String createUrl(String kanji) =>
"https://jisho.org/search/${Uri.encodeComponent("$kanji #kanji")}";

const Kanji(
{required this.kanji,
required this.strokeCount,
this.type,
this.jlptLevel = JLPTLevel.none,
this.meanings = const [],
this.kunReadings = const [],
this.onReadings = const [],
this.details});
const Kanji({
required this.kanji,
required this.strokeCount,
this.type,
this.jlptLevel = JLPTLevel.none,
this.meanings = const [],
this.kunReadings = const [],
this.onReadings = const [],
this.details,
});
}

class KanjiDetails {
Expand All @@ -42,13 +43,14 @@ class KanjiDetails {
final List<Compound> onCompounds;
final List<Compound> kunCompounds;

const KanjiDetails(
{required this.parts,
required this.variants,
required this.radical,
required this.frequency,
required this.onCompounds,
required this.kunCompounds});
const KanjiDetails({
required this.parts,
required this.variants,
required this.radical,
required this.frequency,
required this.onCompounds,
required this.kunCompounds,
});
}

class Radical {
Expand Down
1 change: 0 additions & 1 deletion lib/models/models.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "package:jsdict/packages/inflection.dart";
import "package:jsdict/packages/is_kanji.dart";
import "package:jsdict/packages/list_extensions.dart";

part "furigana.dart";
part "jlpt.dart";
Expand Down
7 changes: 6 additions & 1 deletion lib/models/name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ class Name implements SearchType {
String toString() => reading != null ? "$japanese【$reading】" : japanese;

const Name(
this.japanese, this.reading, this.english, this.type, this.wikipediaWord);
this.japanese,
this.reading,
this.english,
this.type,
this.wikipediaWord,
);
}
32 changes: 17 additions & 15 deletions lib/models/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ class SearchResponse<T extends SearchType> {
final GrammarInfo? grammarInfo;
final Conversion? conversion;

const SearchResponse(
{required this.results,
this.hasNextPage = false,
this.zenEntries = const [],
this.correction,
this.noMatchesFor = const [],
this.grammarInfo,
this.conversion});

const SearchResponse.noMatches(this.noMatchesFor,
{this.zenEntries = const [],
this.correction,
this.grammarInfo,
this.conversion})
: results = const [],
const SearchResponse({
required this.results,
this.hasNextPage = false,
this.zenEntries = const [],
this.correction,
this.noMatchesFor = const [],
this.grammarInfo,
this.conversion,
});

const SearchResponse.noMatches(
this.noMatchesFor, {
this.zenEntries = const [],
this.correction,
this.grammarInfo,
this.conversion,
}) : results = const [],
hasNextPage = false;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/models/sentence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ class Sentence implements SearchType {
kanji = null;

const Sentence.all(
this.id, this.japanese, this.english, this.copyright, this.kanji);
this.id,
this.japanese,
this.english,
this.copyright,
this.kanji,
);

Sentence withKanji(List<Kanji> kanji) =>
Sentence.all(id, japanese, english, copyright, kanji);
Expand Down
97 changes: 46 additions & 51 deletions lib/models/word.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,37 @@ class Word implements SearchType {

final WordDetails? details;

const Word(
{required this.word,
required this.definitions,
this.otherForms = const [],
this.commonWord = false,
this.wanikaniLevels = const [],
this.jlptLevel = JLPTLevel.none,
this.audioUrl,
this.notes = const [],
this.collocations = const [],
this.id,
this.inflectionId = "",
this.hasWikipedia = false,
this.details});
const Word({
required this.word,
required this.definitions,
this.otherForms = const [],
this.commonWord = false,
this.wanikaniLevels = const [],
this.jlptLevel = JLPTLevel.none,
this.audioUrl,
this.notes = const [],
this.collocations = const [],
this.id,
this.inflectionId = "",
this.hasWikipedia = false,
this.details,
});

Word withDetails(WordDetails details) => Word(
details: details,
word: word,
definitions: definitions,
otherForms: otherForms,
commonWord: commonWord,
wanikaniLevels: wanikaniLevels,
jlptLevel: jlptLevel,
audioUrl: audioUrl,
notes: notes,
collocations: collocations,
id: id,
inflectionId: inflectionId,
hasWikipedia: hasWikipedia);
details: details,
word: word,
definitions: definitions,
otherForms: otherForms,
commonWord: commonWord,
wanikaniLevels: wanikaniLevels,
jlptLevel: jlptLevel,
audioUrl: audioUrl,
notes: notes,
collocations: collocations,
id: id,
inflectionId: inflectionId,
hasWikipedia: hasWikipedia,
);

InflectionData? get inflectionData =>
inflectionId.isNotEmpty ? InflectionData(word.text, inflectionId) : null;
Expand All @@ -78,12 +80,13 @@ class Definition {

final Sentence? exampleSentence;

const Definition(
{required this.meanings,
this.types = const [],
this.tags = const [],
this.seeAlso = const [],
this.exampleSentence});
const Definition({
required this.meanings,
this.types = const [],
this.tags = const [],
this.seeAlso = const [],
this.exampleSentence,
});

@override
String toString() {
Expand All @@ -98,11 +101,13 @@ class WikipediaInfo {
final WikipediaPage? wikipediaJapanese;
final WikipediaPage? dbpedia;

const WikipediaInfo(this.title,
{this.textAbstract,
this.wikipediaEnglish,
this.wikipediaJapanese,
this.dbpedia});
const WikipediaInfo(
this.title, {
this.textAbstract,
this.wikipediaEnglish,
this.wikipediaJapanese,
this.dbpedia,
});
}

class WikipediaPage {
Expand Down Expand Up @@ -140,21 +145,11 @@ class Note {

const Note(this.form, this.note);

@override
String toString() => "$form: $note";

static Note parse(String text) {
factory Note.parse(String text) {
final split = text.split(": ");
return Note(split.first, split.last);
}

static List<Note> parseAll(String text) {
return text
.trim()
.replaceFirst(RegExp(r"\.$"), "")
.split(". ")
.deduplicate<String>()
.map(Note.parse)
.toList();
}
@override
String toString() => "$form: $note";
}
8 changes: 6 additions & 2 deletions lib/packages/furigana_ruby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import "package:jsdict/models/models.dart";
import "package:ruby_text/ruby_text.dart";

extension FuriganaMethods on Furigana {
List<RubyTextData> get rubyData => map((part) => RubyTextData(part.text,
ruby: part.furigana.isNotEmpty ? part.furigana : null)).toList();
List<RubyTextData> get rubyData => map(
(part) => RubyTextData(
part.text,
ruby: part.furigana.isNotEmpty ? part.furigana : null,
),
).toList();
}
Loading

0 comments on commit c03e09b

Please sign in to comment.