Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to package:lints 2.0 #3267

Merged
merged 3 commits into from Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion _test/pubspec.yaml
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions _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;
Expand Down
2 changes: 1 addition & 1 deletion _test_common/pubspec.yaml
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion _test_null_safety/pubspec.yaml
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions _test_null_safety/test/common/message.dart
Expand Up @@ -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.
Expand Down
105 changes: 21 additions & 84 deletions analysis_options.yaml
Expand Up @@ -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
4 changes: 2 additions & 2 deletions build/lib/src/analyzer/resolver.dart
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion build/pubspec.yaml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion build_config/pubspec.yaml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion build_daemon/example/example.dart
Expand Up @@ -12,7 +12,7 @@ import 'package:path/path.dart' as p;
void main(List<String> 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
Expand Down
2 changes: 1 addition & 1 deletion build_daemon/pubspec.yaml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build_modules/pubspec.yaml
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build_resolvers/pubspec.yaml
Expand Up @@ -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
2 changes: 2 additions & 0 deletions build_runner/CHANGELOG.md
Expand Up @@ -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

Expand Down
Expand Up @@ -49,21 +49,22 @@ Future<String> _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.');
Expand All @@ -90,7 +91,7 @@ Future<Iterable<Expression>> findBuilderApplications({
return info.builderApplications;
}

Future<_BuildScriptInfo> findBuildScriptOptions({
Future<BuildScriptInfo> findBuildScriptOptions({
PackageGraph? packageGraph,
Map<String, BuildConfig>? buildConfigOverrides,
}) async {
Expand Down Expand Up @@ -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<bool> _allMigratedToNullSafety(PackageGraph packageGraph,
Expand Down Expand Up @@ -207,11 +208,11 @@ Future<bool> _allMigratedToNullSafety(PackageGraph packageGraph,
return true;
}

class _BuildScriptInfo {
class BuildScriptInfo {
final Iterable<Expression> builderApplications;
final bool canRunWithSoundNullSafety;

_BuildScriptInfo(this.builderApplications, this.canRunWithSoundNullSafety);
BuildScriptInfo(this.builderApplications, this.canRunWithSoundNullSafety);
}

/// A method forwarding to `run`.
Expand Down
2 changes: 1 addition & 1 deletion build_runner/pubspec.yaml
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions build_runner/test/server/serve_handler_test.dart
Expand Up @@ -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'))))
Expand Down Expand Up @@ -204,17 +204,15 @@ 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')));
expect(await response.readAsString(), contains(injectionMarker));
});

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(),
Expand All @@ -223,7 +221,7 @@ void main() {

test('doesn\'t inject client code in non-js files', () async {
_addSource(
'a|web/some.html', entrypointExtensionMarker + '\n<br>some');
'a|web/some.html', '$entrypointExtensionMarker\n<br>some');
var response = await serveHandler.handlerFor('web',
buildUpdates: buildUpdates)(
Request('GET', Uri.parse('http://server.com/some.html')));
Expand Down
4 changes: 4 additions & 0 deletions build_runner_core/CHANGELOG.md
@@ -1,3 +1,7 @@
## 7.2.4-dev

- Fix some new lints.

## 7.2.3

- Allow the latest analyzer.
Expand Down
4 changes: 2 additions & 2 deletions build_runner_core/lib/src/changes/build_script_updates.dart
Expand Up @@ -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!
Expand All @@ -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;
Expand Down
Expand Up @@ -260,7 +260,7 @@ Future<AssetId> _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 {
Expand Down
1 change: 1 addition & 0 deletions build_runner_core/lib/src/generate/build_impl.dart
Expand Up @@ -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' +
Expand Down
4 changes: 2 additions & 2 deletions 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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build_test/pubspec.yaml
Expand Up @@ -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'