diff --git a/_test/pubspec.yaml b/_test/pubspec.yaml index 469c22d66..8c694cd7a 100644 --- a/_test/pubspec.yaml +++ b/_test/pubspec.yaml @@ -14,7 +14,7 @@ dev_dependencies: build_runner: any build_runner_core: any build_test: any - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' io: ^1.0.0 path: ^1.8.0 provides_builder: diff --git a/_test/test/goldens/generated_build_script.dart b/_test/test/goldens/generated_build_script.dart index 0886d9eda..c86d0b078 100644 --- a/_test/test/goldens/generated_build_script.dart +++ b/_test/test/goldens/generated_build_script.dart @@ -1,4 +1,5 @@ // ignore_for_file: directives_ordering +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:build_runner_core/build_runner_core.dart' as _i1; import 'package:build_test/builder.dart' as _i2; import 'package:build_config/build_config.dart' as _i3; diff --git a/_test_common/pubspec.yaml b/_test_common/pubspec.yaml index 99ea7caa9..a2af40f54 100644 --- a/_test_common/pubspec.yaml +++ b/_test_common/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: watcher: ^1.0.0 dev_dependencies: - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' dependency_overrides: build: diff --git a/_test_null_safety/pubspec.yaml b/_test_null_safety/pubspec.yaml index c2939b967..f4f38e341 100644 --- a/_test_null_safety/pubspec.yaml +++ b/_test_null_safety/pubspec.yaml @@ -6,7 +6,7 @@ environment: dev_dependencies: js: ^0.6.3 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 build_runner: any build_test: any diff --git a/_test_null_safety/test/common/message.dart b/_test_null_safety/test/common/message.dart index 030a0ff84..90d7d86e6 100644 --- a/_test_null_safety/test/common/message.dart +++ b/_test_null_safety/test/common/message.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. // Uses `?` to ensure null safety is enabled +// ignore: unnecessary_nullable_for_final_variable_declarations final String? message = 'hello'; // Used in null assertion tests. diff --git a/analysis_options.yaml b/analysis_options.yaml index d227c9a99..45f53c48a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -17,87 +17,24 @@ analyzer: linter: rules: - - always_declare_return_types - - always_require_non_null_named_parameters - - annotate_overrides - - avoid_bool_literals_in_conditional_expressions - - avoid_classes_with_only_static_members - - avoid_empty_else - - avoid_function_literals_in_foreach_calls - - avoid_init_to_null - - avoid_null_checks_in_equality_operators - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - - avoid_returning_null_for_void - - avoid_returning_this - - avoid_shadowing_type_parameters - - avoid_single_cascade_in_expression_statements - - avoid_types_as_parameter_names - - avoid_unused_constructor_parameters - - await_only_futures - - camel_case_extensions - - camel_case_types - - cascade_invocations - - comment_references - - control_flow_in_finally - - curly_braces_in_flow_control_structures - - depend_on_referenced_packages - - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - - file_names - - hash_and_equals - - iterable_contains_unrelated_type - - library_names - - library_prefixes - - list_remove_unrelated_type - - no_adjacent_strings_in_list - - no_duplicate_case_values - - non_constant_identifier_names - - null_closures - - omit_local_variable_types - - only_throw_errors - - overridden_fields - - package_names - - package_prefixed_library_names - - prefer_adjacent_string_concatenation - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_contains - - prefer_equal_for_default_values - - prefer_final_fields - - prefer_for_elements_to_map_fromIterable - - prefer_generic_function_type_aliases - - prefer_if_null_operators - - prefer_initializing_formals - - prefer_is_empty - - prefer_is_not_empty - - prefer_iterable_whereType - - prefer_null_aware_operators - - prefer_single_quotes - - prefer_spread_collections - - prefer_typing_uninitialized_variables - - recursive_getters - - slash_for_doc_comments - - test_types_in_equals - - throw_in_finally - - type_init_formals - - unawaited_futures - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - - unnecessary_lambdas - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_null_in_if_null_operators - - unnecessary_overrides - - unnecessary_parenthesis - - unnecessary_statements - - unnecessary_this - - unrelated_type_equality_checks - - use_function_type_syntax_for_parameters - - use_rethrow_when_possible - - valid_regexps - - void_checks + always_declare_return_types: true + avoid_bool_literals_in_conditional_expressions: true + avoid_classes_with_only_static_members: true + avoid_returning_this: true + avoid_unused_constructor_parameters: true + cascade_invocations: true + comment_references: true + directives_ordering: true + no_adjacent_strings_in_list: true + omit_local_variable_types: true + only_throw_errors: true + prefer_single_quotes: true + test_types_in_equals: true + throw_in_finally: true + unawaited_futures: true + unnecessary_lambdas: true + unnecessary_parenthesis: true + unnecessary_statements: true + # TODO: https://github.com/google/built_value.dart/issues/1115 + library_private_types_in_public_api: false + no_leading_underscores_for_local_identifiers: false diff --git a/build/lib/src/analyzer/resolver.dart b/build/lib/src/analyzer/resolver.dart index 3e544dbd9..0d437cd53 100644 --- a/build/lib/src/analyzer/resolver.dart +++ b/build/lib/src/analyzer/resolver.dart @@ -175,8 +175,8 @@ class SyntaxErrorInAssetException implements Exception { // Output messages like "foo.dart:3:4: Expected a semicolon here." buffer.writeln( - '$sourceName:${position.lineNumber}:${position.columnNumber}: ' + - error.message); + '$sourceName:${position.lineNumber}:${position.columnNumber}: ' + '${error.message}'); } final additionalErrors = entries.length - _maxErrorsInToString; diff --git a/build/pubspec.yaml b/build/pubspec.yaml index 0c703fe5f..564104f4c 100644 --- a/build/pubspec.yaml +++ b/build/pubspec.yaml @@ -19,5 +19,5 @@ dependencies: dev_dependencies: build_resolvers: ^2.0.0 build_test: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 diff --git a/build_config/pubspec.yaml b/build_config/pubspec.yaml index c72eefa2e..7b518490d 100644 --- a/build_config/pubspec.yaml +++ b/build_config/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' json_serializable: ^6.0.0 term_glyph: ^1.2.0 test: ^1.16.0 diff --git a/build_daemon/example/example.dart b/build_daemon/example/example.dart index 7fb19e4a7..94f12bbe0 100644 --- a/build_daemon/example/example.dart +++ b/build_daemon/example/example.dart @@ -12,7 +12,7 @@ import 'package:path/path.dart' as p; void main(List args) async { BuildDaemonClient client; var workingDirectory = - p.normalize(p.join(Directory.current.path + '/../example')); + p.normalize(p.join('${Directory.current.path}/../example')); try { // First we connect to the daemon. This will start one if one is not diff --git a/build_daemon/pubspec.yaml b/build_daemon/pubspec.yaml index 136c674d6..7da37211d 100644 --- a/build_daemon/pubspec.yaml +++ b/build_daemon/pubspec.yaml @@ -23,7 +23,7 @@ dev_dependencies: build_runner: ^2.0.0 # TODO: untangle analyzer dependency built_value_generator: ^8.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' mockito: ^5.0.0 test: ^1.16.0 test_descriptor: ^2.0.0 diff --git a/build_modules/pubspec.yaml b/build_modules/pubspec.yaml index 57edf4061..c80670e38 100644 --- a/build_modules/pubspec.yaml +++ b/build_modules/pubspec.yaml @@ -26,7 +26,7 @@ dev_dependencies: # Used inside tests build_runner: ^2.0.0 build_test: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' json_serializable: ^6.0.0 test: ^1.16.0 a: diff --git a/build_resolvers/pubspec.yaml b/build_resolvers/pubspec.yaml index 95777a774..6b40b6f08 100644 --- a/build_resolvers/pubspec.yaml +++ b/build_resolvers/pubspec.yaml @@ -21,6 +21,6 @@ dependencies: yaml: ^3.0.0 dev_dependencies: - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 build_test: ^2.0.0 diff --git a/build_runner/CHANGELOG.md b/build_runner/CHANGELOG.md index 91956e859..4c3c23b38 100644 --- a/build_runner/CHANGELOG.md +++ b/build_runner/CHANGELOG.md @@ -2,6 +2,8 @@ - Fix up the formatting a bit for the error message that is logged when we get errors from the directory watcher. +- Ignore the no_leading_underscores_for_library_prefixes lint in the generated + build script. ## 2.1.8 diff --git a/build_runner/lib/src/build_script_generate/build_script_generate.dart b/build_runner/lib/src/build_script_generate/build_script_generate.dart index 96ebbde4d..da255bb59 100644 --- a/build_runner/lib/src/build_script_generate/build_script_generate.dart +++ b/build_runner/lib/src/build_script_generate/build_script_generate.dart @@ -49,21 +49,22 @@ Future _generateBuildScript() async { allocator: Allocator.simplePrefixing(), useNullSafetySyntax: info.canRunWithSoundNullSafety); try { - final preamble = StringBuffer(); + final content = StringBuffer(); if (!info.canRunWithSoundNullSafety) { - preamble.write(''' + content.writeln(''' // Ensure that the build script itself is not opted in to null safety, // instead of taking the language version from the current package. // // @dart=2.9 - // - '''); + //'''); } - preamble.write('// ignore_for_file: directives_ordering'); + content + ..writeln('// ignore_for_file: directives_ordering') + ..writeln( + '// ignore_for_file: no_leading_underscores_for_library_prefixes') + ..writeln(library.accept(emitter)); - return DartFormatter().format(''' - $preamble - ${library.accept(emitter)}'''); + return DartFormatter().format(content.toString()); } on FormatterException { _log.severe('Generated build script could not be parsed.\n' 'This is likely caused by a misconfigured builder definition.'); @@ -90,7 +91,7 @@ Future> findBuilderApplications({ return info.builderApplications; } -Future<_BuildScriptInfo> findBuildScriptOptions({ +Future findBuildScriptOptions({ PackageGraph? packageGraph, Map? buildConfigOverrides, }) async { @@ -150,7 +151,7 @@ Future<_BuildScriptInfo> findBuildScriptOptions({ .map((e) => e.import) .followedBy(postProcessBuilderDefinitions.map((e) => e.import))); - return _BuildScriptInfo(applications, canRunWithSoundNullSafety); + return BuildScriptInfo(applications, canRunWithSoundNullSafety); } Future _allMigratedToNullSafety(PackageGraph packageGraph, @@ -207,11 +208,11 @@ Future _allMigratedToNullSafety(PackageGraph packageGraph, return true; } -class _BuildScriptInfo { +class BuildScriptInfo { final Iterable builderApplications; final bool canRunWithSoundNullSafety; - _BuildScriptInfo(this.builderApplications, this.canRunWithSoundNullSafety); + BuildScriptInfo(this.builderApplications, this.canRunWithSoundNullSafety); } /// A method forwarding to `run`. diff --git a/build_runner/pubspec.yaml b/build_runner/pubspec.yaml index 069c24dbc..b526ee73e 100644 --- a/build_runner/pubspec.yaml +++ b/build_runner/pubspec.yaml @@ -45,7 +45,7 @@ dependencies: dev_dependencies: build_test: ^2.0.0 build_web_compilers: ^3.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' stream_channel: ^2.0.0 test: ^1.16.0 test_descriptor: ^2.0.0 diff --git a/build_runner/test/server/serve_handler_test.dart b/build_runner/test/server/serve_handler_test.dart index a11b8da42..d4a7d1b92 100644 --- a/build_runner/test/server/serve_handler_test.dart +++ b/build_runner/test/server/serve_handler_test.dart @@ -75,7 +75,7 @@ void main() { }); test('caching with etags takes into account injected JS', () async { - _addSource('a|web/some.js', entrypointExtensionMarker + '\nalert(1)'); + _addSource('a|web/some.js', '$entrypointExtensionMarker\nalert(1)'); var noReloadEtag = (await serveHandler.handlerFor('web', buildUpdates: BuildUpdatesOption.none)( Request('GET', Uri.parse('http://server.com/some.js')))) @@ -204,8 +204,7 @@ void main() { BuildUpdatesOption buildUpdates) => group(groupName, () { test('injects client code if enabled', () async { - _addSource( - 'a|web/some.js', entrypointExtensionMarker + '\nalert(1)'); + _addSource('a|web/some.js', '$entrypointExtensionMarker\nalert(1)'); var response = await serveHandler.handlerFor('web', buildUpdates: buildUpdates)( Request('GET', Uri.parse('http://server.com/some.js'))); @@ -213,8 +212,7 @@ void main() { }); test('doesn\'t inject client code if disabled', () async { - _addSource( - 'a|web/some.js', entrypointExtensionMarker + '\nalert(1)'); + _addSource('a|web/some.js', '$entrypointExtensionMarker\nalert(1)'); var response = await serveHandler.handlerFor('web')( Request('GET', Uri.parse('http://server.com/some.js'))); expect(await response.readAsString(), @@ -223,7 +221,7 @@ void main() { test('doesn\'t inject client code in non-js files', () async { _addSource( - 'a|web/some.html', entrypointExtensionMarker + '\n
some'); + 'a|web/some.html', '$entrypointExtensionMarker\n
some'); var response = await serveHandler.handlerFor('web', buildUpdates: buildUpdates)( Request('GET', Uri.parse('http://server.com/some.html'))); diff --git a/build_runner_core/CHANGELOG.md b/build_runner_core/CHANGELOG.md index ffb3fb2d6..5efd73d38 100644 --- a/build_runner_core/CHANGELOG.md +++ b/build_runner_core/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.2.4-dev + +- Fix some new lints. + ## 7.2.3 - Allow the latest analyzer. diff --git a/build_runner_core/lib/src/changes/build_script_updates.dart b/build_runner_core/lib/src/changes/build_script_updates.dart index fefd64ee9..139740b15 100644 --- a/build_runner_core/lib/src/changes/build_script_updates.dart +++ b/build_runner_core/lib/src/changes/build_script_updates.dart @@ -88,7 +88,7 @@ class _MirrorBuildScriptUpdates implements BuildScriptUpdates { /// /// Returns `null` if the uri should be ignored, or throws an [ArgumentError] /// if the [uri] is not recognized. - static AssetId? _idForUri(Uri uri, String _rootPackage) { + static AssetId? _idForUri(Uri uri, String rootPackage) { switch (uri.scheme) { case 'dart': // TODO: check for sdk updates! @@ -99,7 +99,7 @@ class _MirrorBuildScriptUpdates implements BuildScriptUpdates { p.url.joinAll(['lib', ...parts.getRange(1, parts.length)])); case 'file': var relativePath = p.relative(uri.toFilePath(), from: p.current); - return AssetId(_rootPackage, relativePath); + return AssetId(rootPackage, relativePath); case 'data': // Test runner uses a `data` scheme, don't invalidate for those. if (uri.path.contains('package:test')) break; diff --git a/build_runner_core/lib/src/environment/create_merged_dir.dart b/build_runner_core/lib/src/environment/create_merged_dir.dart index 49ce7ecb3..0957d6147 100644 --- a/build_runner_core/lib/src/environment/create_merged_dir.dart +++ b/build_runner_core/lib/src/environment/create_merged_dir.dart @@ -260,7 +260,7 @@ Future _writeAsset( } else { await _writeAsBytes(outputDir, outputId, await reader.readAsBytes(id)); } - } on AssetNotFoundException catch (e, __) { + } on AssetNotFoundException catch (e) { if (p.basename(id.path).startsWith('.')) { _logger.fine('Skipping missing hidden file ${id.path}'); } else { diff --git a/build_runner_core/lib/src/generate/build_impl.dart b/build_runner_core/lib/src/generate/build_impl.dart index 61c5350a0..8bf36aaa0 100644 --- a/build_runner_core/lib/src/generate/build_impl.dart +++ b/build_runner_core/lib/src/generate/build_impl.dart @@ -477,6 +477,7 @@ class _SingleBuild { var inputNode = _assetGraph.get(input)!; assert( inputNode.primaryOutputs.containsAll(builderOutputs), + // ignore: prefer_interpolation_to_compose_strings 'input $input with builder $builder missing primary outputs: \n' 'Got ${inputNode.primaryOutputs.join(', ')} ' 'which was missing:\n' + diff --git a/build_runner_core/pubspec.yaml b/build_runner_core/pubspec.yaml index 50545b022..be1618cb5 100644 --- a/build_runner_core/pubspec.yaml +++ b/build_runner_core/pubspec.yaml @@ -1,5 +1,5 @@ name: build_runner_core -version: 7.2.3 +version: 7.2.4-dev description: Core tools to write binaries that run builders. repository: https://github.com/dart-lang/build/tree/master/build_runner_core @@ -30,7 +30,7 @@ dev_dependencies: analyzer: ">=2.0.0 <4.0.0" build_runner: ^2.0.0 build_test: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' json_serializable: ^6.0.0 test: ^1.16.0 test_descriptor: ^2.0.0 diff --git a/build_test/pubspec.yaml b/build_test/pubspec.yaml index 734f296c8..8acb8ccdf 100644 --- a/build_test/pubspec.yaml +++ b/build_test/pubspec.yaml @@ -26,4 +26,4 @@ dependencies: dev_dependencies: analyzer: ">=2.1.0 <4.0.0" collection: ^1.15.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' diff --git a/build_vm_compilers/pubspec.yaml b/build_vm_compilers/pubspec.yaml index dd996791c..c39adc12d 100644 --- a/build_vm_compilers/pubspec.yaml +++ b/build_vm_compilers/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 test_descriptor: ^2.0.0 _test_common: diff --git a/build_web_compilers/lib/src/dev_compiler_bootstrap.dart b/build_web_compilers/lib/src/dev_compiler_bootstrap.dart index 4e0ad9255..5d0141aa7 100644 --- a/build_web_compilers/lib/src/dev_compiler_bootstrap.dart +++ b/build_web_compilers/lib/src/dev_compiler_bootstrap.dart @@ -8,7 +8,8 @@ import 'dart:convert'; import 'package:build/build.dart'; import 'package:build_modules/build_modules.dart'; -import 'package:path/path.dart' as _p; // ignore: library_prefixes +// ignore: no_leading_underscores_for_library_prefixes +import 'package:path/path.dart' as _p; import 'package:pool/pool.dart'; import 'ddc_names.dart'; diff --git a/build_web_compilers/pubspec.yaml b/build_web_compilers/pubspec.yaml index f1918c439..9fe9fd731 100644 --- a/build_web_compilers/pubspec.yaml +++ b/build_web_compilers/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_test: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 a: path: test/fixtures/a diff --git a/build_web_compilers/web/source_map_stack_trace.dart b/build_web_compilers/web/source_map_stack_trace.dart index 041e03133..a0f3ab457 100644 --- a/build_web_compilers/web/source_map_stack_trace.dart +++ b/build_web_compilers/web/source_map_stack_trace.dart @@ -57,7 +57,7 @@ StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace, } var packageRoot = '$root/packages'; if (p.url.isWithin(packageRoot, sourceUrl)) { - sourceUrl = 'package:' + p.url.relative(sourceUrl, from: packageRoot); + sourceUrl = 'package:${p.url.relative(sourceUrl, from: packageRoot)}'; break; } } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4cf5ec2d4..52d035b79 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_web_compilers: ^3.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' dependency_overrides: build: diff --git a/scratch_space/pubspec.yaml b/scratch_space/pubspec.yaml index c89b051fc..be3eaacfb 100644 --- a/scratch_space/pubspec.yaml +++ b/scratch_space/pubspec.yaml @@ -15,5 +15,5 @@ dependencies: dev_dependencies: build_runner: ^2.0.0 build_test: ^2.0.0 - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test: ^1.16.0 diff --git a/tool/pubspec.yaml b/tool/pubspec.yaml index 8d7b024d9..6f283ed9b 100644 --- a/tool/pubspec.yaml +++ b/tool/pubspec.yaml @@ -11,6 +11,6 @@ dependencies: yaml: ^3.1.0 dev_dependencies: - lints: ^1.0.0 + lints: '>=1.0.0 <3.0.0' test_descriptor: ^2.0.0 test: ^1.20.1