Skip to content

Commit

Permalink
refactor: replace to flutter_lints (#137)
Browse files Browse the repository at this point in the history
* refactor: change to flutter_lints

* style: fix surround symbol
  • Loading branch information
wasabeef authored Oct 19, 2021
1 parent 66ba708 commit e8927c0
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 124 deletions.
2 changes: 1 addition & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:effective_dart/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

linter:
rules:
Expand Down
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Auto generated image from FlutterGen.
Container(
SizedBox(
width: 200,
height: 200,
child: Assets.flare.penguin.flare(
Expand All @@ -32,14 +32,14 @@ void main() {
),
),
Image(image: Assets.images.chip1),
Assets.images.icons.kmm.svg(key: Key("kmm_svg")),
Assets.images.icons.kmm.svg(key: const Key("kmm_svg")),
Assets.images.icons.fuchsia.svg(),
Assets.images.icons.paint.svg(
width: 120,
height: 120,
),
Assets.pictures.chip5.image(
key: Key("chip5"),
key: const Key("chip5"),
width: 120,
height: 120,
fit: BoxFit.scaleDown,
Expand Down
21 changes: 14 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.1"
effective_dart:
dependency: "direct dev"
description:
name: effective_dart
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -230,6 +223,13 @@ packages:
relative: true
source: path
version: "4.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_svg:
dependency: "direct main"
description:
Expand Down Expand Up @@ -298,6 +298,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
logging:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dev_dependencies:
flutter_gen_runner:
path: ../packages/runner

effective_dart: '>=1.3.1 <2.0.0'
flutter_lints: '>=1.0.4 < 2.0.0'

flutter_gen:
output: lib/gen/ # Optional (default: lib/gen/)
Expand Down
2 changes: 1 addition & 1 deletion packages/command/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:effective_dart/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

linter:
rules:
Expand Down
1 change: 1 addition & 0 deletions packages/command/bin/flutter_gen_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void main(List<String> args) {
try {
results = parser.parse(args);
if (results.wasParsed('help')) {
// ignore: avoid_print
print(parser.usage);
return;
}
Expand Down
21 changes: 14 additions & 7 deletions packages/command/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.1"
effective_dart:
dependency: "direct dev"
description:
name: effective_dart
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
file:
dependency: transitive
description:
Expand All @@ -113,6 +106,13 @@ packages:
relative: true
source: path
version: "4.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
glob:
dependency: transitive
description:
Expand All @@ -127,6 +127,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
meta:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/command/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
args: '>=2.0.0 <3.0.0'

dev_dependencies:
effective_dart: '>=1.3.1 <2.0.0'
flutter_lints: '>=1.0.4 < 2.0.0'

# TODO: When publish to pub.dev, disabled the dependencies_override
dependency_overrides:
Expand Down
2 changes: 1 addition & 1 deletion packages/core/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:effective_dart/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
Expand Down
2 changes: 2 additions & 0 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: avoid_print

import 'dart:io';

import 'package:dart_style/dart_style.dart';
Expand Down
8 changes: 4 additions & 4 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ String generateAssets(
DartFormatter formatter,
) {
if (config.assets.isEmpty) {
throw InvalidSettingsException(
throw const InvalidSettingsException(
'The value of "flutter/assets:" is incorrect.');
}

Expand Down Expand Up @@ -148,15 +148,15 @@ _Statement? _createAssetTypeStatement(
return _Statement(
type: 'AssetGenImage',
name: name,
value: 'AssetGenImage\(\'${posixStyle(assetType.path)}\'\)',
value: 'AssetGenImage(\'${posixStyle(assetType.path)}\')',
isConstConstructor: true,
);
} else if (FileSystemEntity.isDirectorySync(childAssetAbsolutePath)) {
final childClassName = '\$${assetType.path.camelCase().capitalize()}Gen';
return _Statement(
type: childClassName,
name: name,
value: '$childClassName\(\)',
value: '$childClassName()',
isConstConstructor: true,
);
} else if (!assetType.isIgnoreFile) {
Expand Down Expand Up @@ -227,7 +227,7 @@ String _dotDelimiterStyleDefinition(
assetsStaticStatements.add(_Statement(
type: className,
name: assetType.baseName.camelCase(),
value: '$className\(\)',
value: '$className()',
isConstConstructor: true,
));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ String generateColors(
FlutterGenColors colors,
) {
if (colors.inputs.isEmpty) {
throw InvalidSettingsException(
throw const InvalidSettingsException(
'The value of "flutter_gen/colors:" is incorrect.');
}

Expand Down
5 changes: 3 additions & 2 deletions packages/core/lib/generators/fonts_generator.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: prefer_const_constructors

import 'package:dart_style/dart_style.dart';
import 'package:dartx/dartx.dart';

Expand All @@ -23,8 +25,7 @@ String generateFonts(
buffer.writeln();

fonts.map((element) => element.family).distinct().sorted().forEach((family) {
buffer
.writeln(" static const String ${family.camelCase()} = \'$family\';");
buffer.writeln(" static const String ${family.camelCase()} = '$family';");
});

buffer.writeln('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FlareIntegration extends Integration {
String get className => 'FlareGenImage';

@override
String classInstantiate(String path) => 'FlareGenImage\(\'$path\'\)';
String classInstantiate(String path) => 'FlareGenImage(\'$path\')';

@override
bool isSupport(AssetType type) => type.extension == '.flr';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SvgIntegration extends Integration {
String get className => 'SvgGenImage';

@override
String classInstantiate(String path) => 'SvgGenImage\(\'$path\'\)';
String classInstantiate(String path) => 'SvgGenImage(\'$path\')';

@override
bool isSupport(AssetType type) => type.mime == 'image/svg+xml';
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Config {
}

Future<Config> loadPubspecConfig(File pubspecFile) async {
// ignore: avoid_print
print('FlutterGen Loading ... '
'${normalize(join(
basename(pubspecFile.parent.path),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/utils/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _copyValues<K, V>(
Map<K, V> from, Map<K, V> to, bool recursive, bool acceptNull) {
for (var key in from.keys) {
if (from[key] is Map<K, V> && recursive) {
if (!(to[key] is Map<K, V>)) {
if (to[key] is! Map<K, V>) {
to[key] = <K, V>{} as V;
}
_copyValues(from[key] as Map, to[key] as Map, recursive, acceptNull);
Expand Down
21 changes: 14 additions & 7 deletions packages/core/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.1"
effective_dart:
dependency: "direct dev"
description:
name: effective_dart
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
file:
dependency: transitive
description:
Expand All @@ -197,6 +190,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
frontend_server_client:
dependency: transitive
description:
Expand Down Expand Up @@ -260,6 +260,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
logging:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ dependencies:

dev_dependencies:
test: '>=1.16.0 <2.0.0'
effective_dart: '>=1.3.1 <2.0.0'
flutter_lints: '>=1.0.4 < 2.0.0'
build_runner: '>=2.0.0 <3.0.0'
json_serializable: '>=5.0.0 <6.0.0'
22 changes: 11 additions & 11 deletions packages/core/test/assets_gen_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@ import 'gen_test_helper.dart';
void main() {
group('Test Assets Integration generator', () {
test('Assets with No integrations on pubspec.yaml', () async {
final pubspec = 'test_resources/pubspec_assets_no_integrations.yaml';
final fact = 'test_resources/actual_data/assets_no_integrations.gen.dart';
final generated =
const pubspec = 'test_resources/pubspec_assets_no_integrations.yaml';
const fact = 'test_resources/actual_data/assets_no_integrations.gen.dart';
const generated =
'test_resources/lib/gen/assets_no_integrations.gen.dart';

await expectedAssetsGen(pubspec, generated, fact);
});

test('Assets with Svg integrations on pubspec.yaml', () async {
final pubspec = 'test_resources/pubspec_assets_svg_integrations.yaml';
final fact =
const pubspec = 'test_resources/pubspec_assets_svg_integrations.yaml';
const fact =
'test_resources/actual_data/assets_svg_integrations.gen.dart';
final generated =
const generated =
'test_resources/lib/gen/assets_svg_integrations.gen.dart';

await expectedAssetsGen(pubspec, generated, fact);

final integration = SvgIntegration('package_name');
expect(integration.className, 'SvgGenImage');
expect(integration.classInstantiate('assets/path'),
'SvgGenImage\(\'assets/path\'\)');
'SvgGenImage(\'assets/path\')');
expect(integration.isSupport(AssetType('assets/path/dog.svg')), isTrue);
expect(integration.isSupport(AssetType('assets/path/dog.png')), isFalse);
expect(integration.isConstConstructor, isTrue);
});

test('Assets with Flare integrations on pubspec.yaml', () async {
final pubspec = 'test_resources/pubspec_assets_flare_integrations.yaml';
final fact =
const pubspec = 'test_resources/pubspec_assets_flare_integrations.yaml';
const fact =
'test_resources/actual_data/assets_flare_integrations.gen.dart';
final generated =
const generated =
'test_resources/lib/gen/assets_flare_integrations.gen.dart';

await expectedAssetsGen(pubspec, generated, fact);

final integration = FlareIntegration();
expect(integration.className, 'FlareGenImage');
expect(integration.classInstantiate('assets/path'),
'FlareGenImage\(\'assets/path\'\)');
'FlareGenImage(\'assets/path\')');
expect(integration.isSupport(AssetType('assets/path/dog.flr')), isTrue);
expect(integration.isSupport(AssetType('assets/path/dog.json')), isFalse);
expect(integration.isConstConstructor, isTrue);
Expand Down
Loading

0 comments on commit e8927c0

Please sign in to comment.