Skip to content

Commit

Permalink
move shared analysis to subdir, enable dart_flutter_team_lints (#3497)
Browse files Browse the repository at this point in the history
* Adds a new `analysis` package, with the shared analysis_options.yaml file
* Add an analysis_options.yaml file that imports that one to each package
* Use the dart_flutter_team_lints package for lints
* Fix up all the new lint violations
  • Loading branch information
jakemac53 committed May 8, 2023
1 parent bde5fb9 commit 217b345
Show file tree
Hide file tree
Showing 101 changed files with 463 additions and 418 deletions.
232 changes: 116 additions & 116 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions _test/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
4 changes: 2 additions & 2 deletions _test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ dev_dependencies:
build: any
build_config: any
build_modules: any
build_web_compilers: any
build_runner: any
build_runner_core: any
build_test: any
lints: '>=1.0.0 <3.0.0'
build_web_compilers: any
dart_flutter_team_lints: ^1.0.0
io: ^1.0.0
path: ^1.8.0
provides_builder:
Expand Down
9 changes: 5 additions & 4 deletions _test/test/build_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void main() {
});

test(
'Restores previously deleted outputs if they are not deleted in subsequent builds',
() async {
'Restores previously deleted outputs if they are not deleted in '
'subsequent builds', () async {
final dartSource =
File(p.join('build', 'web', 'packages', '_test', 'app.dart'));
await runBuild(trailingArgs: [
Expand All @@ -112,11 +112,12 @@ void main() {

var nextBuild = await runBuild();
expect(
nextBuild.stdout.split('\n'),
(nextBuild.stdout as String).split('\n'),
containsAllInOrder([
contains('Generating build script'),
contains(
'Invalidated precompiled build script due to missing asset graph.'),
'Invalidated precompiled build script due to missing asset '
'graph.'),
contains('Precompiling build script'),
contains('Building new asset graph.'),
contains('Succeeded after'),
Expand Down
1 change: 1 addition & 0 deletions _test_common/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
3 changes: 2 additions & 1 deletion _test_common/lib/descriptors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Future<d.FileDescriptor> pubspec(
..writeln(' sdk: "$sdkEnvironment"')
..writeln('dependencies:');

// Add all deps as `any` deps, real versions are set in dependency_overrides below.
// Add all deps as `any` deps, real versions are set in dependency_overrides
// below.
var allPackages = [
...currentIsolateDependencies,
...pathDependencies.keys,
Expand Down
11 changes: 7 additions & 4 deletions _test_common/lib/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ class _AssetGraphMatcher extends Matcher {
description.addDescriptionOf(_expected);

@override
Description describeMismatch(
item, Description mismatchDescription, Map matchState, bool verbose) {
matchState.forEach((k, v) =>
mismatchDescription.add('$k: got ${v[0]} but expected ${v[1]}'));
Description describeMismatch(dynamic item, Description mismatchDescription,
Map matchState, bool verbose) {
matchState.forEach((k, v) {
v = v as List;
mismatchDescription.add('$k: got ${v[0]} but expected ${v[1]}');
});

return mismatchDescription;
}
}
2 changes: 1 addition & 1 deletion _test_common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
watcher: ^1.0.0

dev_dependencies:
lints: '>=1.0.0 <3.0.0'
dart_flutter_team_lints: ^1.0.0

dependency_overrides:
build:
Expand Down
23 changes: 23 additions & 0 deletions analysis/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include: package:dart_flutter_team_lints/analysis_options.yaml
analyzer:
language:
strict-casts: true
errors:
unused_import: error
unused_local_variable: error
dead_code: error
todo: ignore
deprecated_member_use_from_same_package: ignore
exclude:
# Prevents extra work during some e2e test runs.
- "dart2js_test/**"
# Common top level directories containing generated files in any package.
- "build/**"
- ".dart_tool/**"

linter:
rules:
# TODO: Remove this once we can use unnamed libraries.
library_annotations: false
# TODO: https://github.com/google/json_serializable.dart/issues/1313
use_string_in_part_of_directives: false
2 changes: 1 addition & 1 deletion pubspec.yaml → analysis/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ publish_to: none
environment:
sdk: ">=2.12.0 <4.0.0"
dev_dependencies:
lints: ^2.0.0
dart_flutter_team_lints: any
40 changes: 0 additions & 40 deletions analysis_options.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.4.1-wip

## 2.4.0

- Add `BuildStep.packageConfig` getter to resolve a package config of all
Expand Down
1 change: 1 addition & 0 deletions build/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
7 changes: 5 additions & 2 deletions build/lib/src/asset/id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ class AssetId implements Comparable<AssetId> {
? uri
: from != null
? from.uri.resolveUri(uri)
: (throw ArgumentError.value(from, 'from',
'An AssetId "from" must be specified to resolve a relative URI'));
: (throw ArgumentError.value(
from,
'from',
'An AssetId "from" must be specified to resolve a relative '
'URI'));
if (resolved.scheme == 'package') {
return AssetId(resolved.pathSegments.first,
p.url.join('lib', p.url.joinAll(resolved.pathSegments.skip(1))));
Expand Down
6 changes: 3 additions & 3 deletions build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: build
version: 2.4.0
version: 2.4.1-wip
description: A package for authoring build_runner compatible code generators.
repository: https://github.com/dart-lang/build/tree/master/build

environment:
sdk: ">=2.18.0 <3.0.0"
sdk: ">=2.19.0 <3.0.0"

dependencies:
analyzer: ">=1.5.0 <6.0.0"
Expand All @@ -20,5 +20,5 @@ dependencies:
dev_dependencies:
build_resolvers: ^2.0.0
build_test: ^2.0.0
lints: '>=1.0.0 <3.0.0'
dart_flutter_team_lints: ^1.0.0
test: ^1.16.0
4 changes: 2 additions & 2 deletions build/test/generate/run_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void main() {
config.packages.singleWhere((p) => p.name == 'build');
expect(buildPackage.root, Uri.parse('asset:build/'));
expect(buildPackage.packageUriRoot, Uri.parse('asset:build/lib/'));
expect(buildPackage.languageVersion, LanguageVersion(2, 18));
expect(buildPackage.languageVersion, LanguageVersion(2, 19));

final resolvedBuildUri =
config.resolve(Uri.parse('package:build/foo.txt'))!;
Expand All @@ -104,7 +104,7 @@ void main() {
Package(
'build',
Uri.file('/foo/bar/'),
languageVersion: LanguageVersion(2, 18),
languageVersion: LanguageVersion(2, 19),
),
]),
);
Expand Down
1 change: 1 addition & 0 deletions build_config/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
4 changes: 2 additions & 2 deletions build_config/lib/build_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

export 'src/build_config.dart' show BuildConfig;
export 'src/build_target.dart'
show BuildTarget, TargetBuilderConfig, GlobalBuilderConfig;
show BuildTarget, GlobalBuilderConfig, TargetBuilderConfig;
export 'src/builder_definition.dart'
show
BuilderDefinition,
AutoApply,
BuildTo,
BuilderDefinition,
PostProcessBuilderDefinition,
TargetBuilderConfigDefaults;
export 'src/common.dart' show runInBuildConfigZone;
Expand Down
2 changes: 1 addition & 1 deletion build_config/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:

dev_dependencies:
build_runner: ^2.0.0
lints: '>=1.0.0 <3.0.0'
dart_flutter_team_lints: ^1.0.0
json_serializable: ^6.0.0
term_glyph: ^1.2.0
test: ^1.16.0
4 changes: 2 additions & 2 deletions build_config/test/build_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ builders:
});
}

var buildYaml = r'''
String buildYaml = r'''
global_options:
":h":
options:
Expand Down Expand Up @@ -237,7 +237,7 @@ additional_public_assets:
- "test/**"
''';

var buildYamlNoTargets = '''
String buildYamlNoTargets = '''
builders:
a:
builder_factories: ["createBuilder"]
Expand Down
4 changes: 2 additions & 2 deletions build_config/test/errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ targets:
_expectThrows(
buildYaml,
allOf(
contains(
'line 4, column 7 of build.yaml: Unsupported value for "builders".'),
contains('line 4, column 7 of build.yaml: Unsupported value for '
'"builders".'),
contains(r'''
4 │ not:defined:
Expand Down
1 change: 1 addition & 0 deletions build_daemon/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
6 changes: 3 additions & 3 deletions build_daemon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A daemon for running Dart builds.
repository: https://github.com/dart-lang/build/tree/master/build_daemon

environment:
sdk: ">=2.18.0 <3.0.0"
sdk: ">=2.19.0 <3.0.0"

dependencies:
built_collection: ^5.0.0
Expand All @@ -20,11 +20,11 @@ dependencies:
web_socket_channel: ^2.0.0

dev_dependencies:
build_runner: ^2.0.0
analyzer: '>=3.4.0 <6.0.0'
build_runner: ^2.0.0
# TODO: untangle analyzer dependency
built_value_generator: ^8.1.0
lints: '>=1.0.0 <3.0.0'
dart_flutter_team_lints: ^1.0.0
mockito: ^5.0.0
test: ^1.16.0
test_descriptor: ^2.0.0
Expand Down
2 changes: 2 additions & 0 deletions build_modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 5.0.3-wip

## 5.0.2

- Support Dart version 3.1.
Expand Down
1 change: 1 addition & 0 deletions build_modules/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml
2 changes: 1 addition & 1 deletion build_modules/lib/src/module_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ModuleLibrary {
/// Importable libraries can be round tripped to a String. Non-importable
/// libraries should not be printed or parsed.
factory ModuleLibrary.deserialize(AssetId id, String encoded) {
var json = jsonDecode(encoded);
var json = jsonDecode(encoded) as Map<String, Object?>;

return ModuleLibrary._(id,
isEntryPoint: json['isEntrypoint'] as bool,
Expand Down
2 changes: 1 addition & 1 deletion build_modules/lib/src/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DartPlatform {
int get hashCode => name.hashCode;

@override
bool operator ==(other) => other is DartPlatform && other.name == name;
bool operator ==(Object other) => other is DartPlatform && other.name == name;
}

class DartPlatformAlreadyRegistered implements Exception {
Expand Down
12 changes: 6 additions & 6 deletions build_modules/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build_modules
version: 5.0.2
version: 5.0.3-wip
description: >-
Builders to analyze and split Dart code into individually compilable modules
based on imports.
Expand All @@ -25,13 +25,13 @@ dependencies:
stream_transform: ^2.0.0

dev_dependencies:
a:
path: test/fixtures/a
b:
path: test/fixtures/b
# Used inside tests
build_runner: ^2.0.0
build_test: ^2.0.0
lints: '>=1.0.0 <3.0.0'
dart_flutter_team_lints: ^1.0.0
json_serializable: ^6.0.0
test: ^1.16.0
a:
path: test/fixtures/a
b:
path: test/fixtures/b
1 change: 1 addition & 0 deletions build_modules/test/fixtures/a/lib/a_non_sdk.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// ignore: unnecessary_library_directive
library dart.pkg.not_in_sdk;
10 changes: 5 additions & 5 deletions build_modules/test/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EncodedMetaModuleMatcher extends Matcher {
EncodedMetaModuleMatcher(this.expected);

@override
bool matches(actual, description) {
bool matches(dynamic actual, Map<dynamic, dynamic> description) {
if (actual is List<int>) {
actual = utf8.decode(actual);
}
Expand All @@ -37,8 +37,8 @@ class EncodedMetaModuleMatcher extends Matcher {
}

@override
Description describeMismatch(
item, Description mismatchDescription, Map matchState, bool verbose) {
Description describeMismatch(dynamic item, Description mismatchDescription,
Map matchState, bool verbose) {
try {
if (item is List<int>) {
item = utf8.decode(item);
Expand All @@ -63,7 +63,7 @@ class ModuleMatcher extends Matcher {
ModuleMatcher(this.expected);

@override
bool matches(actual, description) {
bool matches(dynamic actual, Map<dynamic, dynamic> description) {
if (actual is! Module) return false;
return actual.primarySource == expected.primarySource &&
unorderedEquals(expected.sources)
Expand All @@ -84,7 +84,7 @@ class EncodedModuleMatcher extends Matcher {
EncodedModuleMatcher(this.expected);

@override
bool matches(actual, description) {
bool matches(dynamic actual, Map<dynamic, dynamic> description) {
if (actual is List<int>) {
actual = utf8.decode(actual);
}
Expand Down
2 changes: 2 additions & 0 deletions build_resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.2.1-wip

## 2.2.0

- Add support for `CompilationUnitElement` to `AnalysisResolver.astNodeFor()`.
Expand Down
1 change: 1 addition & 0 deletions build_resolvers/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis/analysis_options.yaml

0 comments on commit 217b345

Please sign in to comment.