Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: support flutter 3.16 dart 3.2 #59

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dart 3.1.5
flutter 3.13.9-stable
dart 3.2.0
flutter 3.16.0-stable
28 changes: 19 additions & 9 deletions packages/nilts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ Some of lint rules support quick fixes on IDE.

### Overview

| Rule name | Overview | Target SDK | Rule type | Maturity level | Quick fix |
| :-- | :-- | :--: | :--: | :--: | :--: |
| [defined\_void\_callback\_type](#defined_void_callback_type) | Checks `void Function()` definitions. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [fixed\_text\_scale\_factor\_rich\_text](#fixed_text_scale_factor_rich_text) | Checks usage of `textScaleFactor` in `RichText` constructor. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [flaky\_tests\_with\_set\_up\_all](#flaky_tests_with_set_up_all) | Checks `setUpAll` usages. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [shrink\_wrapped\_scroll\_view](#shrink_wrapped_scroll_view) | Checks the content of the scroll view is shrink wrapped. | Any versions nilts supports | 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 | ✅️ |
| Rule name | Overview | Target SDK | Rule type | Maturity level | Quick fix |
|:------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------|:------------------------------:| :--: |:--------------:| :--: |
| [defined\_void\_callback\_type](#defined_void_callback_type) | Checks `void Function()` definitions. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [fixed\_text\_scale\_rich\_text](#fixed_text_scale_rich_text) | Checks usage of `textScaler` or `textScaleFactor` in `RichText` constructor. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [flaky\_tests\_with\_set\_up\_all](#flaky_tests_with_set_up_all) | Checks `setUpAll` usages. | Any versions nilts supports | Practice | Experimental | ✅️ |
| [shrink\_wrapped\_scroll\_view](#shrink_wrapped_scroll_view) | Checks the content of the scroll view is shrink wrapped. | Any versions nilts supports | 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

Expand All @@ -118,14 +118,14 @@ final void Function() callback;
final VoidCallback callback;
```

#### fixed_text_scale_factor_rich_text
#### fixed_text_scale_rich_text

- Target SDK: Any versions nilts supports
- Rule type: Practice
- Maturity level: Experimental
- Quick fix: ✅

**Consider** adding `textScaleFactor` argument to `RichText` constructor to make the text size responsive for user setting.
**Consider** adding `textScaler` or `textScaleFactor` (deprecated on Flutter 3.16.0 and above) argument to [RichText] constructor to make the text size responsive for user setting.

**BAD:**
```dart
Expand All @@ -138,6 +138,16 @@ RichText(

**GOOD:**
```dart
RichText(
text: TextSpan(
text: 'Hello, world!',
),
textScaler: MediaQuery.textScalerOf(context),
)
```

**GOOD (deprecated on Flutter 3.16.0 and above):**
```dart
RichText(
text: TextSpan(
text: 'Hello, world!',
Expand Down
13 changes: 10 additions & 3 deletions packages/nilts/lib/nilts.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:custom_lint_builder/custom_lint_builder.dart';
import 'package:nilts/src/dart_version.dart';
import 'package:nilts/src/lints/defined_void_callback_type.dart';
import 'package:nilts/src/lints/fixed_text_scale_factor_rich_text.dart';
import 'package:nilts/src/lints/fixed_text_scale_rich_text.dart';
import 'package:nilts/src/lints/flaky_tests_with_set_up_all.dart';
import 'package:nilts/src/lints/shrink_wrapped_scroll_view.dart';
import 'package:nilts/src/lints/unnecessary_rebuilds_from_media_query.dart';
Expand All @@ -11,12 +12,18 @@ PluginBase createPlugin() => _NiltsLint();

/// A class for defining all lint rules and assists managed by nilts.
class _NiltsLint extends PluginBase {
final _dartVersion = DartVersion.fromPlatform();

@override
List<LintRule> getLintRules(CustomLintConfigs configs) => [
const DefinedVoidCallbackType(),
const FixedTextScaleFactorRichText(),
if (_dartVersion >= const DartVersion(major: 3, minor: 2, patch: 0))
const FixedTextScaleRichText()
else
const FixedTextScaleRichTextLegacy(),
const FlakyTestsWithSetUpAll(),
const ShrinkWrappedScrollView(),
const UnnecessaryRebuildsFromMediaQuery(),
if (_dartVersion >= const DartVersion(major: 3, minor: 0, patch: 0))
UnnecessaryRebuildsFromMediaQuery(_dartVersion),
Comment on lines +15 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The changes made here are good, but there's a potential issue. The DartVersion comparison in the conditional statements (lines 20 and 26) might not work as expected if the Dart version has a pre-release suffix like 3.2.0-beta.1. It would be better to use a method that compares only the major, minor, and patch versions without considering the pre-release suffix.

- if (_dartVersion >= const DartVersion(major: 3, minor: 2, patch: 0))
+ if (_dartVersion.isAtLeast(const DartVersion(major: 3, minor: 2, patch: 0)))

- if (_dartVersion >= const DartVersion(major: 3, minor: 0, patch: 0))
+ if (_dartVersion.isAtLeast(const DartVersion(major: 3, minor: 0, patch: 0)))

In the DartVersion class, you can add a new method isAtLeast:

bool isAtLeast(DartVersion other) {
  return this.major > other.major ||
      (this.major == other.major && this.minor > other.minor) ||
      (this.major == other.major && this.minor == other.minor && this.patch >= other.patch);
}

This will ensure that the comparison works correctly even when the Dart version has a pre-release suffix.

];
}
3 changes: 3 additions & 0 deletions packages/nilts/lib/src/change_priority.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class ChangePriority {
/// The priority for [_AddTextScaleFactor].
static const int addTextScaleFactor = 100;

/// The priority for [_AddTextScaler].
static const int addTextScaler = 100;

/// The priority for [_RemoveShrinkWrap].
static const int removeShrinkWrap = 100;

Expand Down
119 changes: 0 additions & 119 deletions packages/nilts/lib/src/lints/fixed_text_scale_factor_rich_text.dart

This file was deleted.

Loading
Loading