From 348f3d79ec1200bebd5c892f783d1f4a48c4f14e Mon Sep 17 00:00:00 2001 From: ronnnnn Date: Sun, 16 Feb 2025 19:10:50 +0900 Subject: [PATCH] feat: nilts depends on nilts_core --- packages/nilts/lib/nilts.dart | 2 +- packages/nilts/lib/src/dart_version.dart | 217 ------------------ .../src/lints/fixed_text_scale_rich_text.dart | 2 +- .../lints/flaky_tests_with_set_up_all.dart | 2 +- .../no_support_multi_text_direction.dart | 2 +- .../src/lints/shrink_wrapped_scroll_view.dart | 2 +- ...unnecessary_rebuilds_from_media_query.dart | 3 +- .../lib/src/utils/library_element_ext.dart | 20 -- packages/nilts/pubspec.yaml | 3 +- 9 files changed, 8 insertions(+), 245 deletions(-) delete mode 100644 packages/nilts/lib/src/dart_version.dart delete mode 100644 packages/nilts/lib/src/utils/library_element_ext.dart diff --git a/packages/nilts/lib/nilts.dart b/packages/nilts/lib/nilts.dart index b0e4c30..db8339c 100644 --- a/packages/nilts/lib/nilts.dart +++ b/packages/nilts/lib/nilts.dart @@ -1,5 +1,4 @@ import 'package:custom_lint_builder/custom_lint_builder.dart'; -import 'package:nilts/src/dart_version.dart'; import 'package:nilts/src/lints/defined_async_callback_type.dart'; import 'package:nilts/src/lints/defined_async_value_getter_type.dart'; import 'package:nilts/src/lints/defined_async_value_setter_type.dart'; @@ -13,6 +12,7 @@ import 'package:nilts/src/lints/no_support_multi_text_direction.dart'; import 'package:nilts/src/lints/no_support_web_platform_check.dart'; import 'package:nilts/src/lints/shrink_wrapped_scroll_view.dart'; import 'package:nilts/src/lints/unnecessary_rebuilds_from_media_query.dart'; +import 'package:nilts_core/nilts_core.dart'; /// custom_lint integrates the nilts's plugin from this method on /// `custom_lint_client.dart` which is generated by custom_lint CLI. diff --git a/packages/nilts/lib/src/dart_version.dart b/packages/nilts/lib/src/dart_version.dart deleted file mode 100644 index 7730fdc..0000000 --- a/packages/nilts/lib/src/dart_version.dart +++ /dev/null @@ -1,217 +0,0 @@ -import 'dart:io'; - -import 'package:meta/meta.dart'; - -/// A class that represents the Dart version. -/// -/// The Dart versioning string from [Platform.version] is as follows: -/// -/// ```txt -/// // stable channel -/// 3.0.5 (stable) (Mon Jun 12 18:31:49 2023 +0000) on "macos_arm64" -/// // beta channel -/// 3.0.0-417.4.beta (beta) (Tue May 2 10:26:14 2023 +0000) on "macos_arm64" -/// // dev channel -/// 3.0.0-417.0.dev (dev) (Thu Apr 6 09:10:27 2023 -0700) on "macos_arm64" -/// ``` -/// -/// See also: -/// -/// - [Get the Dart SDK | Dart](https://dart.dev/get-dart#release-channels) -@immutable -class DartVersion { - /// Creates a new [DartVersion] instance. - const DartVersion({ - required this.major, - required this.minor, - required this.patch, - this.pre, - this.prePatch, - this.channel = DartReleaseChannel.stable, - }); - - /// Creates a new [DartVersion] instance from [Platform.version]. - factory DartVersion.fromPlatform() { - return DartVersion.fromString(Platform.version); - } - - /// Creates a new [DartVersion] instance from the given [version]. - factory DartVersion.fromString(String version) { - final pattern = RegExp( - r'^(?0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?0|[1-9]\d*)(-(?
0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?(beta|dev)?))?.*$',
-    );
-    final match = pattern.firstMatch(version);
-    if (match == null) {
-      throw ArgumentError('Invalid Dart versioning string');
-    }
-
-    final major = match.namedGroup('major');
-    final minor = match.namedGroup('minor');
-    final patch = match.namedGroup('patch');
-    final pre = match.namedGroup('pre');
-    final prePatch = match.namedGroup('prePatch');
-    final channelString = match.namedGroup('channel');
-
-    if (major == null || minor == null || patch == null) {
-      throw ArgumentError('Invalid Dart versioning string');
-    }
-    if (channelString != null &&
-        channelString != 'beta' &&
-        channelString != 'dev') {
-      throw ArgumentError('Invalid Dart versioning string');
-    }
-    if (channelString != null && (pre == null || prePatch == null)) {
-      throw ArgumentError('Invalid Dart versioning string');
-    }
-    if (channelString == null && (pre != null || prePatch != null)) {
-      throw ArgumentError('Invalid Dart versioning string');
-    }
-
-    final DartReleaseChannel channel;
-    switch (channelString) {
-      case 'dev':
-        channel = DartReleaseChannel.dev;
-      case 'beta':
-        channel = DartReleaseChannel.beta;
-      case null:
-        channel = DartReleaseChannel.stable;
-      default:
-        throw ArgumentError('Invalid Dart versioning string');
-    }
-
-    return DartVersion(
-      major: int.parse(major),
-      minor: int.parse(minor),
-      patch: int.parse(patch),
-      pre: pre == null ? null : int.parse(pre),
-      prePatch: prePatch == null ? null : int.parse(prePatch),
-      channel: channel,
-    );
-  }
-
-  /// The major version.
-  final int major;
-
-  /// The minor version.
-  final int minor;
-
-  /// The patch version.
-  final int patch;
-
-  /// The prerelease version.
-  final int? pre;
-
-  /// The prerelease patch version.
-  final int? prePatch;
-
-  /// The channel
-  final DartReleaseChannel channel;
-
-  /// Whether this version is stable.
-  bool get isStable => channel == DartReleaseChannel.stable;
-
-  /// Whether this version is beta.
-  bool get isBeta => channel == DartReleaseChannel.beta;
-
-  /// Whether this version is dev.
-  bool get isDev => channel == DartReleaseChannel.dev;
-
-  /// Whether this version is newer release than [other].
-  ///
-  /// Returns `1` if this version is newer than [other].
-  /// Returns `-1` if this version is older than [other].
-  /// Returns `0` if this version is same as [other].
-  int compareTo(DartVersion other) {
-    if (major != other.major) {
-      return major.compareTo(other.major);
-    }
-    if (minor != other.minor) {
-      return minor.compareTo(other.minor);
-    }
-    if (patch != other.patch) {
-      return patch.compareTo(other.patch);
-    }
-    if (channel != other.channel) {
-      if (isStable) {
-        return 1;
-      } else if (isBeta) {
-        if (other.isStable) {
-          return -1;
-        } else if (other.isDev) {
-          return 1;
-        }
-      } else if (isDev) {
-        if (other.isStable) {
-          return -1;
-        } else if (other.isBeta) {
-          return -1;
-        }
-      }
-    }
-    if (pre != other.pre) {
-      return pre!.compareTo(other.pre!);
-    }
-    if (prePatch != other.prePatch) {
-      return prePatch!.compareTo(other.prePatch!);
-    }
-    return 0;
-  }
-
-  @override
-  bool operator ==(Object other) =>
-      identical(this, other) ||
-      other is DartVersion &&
-          runtimeType == other.runtimeType &&
-          major == other.major &&
-          minor == other.minor &&
-          patch == other.patch &&
-          pre == other.pre &&
-          prePatch == other.prePatch &&
-          channel == other.channel;
-
-  @override
-  int get hashCode =>
-      major.hashCode ^
-      minor.hashCode ^
-      patch.hashCode ^
-      patch.hashCode ^
-      prePatch.hashCode ^
-      channel.hashCode;
-
-  /// Whether this version is older release than [other].
-  bool operator <(DartVersion other) => compareTo(other) < 0;
-
-  /// Whether this version is older or same release than [other].
-  bool operator <=(DartVersion other) => compareTo(other) <= 0;
-
-  /// Whether this version is newer release than [other].
-  bool operator >(DartVersion other) => compareTo(other) > 0;
-
-  /// Whether this version is newer or same release than [other].
-  bool operator >=(DartVersion other) => compareTo(other) >= 0;
-
-  @override
-  String toString() {
-    final mainVersion = '$major.$minor.$patch';
-    if (isStable) return mainVersion;
-
-    return '$mainVersion-$pre.$prePatch.$channel';
-  }
-}
-
-/// Enum of Dart release channel.
-///
-/// See also:
-///
-/// - [Get the Dart SDK | Dart](https://dart.dev/get-dart#release-channels)
-enum DartReleaseChannel {
-  /// Stable channel.
-  stable,
-
-  /// Beta channel.
-  beta,
-
-  /// Dev channel.
-  dev,
-  ;
-}
diff --git a/packages/nilts/lib/src/lints/fixed_text_scale_rich_text.dart b/packages/nilts/lib/src/lints/fixed_text_scale_rich_text.dart
index e30e65f..c03f267 100644
--- a/packages/nilts/lib/src/lints/fixed_text_scale_rich_text.dart
+++ b/packages/nilts/lib/src/lints/fixed_text_scale_rich_text.dart
@@ -5,7 +5,7 @@ import 'package:analyzer/error/error.dart' as analyzer;
 import 'package:analyzer/error/listener.dart';
 import 'package:custom_lint_builder/custom_lint_builder.dart';
 import 'package:nilts/src/change_priority.dart';
-import 'package:nilts/src/utils/library_element_ext.dart';
+import 'package:nilts_core/nilts_core.dart';
 
 /// A class for `fixed_text_scale_rich_text` rule.
 ///
diff --git a/packages/nilts/lib/src/lints/flaky_tests_with_set_up_all.dart b/packages/nilts/lib/src/lints/flaky_tests_with_set_up_all.dart
index 24ce37d..f5aa47a 100644
--- a/packages/nilts/lib/src/lints/flaky_tests_with_set_up_all.dart
+++ b/packages/nilts/lib/src/lints/flaky_tests_with_set_up_all.dart
@@ -7,7 +7,7 @@ import 'package:analyzer/error/listener.dart';
 import 'package:analyzer/source/source_range.dart';
 import 'package:custom_lint_builder/custom_lint_builder.dart';
 import 'package:nilts/src/change_priority.dart';
-import 'package:nilts/src/utils/library_element_ext.dart';
+import 'package:nilts_core/nilts_core.dart';
 
 /// A class for `flaky_tests_with_set_up_all` rule.
 ///
diff --git a/packages/nilts/lib/src/lints/no_support_multi_text_direction.dart b/packages/nilts/lib/src/lints/no_support_multi_text_direction.dart
index 706dd36..7424527 100644
--- a/packages/nilts/lib/src/lints/no_support_multi_text_direction.dart
+++ b/packages/nilts/lib/src/lints/no_support_multi_text_direction.dart
@@ -4,7 +4,7 @@ import 'package:analyzer/error/error.dart' as analyzer;
 import 'package:analyzer/error/listener.dart';
 import 'package:custom_lint_builder/custom_lint_builder.dart';
 import 'package:nilts/src/change_priority.dart';
-import 'package:nilts/src/utils/library_element_ext.dart';
+import 'package:nilts_core/nilts_core.dart';
 
 /// A class for `no_support_multi_text_direction` rule.
 ///
diff --git a/packages/nilts/lib/src/lints/shrink_wrapped_scroll_view.dart b/packages/nilts/lib/src/lints/shrink_wrapped_scroll_view.dart
index adb32d3..de61a43 100644
--- a/packages/nilts/lib/src/lints/shrink_wrapped_scroll_view.dart
+++ b/packages/nilts/lib/src/lints/shrink_wrapped_scroll_view.dart
@@ -5,7 +5,7 @@ import 'package:analyzer/error/error.dart' as analyzer;
 import 'package:analyzer/error/listener.dart';
 import 'package:custom_lint_builder/custom_lint_builder.dart';
 import 'package:nilts/src/change_priority.dart';
-import 'package:nilts/src/utils/library_element_ext.dart';
+import 'package:nilts_core/nilts_core.dart';
 
 /// A class for `shrink_wrapped_scroll_view` rule.
 ///
diff --git a/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart b/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart
index 103b7b3..1e7b8fc 100644
--- a/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart
+++ b/packages/nilts/lib/src/lints/unnecessary_rebuilds_from_media_query.dart
@@ -6,8 +6,7 @@ import 'package:analyzer/error/error.dart' as analyzer;
 import 'package:analyzer/error/listener.dart';
 import 'package:custom_lint_builder/custom_lint_builder.dart';
 import 'package:nilts/src/change_priority.dart';
-import 'package:nilts/src/dart_version.dart';
-import 'package:nilts/src/utils/library_element_ext.dart';
+import 'package:nilts_core/nilts_core.dart';
 
 /// A class for `unnecessary_rebuilds_from_media_query` rule.
 ///
diff --git a/packages/nilts/lib/src/utils/library_element_ext.dart b/packages/nilts/lib/src/utils/library_element_ext.dart
deleted file mode 100644
index f256f4f..0000000
--- a/packages/nilts/lib/src/utils/library_element_ext.dart
+++ /dev/null
@@ -1,20 +0,0 @@
-import 'package:analyzer/dart/element/element.dart';
-
-/// Extension methods for [LibraryElement].
-extension LibraryElementExt on LibraryElement {
-  /// Returns `true` if this library is from the package
-  /// with the given [packageName].
-  bool checkPackage({required String packageName}) {
-    final libraryUri = Uri.tryParse(identifier);
-    if (libraryUri == null) return false;
-    if (libraryUri.scheme != 'package') return false;
-    if (libraryUri.pathSegments.first != packageName) return false;
-    return true;
-  }
-
-  /// Returns `true` if this library is from the package `flutter`.
-  bool get isFlutter => checkPackage(packageName: 'flutter');
-
-  /// Returns `true` if this library is from the package `flutter_test`.
-  bool get isFlutterTest => checkPackage(packageName: 'flutter_test');
-}
diff --git a/packages/nilts/pubspec.yaml b/packages/nilts/pubspec.yaml
index 7233905..39fb637 100644
--- a/packages/nilts/pubspec.yaml
+++ b/packages/nilts/pubspec.yaml
@@ -27,10 +27,11 @@ environment:
   sdk: '>=3.0.0 <4.0.0'
 
 dependencies:
+  nilts_core: ^0.1.0
+
   analyzer: ^7.0.0
   analyzer_plugin: ^0.12.0
   custom_lint_builder: ^0.7.3
-  meta: ^1.9.1
 
 dev_dependencies:
   very_good_analysis: ^7.0.0