Skip to content

Commit

Permalink
refactor: update lint rules (espresso-cash#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
ookami-kb authored Oct 3, 2023
1 parent 133457c commit 1c12eb0
Show file tree
Hide file tree
Showing 129 changed files with 431 additions and 445 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: "1.8.4"
version: "1.9.1"

- name: Activate utils
run: make activate_utils
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: "1.8.4"
version: "1.9.1"

- name: Activate utils
run: make activate_utils
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: "1.8.4"
version: "1.9.1"

- name: Activate utils
run: make activate_utils
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: "1.8.4"
version: "1.9.1"

- name: Activate utils
run: make activate_utils
Expand Down Expand Up @@ -216,7 +216,7 @@ jobs:
uses: CQLabs/setup-dcm@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: "1.8.4"
version: "1.9.1"

- name: Activate utils
run: make activate_utils
Expand Down
2 changes: 1 addition & 1 deletion packages/borsh/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies:

dev_dependencies:
build_runner: ^2.0.6
mews_pedantic: ^0.16.0
mews_pedantic: ^0.19.0
test: ^1.17.10
4 changes: 4 additions & 0 deletions packages/borsh_annotation/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:mews_pedantic/analysis_options.yaml

dart_code_metrics:
rules:
avoid-passing-self-as-argument: false
3 changes: 2 additions & 1 deletion packages/borsh_annotation/lib/src/binary_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ BigInt _decodeBigInt(Iterable<int> bytes, {required bool isSigned}) {
BigInt result;

if (list.length == 1) {
// ignore: avoid-unnecessary-reassignment, valid case
result = BigInt.from(list.first);
} else {
result = BigInt.zero;
for (var i = 0; i < list.length; i++) {
for (int i = 0; i < list.length; i++) {
final item = list[i];
result |= BigInt.from(item) << (8 * i);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/borsh_annotation/lib/src/binary_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Iterable<int> _encodeBigIntAsUnsigned(BigInt number, int s) {
}

final result = Uint8List(s);
for (var i = 0; i < s; i++) {
for (int i = 0; i < s; i++) {
result[i] = (number & _byteMask).toInt();
number = number >> 8;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/borsh_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ environment:
sdk: ">=2.13.0 <3.0.0"

dev_dependencies:
mews_pedantic: ^0.16.0
mews_pedantic: ^0.19.0
4 changes: 4 additions & 0 deletions packages/espressocash_app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ analyzer:

dart_code_metrics:
rules:
avoid-passing-self-as-argument: false
avoid-banned-imports:
severity: error
entries:
Expand All @@ -42,6 +43,9 @@ dart_code_metrics:
- paths: [".*/ui/.+\\.dart"]
deny: [".*/features/.*"]
message: "Do not import features from ui"
avoid-nullable-interpolation:
exclude:
- test/**

rules-exclude:
- "**/*.gr.dart"
Expand Down
2 changes: 1 addition & 1 deletion packages/espressocash_app/lib/core/presentation/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ extension StringExt on String {
}

String withZeroWidthSpaces() =>
splitMapJoin('', onMatch: (m) => '${m.group(0)}\u200b');
splitMapJoin('', onMatch: (m) => '${m.group(0) ?? ''}\u200b');
}
2 changes: 1 addition & 1 deletion packages/espressocash_app/lib/core/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class KeyPairParams {
Future<Wallet> walletFromParts({
required String firstPart,
required String secondPart,
}) async {
}) {
final keyPart1 = ByteArray.fromBase58(firstPart).toList();
final keyPart2 = ByteArray.fromBase58(secondPart).toList();

Expand Down
2 changes: 1 addition & 1 deletion packages/espressocash_app/lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final sl = GetIt.instance;
preferRelativeImports: false,
throwOnMissingDependencies: true,
)
Future<void> configureDependencies() async => sl.init();
Future<void> configureDependencies() => sl.init();

@module
abstract class AppModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ extension ODPRowToActivityExt on ODPRow {
}

extension OSKPRowToActivityExt on OSKPRow {
Future<Activity> toActivity(TokenList tokens) async =>
Activity.outgoingSplitKeyPayment(
Activity toActivity(TokenList tokens) => Activity.outgoingSplitKeyPayment(
id: id,
created: created,
data: await toModel(tokens),
data: toModel(tokens),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ class PendingActivitiesRepository {
opr.watch().map((rows) => rows.map((r) => r.toActivity()));
final odpStream =
odp.watch().map((rows) => rows.map((r) => r.toActivity(_tokens)));
final oskpStream = oskp
.watch()
.map((rows) => rows.map((r) => r.toActivity(_tokens)))
.asyncMap(Future.wait);
final oskpStream =
oskp.watch().map((rows) => rows.map((r) => r.toActivity(_tokens)));
final swapStream =
swap.watch().map((rows) => rows.map((r) => r.toActivity(_tokens)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ extension Q<Tbl extends HasResultSet, D> on ResultSetImplementation<Tbl, D> {
}
}

// ignore: prefer-public-exception-classes, intentionally private
class _Ignore implements Exception {
const _Ignore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ActivitiesScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final bottom = MediaQuery.of(context).padding.bottom;
final bottom = MediaQuery.paddingOf(context).bottom;
const insets = EdgeInsets.only(left: 8, right: 8, top: _padding);
final isTransactions = goToTransactions ?? false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TxUpdaterBloc extends Bloc<_Event, _State> {
await _fetchedRepository.update(_wallet.publicKey);

emit(const TxUpdaterState.none());
} on Exception catch (e) {
emit(TxUpdaterState.error(e));
} on Exception catch (error) {
emit(TxUpdaterState.error(error));
emit(const TxUpdaterState.none());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AppLockBloc extends Bloc<AppLockEvent, AppLockState> {
}
}

Future<void> _onLock(AppLockEventLock _, _Emitter emit) async {
void _onLock(AppLockEventLock _, _Emitter emit) {
if (state is! AppLockStateEnabled) return;
emit(const AppLockState.locked(isRetrying: false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PinKeypad extends StatelessWidget {

@override
Widget build(BuildContext context) => SizedBox(
height: MediaQuery.of(context).size.height * 0.5,
height: MediaQuery.sizeOf(context).height * 0.5,
child: Padding(
padding: const EdgeInsets.all(20),
child: GridView.count(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PuzzleReminderBloc
PuzzleReminderEventLoggedOut() => _onLoggedOut(),
};

Future<PuzzleReminderData> _readSharedPreferences() async {
PuzzleReminderData _readSharedPreferences() {
final content = _sharedPreferences.getString(_spKey);

return content == null
Expand Down Expand Up @@ -97,7 +97,7 @@ class PuzzleReminderBloc
),
// Check for reminder if user account was loaded from storage
loaded: () async {
final data = await _readSharedPreferences();
final data = _readSharedPreferences();

if (data.shouldRemindNow) {
emit(const PuzzleReminderState.remindNow());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ class BalancesBloc extends Bloc<BalancesEvent, BalancesState>

final mainAccounts = await Future.wait<_MainTokenAccount?>(
allAccounts.map((programAccount) async {
final pubKey = programAccount.pubkey;
final account = programAccount.account;
final data = account.data;

if (data is ParsedAccountData) {
return data.maybeWhen<Future<_MainTokenAccount?>>(
splToken: (parsed) => parsed.maybeMap<Future<_MainTokenAccount?>>(
account: (a) =>
_MainTokenAccount.create(pubKey, a.info, _tokens),
account: (a) => _MainTokenAccount.create(
programAccount.pubkey,
a.info,
_tokens,
),
orElse: () async => null,
),
orElse: () async => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RefreshBalancesWrapper extends StatefulWidget {
class _RefreshBalancesWrapperState extends State<RefreshBalancesWrapper> {
AsyncResult<void> _listenForProcessingStateAndThrowOnError(
Stream<ProcessingState> stream,
) async =>
) =>
stream
.firstWhere(
(state) => switch (state) {
Expand All @@ -64,7 +64,7 @@ class _RefreshBalancesWrapperState extends State<RefreshBalancesWrapper> {
return _listenForProcessingStateAndThrowOnError(bloc.stream);
}

AsyncResult<void> _updateBalances() async {
AsyncResult<void> _updateBalances() {
context.notifyBalanceAffected();

return _listenForProcessingStateAndThrowOnError(sl<BalancesBloc>().stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _ContentState extends State<_Content> {
if (country != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
final index = _countries.indexOf(country);
final centerOffset = (context.size?.height ?? 0 - _tileHeight) / 2.5;
final centerOffset = ((context.size?.height ?? 0) - _tileHeight) / 2.5;
final offset = index * _tileHeight - centerOffset;
_scrollController.jumpTo(offset);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FavoriteTokenRepository {
.map((e) => e.map((e) => e.toToken(_tokenList)).toList());
}

Future<List<Token>> read() async {
Future<List<Token>> read() {
final query = _db.select(_db.favoriteTokenRows);

return query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class PendingISKPRepository {
}
}

Future<void> save(SplitKeyFirstLink firstPart) async =>
Future<void> save(SplitKeyFirstLink firstPart) =>
SharedPreferences.getInstance().then(
(value) => value.setString(_key, jsonEncode(firstPart.toJson())),
);

Future<void> clear() async =>
Future<void> clear() =>
SharedPreferences.getInstance().then((value) => value.remove(_key));

static const _key = 'pending_iskp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class ISKPService {
.letAsync((it) => it.resign(account));

return ISKPStatus.txCreated(tx, slot: response.slot);
} on DioError catch (e) {
if (e.toEspressoCashError() == EspressoCashError.invalidEscrowAccount) {
} on DioError catch (error) {
if (error.toEspressoCashError() ==
EspressoCashError.invalidEscrowAccount) {
return const ISKPStatus.txFailure(
reason: TxFailureReason.escrowFailure,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension ISKPExt on BuildContext {
Future<String> createISKP({
required Ed25519HDKeyPair escrow,
required SplitKeyApiVersion version,
}) async =>
}) =>
runWithLoader(this, () async {
final payment = await sl<ISKPService>().create(
account: read<MyAccount>().wallet,
Expand All @@ -24,7 +24,7 @@ extension ISKPExt on BuildContext {
return payment.id;
});

Future<void> retryISKP(IncomingSplitKeyPayment payment) async =>
Future<void> retryISKP(IncomingSplitKeyPayment payment) =>
runWithLoader(this, () async {
await sl<ISKPService>().retry(
payment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class InvestmentsScreen extends StatelessWidget {
child: SizedBox(
height: max(
0,
MediaQuery.of(context).padding.bottom -
MediaQuery.paddingOf(context).bottom -
cpNavigationBarheight,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MainScreen extends StatefulWidget {
}

class _MainScreenState extends State<MainScreen> {
Future<void> _onQrScanner() async =>
Future<void> _onQrScanner() =>
context.launchQrScannerFlow(cryptoCurrency: Currency.usdc);

@override
Expand Down Expand Up @@ -99,7 +99,7 @@ class _MainScreenState extends State<MainScreen> {
child: SizedBox(
height: max(
0,
MediaQuery.of(context).padding.bottom -
MediaQuery.paddingOf(context).bottom -
cpNavigationBarheight +
8,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class _Headline extends StatelessWidget {
final VoidCallback onInfo;

@override
Widget build(BuildContext context) => RichText(
text: TextSpan(
Widget build(BuildContext context) => Text.rich(
TextSpan(
text: context.l10n.cryptoCashBalance,
style: const TextStyle(
color: Colors.white,
Expand All @@ -229,8 +229,8 @@ class _Headline extends StatelessWidget {
WidgetSpan(
child: GestureDetector(
onTap: onInfo,
child: RichText(
text: TextSpan(
child: Text.rich(
TextSpan(
text: context.l10n.inUsdc,
style: const TextStyle(
fontSize: 16,
Expand Down Expand Up @@ -278,7 +278,7 @@ class _HeaderSwitcherState extends State<_HeaderSwitcher> {
Widget build(BuildContext context) => LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (_firstChildHeight == null) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_firstChildHeight = context.size?.height;
});
Expand Down
Loading

0 comments on commit 1c12eb0

Please sign in to comment.