Skip to content

Commit

Permalink
#5 Fixed the literals & strictmode & fixed the nullsafe boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Mar 26, 2021
1 parent ac4f6a7 commit 7e36743
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 71 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.2.0] - 2021-03-26
### Added
-

## [1.1.1] - 2021-03-07
### Fixed
-Required url in License object
Expand Down
7 changes: 5 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ analyzer:
missing_return: error
todo: ignore
sdk_version_async_exported_from_core: ignore
strong-mode:
implicit-casts: false
implicit-dynamic: false
exclude:
- '**.g.dart'

linter:
rules:
- prefer_collection_literals
# - avoid_print
- always_put_required_named_parameters_first
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_annotating_with_dynamic
- avoid_as
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
Expand Down Expand Up @@ -101,7 +105,6 @@ linter:
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- recursive_getters
- slash_for_doc_comments
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
Expand Down
23 changes: 17 additions & 6 deletions bin/icapps_license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ Future<void> main(List<String> args) async {
..writeln(' final String licenseUrl;')
..writeln(' final String license;')
..writeln()
..writeln(' License({')
..writeln(' required this.name,')
..writeln(' required this.version,')
..writeln(' required this.licenseUrl,')
..writeln(' required this.license,')
..writeln(' required this.url,')
..writeln(' License({');
if (params.nullSafe) {
sb
..writeln(' required this.name,')
..writeln(' required this.version,')
..writeln(' required this.licenseUrl,')
..writeln(' required this.license,')
..writeln(' required this.url,');
} else {
sb
..writeln(' this.name,')
..writeln(' this.version,')
..writeln(' this.licenseUrl,')
..writeln(' this.license,')
..writeln(' this.url,');
}
sb
..writeln(' });')
..writeln('}')
..writeln()
Expand Down
2 changes: 1 addition & 1 deletion bin/src/model/webservice/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Package {
}

Map<String, dynamic> toJson() {
return {
return <String, dynamic>{
'pubspec': pubspec,
};
}
Expand Down
2 changes: 1 addition & 1 deletion bin/src/model/webservice/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PubSpec {
}

Map<String, dynamic> toJson() {
return {
return <String, dynamic>{
'name': name,
'version': version,
'homepage': homepage,
Expand Down
41 changes: 24 additions & 17 deletions bin/src/params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,47 @@ class Params {
final dependencies = <Dependency>[];
final devDependencies = <Dependency>[];

Future<void> init(pubspecContent) async {
final config = loadYaml(pubspecContent);
final projectName = config['name'];
Future<void> init(String pubspecContent) async {
final config = loadYaml(pubspecContent) as YamlMap; // ignore: avoid_as
final projectName = config['name'] as String?; // ignore: avoid_as

if (projectName == null || projectName.isEmpty) {
throw Exception(
'Could not parse the pubspec.yaml, project name not found');
}

final YamlMap? icappsLicenseConfig = config[yamlConfigLicense];
final icappsLicenseConfig =
config[yamlConfigLicense] as YamlMap?; // ignore: avoid_as

if (icappsLicenseConfig != null) {
failFast = icappsLicenseConfig[yamlConfigFailFast] == true;
nullSafe = icappsLicenseConfig[yamlConfigNullSafety] == true;
}

final YamlMap? dependenciesYamlList = config['dependencies'];
final dependenciesYamlList =
config['dependencies'] as YamlMap?; // ignore: avoid_as
if (dependenciesYamlList != null && dependenciesYamlList.isNotEmpty) {
for (final key in dependenciesYamlList.keys) {
final value = dependenciesYamlList[key];
final stringKey = key as String; // ignore: avoid_as
final value = dependenciesYamlList[key] as Object; // ignore: avoid_as
final dependency = await _getDependency(
key, value, _getOverrideLicenseUrl(icappsLicenseConfig, key));
stringKey, value, _getOverrideLicenseUrl(icappsLicenseConfig, key));
if (dependency != null) {
dependencies.add(dependency);
}
}
}

final YamlMap? devDependenciesYamlList = config['dev_dependencies'];
final devDependenciesYamlList =
config['dev_dependencies'] as YamlMap?; // ignore: avoid_as
if (devDependenciesYamlList != null && devDependenciesYamlList.isNotEmpty) {
for (final key in devDependenciesYamlList.keys) {
final value = devDependenciesYamlList[key];
final stringKey = key as String; // ignore: avoid_as
final value =
devDependenciesYamlList[key] as Object; // ignore: avoid_as
final dependency = await _getDependency(
key, value, _getOverrideLicenseUrl(icappsLicenseConfig, key));
stringKey, value, _getOverrideLicenseUrl(icappsLicenseConfig, key));

if (dependency != null) {
devDependencies.add(dependency);
}
Expand All @@ -74,15 +81,14 @@ class Params {

String? _getOverrideLicenseUrl(YamlMap? icappsLicenseConfig, String name) {
if (icappsLicenseConfig == null) return null;
final YamlMap? overrideLicenseMap =
icappsLicenseConfig[yamlConfigLicensesList];
final overrideLicenseMap = icappsLicenseConfig[yamlConfigLicensesList]
as YamlMap?; // ignore: avoid_as
if (overrideLicenseMap == null) return null;
return overrideLicenseMap[name];
return overrideLicenseMap[name] as String?; // ignore: avoid_as
}

Future<Dependency?> _getDependency(
String name, value, String? overrideLicense) async {
String version;
String name, Object value, String? overrideLicense) async {
if (value is YamlMap) {
if (value.containsKey('sdk') && value['sdk'] == 'flutter') {
print('$name is part of flutter itself.');
Expand All @@ -102,7 +108,7 @@ class Params {
print('----');
return null;
}
version = value;
final version = value;

final apiUrl =
baseUrl + name + urlVersionPath + version.replaceFirst('^', '');
Expand All @@ -115,7 +121,8 @@ class Params {
print('----');
return null;
}
final jsonObj = json.decode(result.body);
final jsonObj =
json.decode(result.body) as Map<String, dynamic>; // ignore: avoid_as
final package = Package.fromJson(jsonObj);
String? licenseUrl;
if (overrideLicense == null) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/util/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SOFTWARE.''',
'https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences',
licenseUrl:
'https://raw.githubusercontent.com/flutter/plugins/master/packages/shared_preferences/shared_preferences/LICENSE',
license: '''Copyright 2017 The Chromium Authors. All rights reserved.
license: '''Copyright 2013 The Flutter Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.0"
version: "0.13.1"
http_parser:
dependency: transitive
description:
Expand All @@ -104,7 +104,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.8"
version: "1.2.0"
intl:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ flutter:
- assets/locale/

icapps_license:
failFast: true
# failFast: true
nullsafety: false
licenses:
icapps_license: 'https://raw.githubusercontent.com/icapps/flutter-icapps-license/master/LICENSE'
Loading

0 comments on commit 7e36743

Please sign in to comment.