From 654b6a60e720fff13c1a5308e2b7c28cb801395c Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 5 Dec 2017 13:10:20 -0800 Subject: [PATCH] Add additional linst Split lints into 'error's and 'style' and sort within each section. Fix a few existing violations. --- analysis_options.yaml | 40 +++++++++++++++++++++++++---------- lib/src/builder.dart | 1 + lib/src/constants/revive.dart | 2 +- lib/src/constants/utils.dart | 2 +- lib/src/generated_output.dart | 2 +- lib/src/type_checker.dart | 2 +- lib/src/utils.dart | 2 +- test/src/io.dart | 4 +--- 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 848b33ff..ee533dab 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -6,33 +6,51 @@ analyzer: unused_import: error unused_local_variable: error dead_code: error + override_on_non_overriding_method: error linter: rules: - - annotate_overrides + # Errors - avoid_empty_else - - avoid_init_to_null - - avoid_return_types_on_setters - await_only_futures - - camel_case_types - comment_references - control_flow_in_finally + - empty_statements + - hash_and_equals + - iterable_contains_unrelated_type + - no_duplicate_case_values + - test_types_in_equals + - throw_in_finally + - unawaited_futures + - unnecessary_statements + - unrelated_type_equality_checks + - valid_regexps + + # Style + - annotate_overrides + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_unused_constructor_parameters + - camel_case_types - directives_ordering - empty_catches - empty_constructor_bodies - - empty_statements - - hash_and_equals - implementation_imports - library_names - library_prefixes - non_constant_identifier_names - only_throw_errors + - prefer_conditional_assignment - prefer_final_fields + - prefer_is_empty - prefer_is_not_empty - prefer_single_quotes + - prefer_typing_uninitialized_variables + - recursive_getters - slash_for_doc_comments - - test_types_in_equals - - test_types_in_equals - - throw_in_finally - type_init_formals - - unrelated_type_equality_checks - - valid_regexps + - unnecessary_brace_in_string_interps + - unnecessary_getter_setters + - unnecessary_lambda + - unnecessary_null_aware_assignments diff --git a/lib/src/builder.dart b/lib/src/builder.dart index c1fece7e..39da013c 100644 --- a/lib/src/builder.dart +++ b/lib/src/builder.dart @@ -146,6 +146,7 @@ class _Builder extends Builder { stack); } + // ignore: unawaited_futures buildStep.writeAsString(outputId, genPartContent); } } diff --git a/lib/src/constants/revive.dart b/lib/src/constants/revive.dart index 1dc18990..ac2d64ef 100644 --- a/lib/src/constants/revive.dart +++ b/lib/src/constants/revive.dart @@ -13,7 +13,7 @@ import '../utils.dart'; /// /// Optionally specify the [library] type that contains the reference. /// -/// Returns [null] if not revivable. +/// Returns `null` if not revivable. Revivable reviveInstance(DartObject object, [LibraryElement library]) { library ??= object.type.element.library; var url = Uri.parse(urlOfElement(object.type.element)); diff --git a/lib/src/constants/utils.dart b/lib/src/constants/utils.dart index d834cac2..53524b60 100644 --- a/lib/src/constants/utils.dart +++ b/lib/src/constants/utils.dart @@ -20,7 +20,7 @@ void assertHasField(ClassElement root, String name) { element = element.supertype?.element; } final allFields = root.fields.toSet(); - root.allSupertypes.forEach((t) => allFields.addAll(t.element.fields)); + allFields.addAll(root.allSupertypes.expand((t) => t.element.fields)); throw new FormatException( 'Class ${root.name} does not have field "$name".', 'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}', diff --git a/lib/src/generated_output.dart b/lib/src/generated_output.dart index 4657d870..a4e59cdf 100644 --- a/lib/src/generated_output.dart +++ b/lib/src/generated_output.dart @@ -9,7 +9,7 @@ import 'generator.dart'; class GeneratedOutput { final String output; final Generator generator; - final error; + final dynamic error; final StackTrace stackTrace; bool get isError => error != null; diff --git a/lib/src/type_checker.dart b/lib/src/type_checker.dart index b3fa6093..b0c31fd2 100644 --- a/lib/src/type_checker.dart +++ b/lib/src/type_checker.dart @@ -253,7 +253,7 @@ class _UriTypeChecker extends TypeChecker { bool isExactly(Element element) => hasSameUrl(urlOfElement(element)); @override - String toString() => '${uri}'; + String toString() => '$uri'; } class _AnyChecker extends TypeChecker { diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 9f7dcfd8..fa314f21 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -136,7 +136,7 @@ Uri packageToAssetUrl(Uri url) => url.scheme == 'package' /// are not describable using `package:...`, such as files in the `bin`, `tool`, /// `web`, or even root directory of a package - `asset:some_lib/web/main.dart`. Uri assetToPackageUrl(Uri url) => url.scheme == 'asset' && - url.pathSegments.length >= 1 && + url.pathSegments.isNotEmpty && url.pathSegments[1] == 'lib' ? url.replace( scheme: 'package', diff --git a/test/src/io.dart b/test/src/io.dart index 00412ba3..fff5b983 100644 --- a/test/src/io.dart +++ b/test/src/io.dart @@ -29,9 +29,7 @@ Future> getDartFiles(String directoryPath, /// directories defined in the list. Stream getFiles(String directoryPath, {List searchList, bool followLinks: false}) async* { - if (searchList == null) { - searchList = []; - } + searchList ??= []; var map = await _expandSearchList(directoryPath, searchList); var searchDirs = [];