Skip to content

Commit

Permalink
Update analysis options
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed Jun 18, 2022
1 parent 96aa4dc commit cf1305d
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 222 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.1

- Code refactor

## 3.0.0

- Update to Flutter 3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

URL preview extracted from the provided text with basic customization and ability to render from cached data.

<img src="https://user-images.githubusercontent.com/14123304/117151394-5285fd80-adb9-11eb-857b-3c21558ecd24.png" width="428" height="926">
<img src="https://user-images.githubusercontent.com/14123304/174437317-4f3c6a90-4639-4b4a-80e3-9df955ab0e34.png" width="428" height="926">

## Getting Started

Expand Down
39 changes: 39 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
analyzer:
plugins:
- dart_code_metrics

# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
Expand All @@ -24,7 +28,42 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
- always_declare_return_types
- avoid_unused_constructor_parameters
- directives_ordering
- omit_local_variable_types
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sized_box_for_whitespace
- sort_child_properties_last
- sort_pub_dependencies
- type_annotate_public_apis
- unawaited_futures
- use_named_constants
- use_super_parameters

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

dart_code_metrics:
rules:
- always-remove-listener
- avoid-unused-parameters
- format-comment
- member-ordering:
alphabetize: false
order:
- constructors
- public-fields
- public-getters
- public-setters
- private-fields
- private-getters
- private-setters
- public-methods
- private-methods
- no-boolean-literal-compare
- prefer-trailing-comma
39 changes: 39 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
analyzer:
plugins:
- dart_code_metrics

# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
Expand All @@ -24,7 +28,42 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
- always_declare_return_types
- avoid_unused_constructor_parameters
- directives_ordering
- omit_local_variable_types
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sized_box_for_whitespace
- sort_child_properties_last
- sort_pub_dependencies
- type_annotate_public_apis
- unawaited_futures
- use_named_constants
- use_super_parameters

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

dart_code_metrics:
rules:
- always-remove-listener
- avoid-unused-parameters
- format-comment
- member-ordering:
alphabetize: false
order:
- constructors
- public-fields
- public-getters
- public-setters
- private-fields
- private-getters
- private-setters
- public-methods
- private-methods
- no-boolean-literal-compare
- prefer-trailing-comma
10 changes: 4 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ class MyApp extends StatelessWidget {

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
Widget build(BuildContext context) => const MaterialApp(
home: MyHomePage(),
);
}

class MyHomePage extends StatefulWidget {
Expand All @@ -30,8 +28,8 @@ class _MyHomePageState extends State<MyHomePage> {
Map<String, PreviewData> datas = {};

List<String> get urls => const [
'https://flyer.chat',
'github.com/flyerhq',
'https://thereverseland.com',
];

@override
Expand Down
12 changes: 5 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ environment:
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
flutter:
sdk: flutter
flutter_chat_types: ^3.4.1
flutter_link_previewer:
path: ../

dev_dependencies:
flutter_test:
sdk: flutter

dart_code_metrics: ^4.15.2
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
8 changes: 4 additions & 4 deletions lib/src/types.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:meta/meta.dart';

/// Represents the size object
/// Represents the size object.
@immutable
class Size {
/// Creates [Size] from width and height
/// Creates [Size] from width and height.
const Size({
required this.height,
required this.width,
});

/// Height
/// Height.
final double height;

/// Width
/// Width.
final double width;
}
24 changes: 13 additions & 11 deletions lib/src/url_linkifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ final _protocolIdentifierRegex = RegExp(
/// Utility class that implements [Linkifier.parse] method.
/// Used to find links in the text.
class UrlLinkifier extends Linkifier {
/// Default constructor
/// Default constructor.
const UrlLinkifier();

/// Parses text to find all links inside it
/// Parses text to find all links inside it.
@override
List<LinkifyElement> parse(elements, options) {
List<LinkifyElement> parse(
List<LinkifyElement> elements,
LinkifyOptions options,
) {
final list = <LinkifyElement>[];

for (final element in elements) {
Expand Down Expand Up @@ -98,24 +101,23 @@ class UrlLinkifier extends Linkifier {
}
}

/// Represents an element containing a link
/// Represents an element containing a link.
@immutable
class UrlElement extends LinkableElement {
/// Creates [UrlElement]
/// Creates [UrlElement].
UrlElement(String url, [String? text]) : super(text, url);

@override
String toString() {
return "LinkElement: '$url' ($text)";
}
// ignore: unnecessary_overrides
int get hashCode => super.hashCode;

@override
bool operator ==(other) => equals(other);
bool operator ==(Object other) => equals(other);

@override
// ignore: type_annotate_public_apis
bool equals(other) => other is UrlElement && super.equals(other);

@override
// ignore: unnecessary_overrides
int get hashCode => super.hashCode;
String toString() => "LinkElement: '$url' ($text)";
}
21 changes: 10 additions & 11 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ String? _getTitle(Document document) {
_getMetaContent(document, 'og:site_name');
}

String? _getDescription(Document document) {
return _getMetaContent(document, 'og:description') ??
_getMetaContent(document, 'description') ??
_getMetaContent(document, 'twitter:description');
}
String? _getDescription(Document document) =>
_getMetaContent(document, 'og:description') ??
_getMetaContent(document, 'description') ??
_getMetaContent(document, 'twitter:description');

List<String> _getImageUrls(Document document, String baseUrl) {
final meta = document.getElementsByTagName('meta');
Expand Down Expand Up @@ -112,11 +111,11 @@ Future<Size> _getImageSize(String url) {
final stream = Image.network(url).image.resolve(ImageConfiguration.empty);
late ImageStreamListener streamListener;

onError(Object error, StackTrace? stackTrace) {
void onError(Object error, StackTrace? stackTrace) {
completer.completeError(error, stackTrace);
}

listener(ImageInfo info, bool _) {
void listener(ImageInfo info, bool _) {
if (!completer.isCompleted) {
completer.complete(
Size(
Expand Down Expand Up @@ -157,7 +156,7 @@ Future<String> _getBiggestImageUrl(
return currentUrl;
}

/// Parses provided text and returns [PreviewData] for the first found link
/// Parses provided text and returns [PreviewData] for the first found link.
Future<PreviewData> getPreviewData(
String text, {
String? proxy,
Expand Down Expand Up @@ -260,12 +259,12 @@ Future<PreviewData> getPreviewData(
}
}

/// Regex to check if text is email
/// Regex to check if text is email.
const regexEmail = r'([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)';

/// Regex to check if content type is an image
/// Regex to check if content type is an image.
const regexImageContentType = r'image\/*';

/// Regex to find all links in the text
/// Regex to find all links in the text.
const regexLink =
r'((http|ftp|https):\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?';
Loading

0 comments on commit cf1305d

Please sign in to comment.