Skip to content

Commit

Permalink
refactor: use_media_query_xxx_of to unnecessary_rebuilds_from_media_q…
Browse files Browse the repository at this point in the history
…uery (#20)
  • Loading branch information
ronnnnn authored Jul 31, 2023
1 parent 537e584 commit c5d1260
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/nilts_example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions packages/nilts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.**
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/nilts/lib/nilts.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,6 +9,6 @@ PluginBase createPlugin() => _NiltsLint();
class _NiltsLint extends PluginBase {
@override
List<LintRule> getLintRules(CustomLintConfigs configs) => [
const UseMediaQueryXxxOf(),
const UnnecessaryRebuildsFromMediaQuery(),
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c5d1260

Please sign in to comment.