Skip to content

Commit 8d827d1

Browse files
authored
Merge pull request #2831 from jcollins-g/nnbd-mastermerge-1008
Merge from main branch to NNBD
2 parents ac4256e + d71c385 commit 8d827d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+576
-427
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 4.0.0
2+
* BREAKING CHANGE: Refactors to support NNBD and adapt to new analyzer
3+
changes are technically semver breaking. If you make extensive use of
4+
the `documentationComment` getter on `ModelElement` or other deep
5+
structural elements in dartdoc or custom templates, they could break
6+
dependent code. (#2819, #2818, #2817, #2806, #2798)
7+
* BREAKING CHANGE: Remove a large number of long-standing deprecated
8+
symbols in dartdoc. (#2821)
9+
* Fix a problem where certain comment reference strings could
10+
crash the parser. (#2813, #2808)
11+
* Fix an assert in canonicalization for enums. (#2812)
12+
113
## 3.1.0
214
* This version supports the Dart language feature constructor tearoffs,
315
pending completion by other tools.

analysis_options.yaml

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change analysis_options.yaml and analysis_options_presubmit.yaml
22
# together.
3-
include: package:pedantic/analysis_options.1.11.0.yaml
3+
include: package:lints/recommended.yaml
44

55
analyzer:
66
errors:
@@ -19,45 +19,19 @@ analyzer:
1919
- 'testing/test_package_export_error/**'
2020
linter:
2121
rules:
22-
- always_declare_return_types
23-
- avoid_dynamic_calls
24-
- avoid_single_cascade_in_expression_statements
25-
- avoid_unused_constructor_parameters
26-
- annotate_overrides
27-
- avoid_init_to_null
28-
- directives_ordering
29-
- no_adjacent_strings_in_list
30-
- package_api_docs
31-
- prefer_final_fields
32-
- prefer_initializing_formals
33-
- prefer_void_to_null
34-
- slash_for_doc_comments
35-
- type_annotate_public_apis
36-
# - unnecessary_brace_in_string_interps
22+
always_declare_return_types: true
23+
annotate_overrides: true
24+
avoid_dynamic_calls: true
25+
avoid_single_cascade_in_expression_statements: true
26+
avoid_unused_constructor_parameters: true
27+
avoid_init_to_null: true
28+
directives_ordering: true
29+
no_adjacent_strings_in_list: true
30+
package_api_docs: true
31+
prefer_final_fields: true
32+
prefer_initializing_formals: true
33+
prefer_void_to_null: true
34+
slash_for_doc_comments: true
35+
type_annotate_public_apis: true
3736
# Work in progress canonical score lints
38-
- avoid_empty_else
39-
- avoid_relative_lib_imports
40-
- avoid_shadowing_type_parameters
41-
- await_only_futures
42-
- camel_case_extensions
43-
- camel_case_types
44-
- curly_braces_in_flow_control_structures
45-
- empty_catches
46-
- file_names
47-
- hash_and_equals
48-
- iterable_contains_unrelated_type
49-
- list_remove_unrelated_type
50-
- no_duplicate_case_values
51-
# - non_constant_identifier_names
52-
- package_prefixed_library_names
53-
- prefer_generic_function_type_aliases
54-
- prefer_is_empty
55-
- prefer_is_not_empty
56-
- prefer_iterable_whereType
57-
- prefer_typing_uninitialized_variables
58-
- provide_deprecation_message
59-
- unawaited_futures
60-
- unnecessary_overrides
61-
- unrelated_type_equality_checks
62-
- valid_regexps
63-
- void_checks
37+
unawaited_futures: true

analysis_options_presubmit.yaml

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change analysis_options.yaml and analysis_options_presubmit.yaml
22
# together.
3-
include: package:pedantic/analysis_options.1.11.0.yaml
3+
include: package:lints/recommended.yaml
44

55
analyzer:
66
errors:
@@ -24,45 +24,19 @@ analyzer:
2424
- 'testing/test_package_export_error/**'
2525
linter:
2626
rules:
27-
- always_declare_return_types
28-
- avoid_dynamic_calls
29-
- avoid_single_cascade_in_expression_statements
30-
- avoid_unused_constructor_parameters
31-
- annotate_overrides
32-
- avoid_init_to_null
33-
- directives_ordering
34-
- no_adjacent_strings_in_list
35-
- package_api_docs
36-
- prefer_final_fields
37-
- prefer_initializing_formals
38-
- prefer_void_to_null
39-
- slash_for_doc_comments
40-
- type_annotate_public_apis
41-
# - unnecessary_brace_in_string_interps
27+
always_declare_return_types: true
28+
annotate_overrides: true
29+
avoid_dynamic_calls: true
30+
avoid_single_cascade_in_expression_statements: true
31+
avoid_unused_constructor_parameters: true
32+
avoid_init_to_null: true
33+
directives_ordering: true
34+
no_adjacent_strings_in_list: true
35+
package_api_docs: true
36+
prefer_final_fields: true
37+
prefer_initializing_formals: true
38+
prefer_void_to_null: true
39+
slash_for_doc_comments: true
40+
type_annotate_public_apis: true
4241
# Work in progress canonical score lints
43-
- avoid_empty_else
44-
- avoid_relative_lib_imports
45-
- avoid_shadowing_type_parameters
46-
- await_only_futures
47-
- camel_case_extensions
48-
- camel_case_types
49-
- curly_braces_in_flow_control_structures
50-
- empty_catches
51-
- file_names
52-
- hash_and_equals
53-
- iterable_contains_unrelated_type
54-
- list_remove_unrelated_type
55-
- no_duplicate_case_values
56-
# - non_constant_identifier_names
57-
- package_prefixed_library_names
58-
- prefer_generic_function_type_aliases
59-
- prefer_is_empty
60-
- prefer_is_not_empty
61-
- prefer_iterable_whereType
62-
- prefer_typing_uninitialized_variables
63-
- provide_deprecation_message
64-
- unawaited_futures
65-
- unnecessary_overrides
66-
- unrelated_type_equality_checks
67-
- valid_regexps
68-
- void_checks
42+
unawaited_futures: true

dartdoc_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dartdoc:
22
linkToSource:
33
root: '.'
4-
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v3.1.0/%f%#L%l%'
4+
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v4.0.0/%f%#L%l%'

lib/dartdoc.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
/// A documentation generator for Dart.
88
///
9-
/// Library interface is currently under heavy construction and may change
10-
/// drastically between minor revisions.
9+
/// Library interface is still experimental.
10+
@experimental
1111
library dartdoc;
1212

1313
import 'dart:async';
@@ -372,7 +372,7 @@ class Dartdoc {
372372
var indexPath = path.joinAll([origin, 'index.html']);
373373
var file = config.resourceProvider.getFile(fullPath);
374374
if (!file.exists) {
375-
return null;
375+
return;
376376
}
377377
var decoder = JsonDecoder();
378378
List<Object> jsonData = decoder.convert(file.readAsStringSync());
@@ -417,7 +417,7 @@ class Dartdoc {
417417
// Remove so that we properly count that the file doesn't exist for
418418
// the orphan check.
419419
visited.remove(fullPath);
420-
return null;
420+
return;
421421
}
422422
visited.add(fullPath);
423423
var stringLinks = stringLinksAndHref.item1;

lib/src/comment_references/parser.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,12 @@ class CommentReferenceParser {
134134
var typeVariablesResult = _parseTypeVariables();
135135
if (typeVariablesResult.type == _TypeVariablesResultType.endOfFile) {
136136
break;
137-
} else if (typeVariablesResult.type ==
138-
_TypeVariablesResultType.notTypeVariables) {
139-
// Do nothing, _index has not moved.
140-
;
141137
} else if (typeVariablesResult.type ==
142138
_TypeVariablesResultType.parsedTypeVariables) {
143139
children.add(typeVariablesResult.node);
140+
} else {
141+
assert(typeVariablesResult.type ==
142+
_TypeVariablesResultType.notTypeVariables);
144143
}
145144
}
146145
if (_atEnd || _thisChar != $dot) {

lib/src/dartdoc_options.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ abstract class DartdocOption<T extends Object?> {
533533
/// Apply the function [visit] to [this] and all children.
534534
void traverse(void Function(DartdocOption option) visit) {
535535
visit(this);
536-
_children.values.forEach((d) => d.traverse(visit));
536+
for (var value in _children.values) {
537+
value.traverse(visit);
538+
}
537539
}
538540
}
539541

@@ -716,7 +718,9 @@ class DartdocOptionRoot extends DartdocOptionSet {
716718
/// configuration object.
717719
@override
718720
void traverse(void Function(DartdocOption option) visitor) {
719-
_children.values.forEach((d) => d.traverse(visitor));
721+
for (var value in _children.values) {
722+
value.traverse(visitor);
723+
}
720724
}
721725

722726
@override
@@ -732,7 +736,7 @@ class DartdocOptionSet extends DartdocOption<void> {
732736

733737
/// [DartdocOptionSet] always has the null value.
734738
@override
735-
void valueAt(Folder dir) => null;
739+
void valueAt(Folder dir) {}
736740

737741
/// Since we have no value, [_onMissing] does nothing.
738742
@override
@@ -995,7 +999,9 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
995999
}
9961000
}
9971001
}
998-
canonicalPaths.forEach((p) => _yamlAtCanonicalPathCache[p] = yamlData);
1002+
for (var canonicalPath in canonicalPaths) {
1003+
_yamlAtCanonicalPathCache[canonicalPath] = yamlData;
1004+
}
9991005
return yamlData;
10001006
}
10011007
}
@@ -1102,7 +1108,7 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
11021108
/// 'something-bar-over-the-hill' (with default skip).
11031109
/// This allows argument names to reflect nested structure.
11041110
static String _keysToArgName(Iterable<String> keys, [int skip = 1]) {
1105-
var argName = "${keys.skip(skip).join('-')}";
1111+
var argName = keys.skip(skip).join('-');
11061112
argName = argName.replaceAll('_', '-');
11071113
// Do not consume the lowercase character after the uppercase one, to handle
11081114
// two character words.

lib/src/element_type.dart

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ import 'package:analyzer/dart/element/nullability_suffix.dart';
1212
import 'package:analyzer/dart/element/type.dart';
1313
import 'package:dartdoc/src/model/comment_referable.dart';
1414
import 'package:dartdoc/src/model/model.dart';
15+
import 'package:dartdoc/src/model/model_object_builder.dart';
1516
import 'package:dartdoc/src/render/element_type_renderer.dart';
1617

18+
mixin ElementTypeBuilderImpl implements ElementTypeBuilder {
19+
PackageGraph get packageGraph;
20+
21+
@override
22+
ElementType typeFrom(DartType f, Library library,
23+
{ElementType returnedFrom}) =>
24+
ElementType._from(f, library, packageGraph, returnedFrom: returnedFrom);
25+
}
26+
1727
/// Base class representing a type in Dartdoc. It wraps a [DartType], and
1828
/// may link to a [ModelElement].
19-
abstract class ElementType extends Privacy with CommentReferable, Nameable {
29+
abstract class ElementType extends Privacy
30+
with CommentReferable, Nameable, ModelBuilder {
2031
final DartType _type;
2132
@override
2233
final PackageGraph packageGraph;
@@ -26,7 +37,7 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
2637

2738
ElementType(this._type, this.library, this.packageGraph, this.returnedFrom);
2839

29-
factory ElementType.from(
40+
factory ElementType._from(
3041
DartType f, Library library, PackageGraph packageGraph,
3142
{ElementType returnedFrom}) {
3243
if (f.element == null ||
@@ -41,7 +52,7 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
4152
}
4253
return UndefinedElementType(f, library, packageGraph, returnedFrom);
4354
} else {
44-
var element = ModelElement.fromElement(f.element, packageGraph);
55+
var element = packageGraph.modelBuilder.fromElement(f.element);
4556
// [TypeAliasElement.aliasElement] has different implications.
4657
// In that case it is an actual type alias of some kind (generic
4758
// or otherwise. Here however aliasElement signals that this is a
@@ -174,7 +185,7 @@ class FunctionTypeElementType extends UndefinedElementType
174185

175186
/// An unmodifiable list of this function element's type parameters.
176187
List<TypeParameter> get typeFormals => type.typeFormals
177-
.map((p) => ModelElement.from(p, library, packageGraph) as TypeParameter)
188+
.map((p) => packageGraph.modelBuilder.from(p, library) as TypeParameter)
178189
.toList(growable: false);
179190

180191
@override
@@ -215,26 +226,26 @@ class ParameterizedElementType extends DefinedElementType with Rendered {
215226
@override
216227
Iterable<ElementType> get typeArguments =>
217228
_typeArguments ??= type.typeArguments
218-
.map((f) => ElementType.from(f, library, packageGraph))
229+
.map((f) => modelBuilder.typeFrom(f, library))
219230
.toList(growable: false);
220231
}
221232

222233
/// A [ElementType] whose underlying type was referrred to by a type alias.
223-
mixin Aliased implements ElementType {
234+
mixin Aliased implements ElementType, ModelBuilderInterface {
224235
@override
225236
String get name => type.alias.element.name;
226237

227238
@override
228239
bool get isTypedef => true;
229240

230241
ModelElement _aliasElement;
231-
ModelElement get aliasElement => _aliasElement ??=
232-
ModelElement.fromElement(type.alias.element, packageGraph);
242+
ModelElement get aliasElement =>
243+
_aliasElement ??= modelBuilder.fromElement(type.alias.element);
233244

234245
Iterable<ElementType> _aliasArguments;
235246
Iterable<ElementType> get aliasArguments =>
236247
_aliasArguments ??= type.alias.typeArguments
237-
.map((f) => ElementType.from(f, library, packageGraph))
248+
.map((f) => modelBuilder.typeFrom(f, library))
238249
.toList(growable: false);
239250
}
240251

@@ -376,12 +387,12 @@ abstract class DefinedElementType extends ElementType {
376387
/// unless it is an alias reference.
377388
mixin Callable implements ElementType {
378389
List<Parameter> get parameters => type.parameters
379-
.map((p) => ModelElement.from(p, library, packageGraph) as Parameter)
390+
.map((p) => modelBuilder.from(p, library) as Parameter)
380391
.toList(growable: false);
381392

382393
ElementType _returnType;
383394
ElementType get returnType {
384-
_returnType ??= ElementType.from(type.returnType, library, packageGraph);
395+
_returnType ??= modelBuilder.typeFrom(type.returnType, library);
385396
return _returnType;
386397
}
387398

@@ -432,7 +443,7 @@ class CallableElementType extends DefinedElementType with Rendered, Callable {
432443
@override
433444
Iterable<ElementType> get typeArguments =>
434445
_typeArguments ??= (type.alias?.typeArguments ?? [])
435-
.map((f) => ElementType.from(f, library, packageGraph))
446+
.map((f) => modelBuilder.typeFrom(f, library))
436447
.toList(growable: false);
437448
}
438449

lib/src/experiment_options.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
library dartdoc.experiment_options;
1010

1111
import 'package:analyzer/file_system/file_system.dart';
12+
// ignore: implementation_imports
1213
import 'package:analyzer/src/dart/analysis/experiments.dart';
1314
import 'package:dartdoc/src/dartdoc_options.dart';
1415

lib/src/generator/empty_generator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import 'package:dartdoc/src/model_utils.dart';
1313
/// it were.
1414
class EmptyGenerator extends Generator {
1515
@override
16-
Future<void> generate(PackageGraph _packageGraph, FileWriter writer) {
17-
logProgress(_packageGraph.defaultPackage.documentationAsHtml);
18-
for (var package in {_packageGraph.defaultPackage}
19-
..addAll(_packageGraph.localPackages)) {
16+
Future<void> generate(PackageGraph packageGraph, FileWriter writer) {
17+
logProgress(packageGraph.defaultPackage.documentationAsHtml);
18+
for (var package in {packageGraph.defaultPackage}
19+
..addAll(packageGraph.localPackages)) {
2020
for (var category in filterNonDocumented(package.categories)) {
2121
logProgress(category.documentationAsHtml);
2222
}

lib/src/generator/html_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class HtmlGeneratorBackend extends DartdocGeneratorBackend {
6161
}
6262

6363
Future<void> _copyResources(FileWriter writer) async {
64-
for (var resourcePath in resources.resource_names) {
64+
for (var resourcePath in resources.resourceNames) {
6565
if (!resourcePath.startsWith(_dartdocResourcePrefix)) {
6666
throw StateError('Resource paths must start with '
6767
'$_dartdocResourcePrefix, encountered $resourcePath');

0 commit comments

Comments
 (0)