From c5d1260feb49e4e05f3a8712ee22febc43a5d582 Mon Sep 17 00:00:00 2001 From: Seiya Kokushi Date: Mon, 31 Jul 2023 09:44:13 +0900 Subject: [PATCH] refactor: use_media_query_xxx_of to unnecessary_rebuilds_from_media_query (#20) --- examples/nilts_example/analysis_options.yaml | 2 +- packages/nilts/README.md | 8 +- packages/nilts/lib/nilts.dart | 4 +- ...nnecessary_rebuilds_from_media_query.dart} | 11 +-- ...nnecessary_rebuilds_from_media_query.dart} | 78 +++++++++---------- 5 files changed, 52 insertions(+), 51 deletions(-) rename packages/nilts/lib/src/lints/{use_media_query_xxx_of.dart => unnecessary_rebuilds_from_media_query.dart} (95%) rename packages/nilts_test/test/lints/{use_media_query_xxx_of.dart => unnecessary_rebuilds_from_media_query.dart} (57%) diff --git a/examples/nilts_example/analysis_options.yaml b/examples/nilts_example/analysis_options.yaml index 58585ec..9d83b56 100644 --- a/examples/nilts_example/analysis_options.yaml +++ b/examples/nilts_example/analysis_options.yaml @@ -13,4 +13,4 @@ custom_lint: # enable_all_lint_rules: false rules: # Disable particular lint rules if you want ignore them whole package. - # - use_media_query_xxx_of: false + # - unnecessary_rebuilds_from_media_query: false diff --git a/packages/nilts/README.md b/packages/nilts/README.md index e8703c5..88d5daf 100644 --- a/packages/nilts/README.md +++ b/packages/nilts/README.md @@ -50,7 +50,7 @@ Add lint rule name and set `false` to disable it. custom_lint: rules: # Disable particular lint rules if you want ignore them whole package. - - use_media_query_xxx_of: false + - unnecessary_rebuilds_from_media_query: false ``` ### Enabling strategy @@ -63,7 +63,7 @@ custom_lint: # Disable all lint rules depends on custom_lint. enable_all_lint_rules: false rules: - - use_media_query_xxx_of: true + - unnecessary_rebuilds_from_media_query: true ``` **NOTE: If you `enable_all_lint_rules` set to `false`, all of lint rules (not only all of nilts's lint rules) depends on `custom_lint` will be disabled by default.** @@ -79,11 +79,11 @@ Some of lint rules support quick fixes on IDE. | Rule name | Overview | Target SDK | Rule type | Maturity level | Quick fix | | :-- | :-- | :--: | :--: | :--: | :--: | -| [use\_media\_query\_xxx\_of](#use_media_query_xxx_of) | Checks `MediaQuery.xxxOf(context)` or `MediaQuery.maybeXxxOf(context)` usages. | >= Flutter 3.10.0 (Dart 3.0.0) | Practice | Experimental | ✅️ | +| [unnecessary\_rebuilds\_from\_media\_query](#unnecessary_rebuilds_from_media_query) | Checks `MediaQuery.xxxOf(context)` or `MediaQuery.maybeXxxOf(context)` usages. | >= Flutter 3.10.0 (Dart 3.0.0) | Practice | Experimental | ✅️ | ### Details -#### use_media_query_xxx_of +#### unnecessary_rebuilds_from_media_query - Target SDK: >= Flutter 3.10.0 (Dart 3.0.0) - Rule type: Practice diff --git a/packages/nilts/lib/nilts.dart b/packages/nilts/lib/nilts.dart index 12561ea..5d628a8 100644 --- a/packages/nilts/lib/nilts.dart +++ b/packages/nilts/lib/nilts.dart @@ -1,5 +1,5 @@ import 'package:custom_lint_builder/custom_lint_builder.dart'; -import 'package:nilts/src/lints/use_media_query_xxx_of.dart'; +import 'package:nilts/src/lints/unnecessary_rebuilds_from_media_query.dart'; /// custom_lint integrates the nilts's plugin from this method on /// `custom_lint_client.dart` which is generated by custom_lint CLI. @@ -9,6 +9,6 @@ PluginBase createPlugin() => _NiltsLint(); class _NiltsLint extends PluginBase { @override List getLintRules(CustomLintConfigs configs) => [ - const UseMediaQueryXxxOf(), + const UnnecessaryRebuildsFromMediaQuery(), ]; } diff --git a/packages/nilts/lib/src/lints/use_media_query_xxx_of.dart b/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart similarity index 95% rename from packages/nilts/lib/src/lints/use_media_query_xxx_of.dart rename to packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart index a17ba5d..b7bebeb 100644 --- a/packages/nilts/lib/src/lints/use_media_query_xxx_of.dart +++ b/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart @@ -6,7 +6,7 @@ import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'package:nilts/src/change_priority.dart'; import 'package:nilts/src/dart_version.dart'; -/// A class for `use_media_query_xxx_of` rule. +/// A class for `unnecessary_rebuilds_from_media_query` rule. /// /// This rule checks if /// `MediaQuery.of(context)` or `MediaQuery.maybeOf(context)` is used @@ -40,17 +40,18 @@ import 'package:nilts/src/dart_version.dart'; /// /// - [MediaQuery as InheritedModel by moffatman · Pull Request #114459 · flutter/flutter](https://github.com/flutter/flutter/pull/114459) /// - [MediaQuery class - widgets library - Dart API](https://api.flutter.dev/flutter/widgets/MediaQuery-class.html) -class UseMediaQueryXxxOf extends DartLintRule { +class UnnecessaryRebuildsFromMediaQuery extends DartLintRule { /// Create a new instance of UseMediaQueryXxxOf. - const UseMediaQueryXxxOf() : super(code: _code); + const UnnecessaryRebuildsFromMediaQuery() : super(code: _code); static const _code = LintCode( - name: 'use_media_query_xxx_of', + name: 'unnecessary_rebuilds_from_media_query', problemMessage: 'Prefer using ' 'MediaQuery.xxxOf(context) or MediaQuery.maybeXxxOf(context) ' 'instead of MediaQuery.of(context) or MediaQuery.maybeOf(context) ' 'to avoid unnecessary rebuilds.', - url: 'https://github.com/ronnnnn/nilts#use_media_query_xxx_of', + url: + 'https://github.com/ronnnnn/nilts#unnecessary_rebuilds_from_media_query', ); @override diff --git a/packages/nilts_test/test/lints/use_media_query_xxx_of.dart b/packages/nilts_test/test/lints/unnecessary_rebuilds_from_media_query.dart similarity index 57% rename from packages/nilts_test/test/lints/use_media_query_xxx_of.dart rename to packages/nilts_test/test/lints/unnecessary_rebuilds_from_media_query.dart index 440ec95..80db951 100644 --- a/packages/nilts_test/test/lints/use_media_query_xxx_of.dart +++ b/packages/nilts_test/test/lints/unnecessary_rebuilds_from_media_query.dart @@ -12,91 +12,91 @@ class MainApp extends StatelessWidget { @override Widget build(BuildContext context) { - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.of(context); - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context); - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final size = MediaQuery.of(context).size; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final nullableSize = MediaQuery.of(context)?.size; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeSize = MediaQuery.maybeOf(context)?.size; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final orientation = MediaQuery.of(context).orientation; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final devicePixelRatio = MediaQuery.of(context).devicePixelRatio; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final textScaleFactor = MediaQuery.of(context).textScaleFactor; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final platformBrightness = MediaQuery.of(context).platformBrightness; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final padding = MediaQuery.of(context).padding; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final viewInsets = MediaQuery.of(context).viewInsets; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final systemGestureInsets = MediaQuery.of(context).systemGestureInsets; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final viewPadding = MediaQuery.of(context).viewPadding; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final accessibleNavigation = MediaQuery.of(context).accessibleNavigation; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final invertColors = MediaQuery.of(context).invertColors; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final highContrast = MediaQuery.of(context).highContrast; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final disableAnimations = MediaQuery.of(context).disableAnimations; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final boldText = MediaQuery.of(context).boldText; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final navigationMode = MediaQuery.of(context).navigationMode; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final gestureSettings = MediaQuery.of(context).gestureSettings; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final displayFeatures = MediaQuery.of(context).displayFeatures; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeOrientation = MediaQuery.maybeOf(context)?.orientation; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeDevicePixelRatio = MediaQuery.maybeOf(context)?.devicePixelRatio; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeTextScaleFactor = MediaQuery.maybeOf(context)?.textScaleFactor; final maybePlatformBrightness = - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context)?.platformBrightness; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybePadding = MediaQuery.maybeOf(context)?.padding; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeViewInsets = MediaQuery.maybeOf(context)?.viewInsets; final maybeSystemGestureInsets = - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context)?.systemGestureInsets; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeViewPadding = MediaQuery.maybeOf(context)?.viewPadding; final maybeAlwaysUse24HourFormat = - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context)?.alwaysUse24HourFormat; final maybeAccessibleNavigation = - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context)?.accessibleNavigation; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeInvertColors = MediaQuery.maybeOf(context)?.invertColors; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeHighContrast = MediaQuery.maybeOf(context)?.highContrast; final maybeDisableAnimations = - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query MediaQuery.maybeOf(context)?.disableAnimations; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeBoldText = MediaQuery.maybeOf(context)?.boldText; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeNavigationMode = MediaQuery.maybeOf(context)?.navigationMode; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeGestureSettings = MediaQuery.maybeOf(context)?.gestureSettings; - // expect_lint: use_media_query_xxx_of + // expect_lint: unnecessary_rebuilds_from_media_query final maybeDisplayFeatures = MediaQuery.maybeOf(context)?.displayFeatures; return const MaterialApp(