Skip to content

Commit b4fa868

Browse files
authored
Get rid of a backlog of potentially suboptimal coding practices in dartdoc (#2830)
* switch to lints/core.yaml * recommended * presubmit cleanup * oops, recommended on presubmit too
1 parent c45302c commit b4fa868

Some content is hidden

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

54 files changed

+221
-224
lines changed

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

lib/dartdoc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class Dartdoc {
370370
var indexPath = path.joinAll([origin, 'index.html']);
371371
var file = config.resourceProvider.getFile(fullPath);
372372
if (!file.exists) {
373-
return null;
373+
return;
374374
}
375375
var decoder = JsonDecoder();
376376
List<Object> jsonData = decoder.convert(file.readAsStringSync());
@@ -415,7 +415,7 @@ class Dartdoc {
415415
// Remove so that we properly count that the file doesn't exist for
416416
// the orphan check.
417417
visited.remove(fullPath);
418-
return null;
418+
return;
419419
}
420420
visited.add(fullPath);
421421
var stringLinks = stringLinksAndHref.item1;

lib/src/comment_references/parser.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,12 @@ class CommentReferenceParser {
131131
var typeVariablesResult = _parseTypeVariables();
132132
if (typeVariablesResult.type == _TypeVariablesResultType.endOfFile) {
133133
break;
134-
} else if (typeVariablesResult.type ==
135-
_TypeVariablesResultType.notTypeVariables) {
136-
// Do nothing, _index has not moved.
137-
;
138134
} else if (typeVariablesResult.type ==
139135
_TypeVariablesResultType.parsedTypeVariables) {
140136
children.add(typeVariablesResult.node);
137+
} else {
138+
assert(typeVariablesResult.type ==
139+
_TypeVariablesResultType.notTypeVariables);
141140
}
142141
}
143142
if (_atEnd || _thisChar != $dot) {

lib/src/dartdoc_options.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ abstract class DartdocOption<T extends Object> {
556556
/// Apply the function [visit] to [this] and all children.
557557
void traverse(void Function(DartdocOption option) visit) {
558558
visit(this);
559-
_children.values.forEach((d) => d.traverse(visit));
559+
for (var value in _children.values) {
560+
value.traverse(visit);
561+
}
560562
}
561563
}
562564

@@ -731,7 +733,7 @@ class DartdocOptionSet extends DartdocOption<void> {
731733

732734
/// [DartdocOptionSet] always has the null value.
733735
@override
734-
void valueAt(Folder dir) => null;
736+
void valueAt(Folder dir) {}
735737

736738
/// Since we have no value, [_onMissing] does nothing.
737739
@override
@@ -742,7 +744,9 @@ class DartdocOptionSet extends DartdocOption<void> {
742744
/// configuration object.
743745
@override
744746
void traverse(void Function(DartdocOption option) visitor) {
745-
_children.values.forEach((d) => d.traverse(visitor));
747+
for (var value in _children.values) {
748+
value.traverse(visitor);
749+
}
746750
}
747751
}
748752

@@ -1033,7 +1037,9 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10331037
}
10341038
}
10351039
}
1036-
canonicalPaths.forEach((p) => _yamlAtCanonicalPathCache[p] = yamlData);
1040+
for (var canonicalPath in canonicalPaths) {
1041+
_yamlAtCanonicalPathCache[canonicalPath] = yamlData;
1042+
}
10371043
return yamlData;
10381044
}
10391045
}
@@ -1137,7 +1143,7 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
11371143
/// 'something-bar-over-the-hill' (with default skip).
11381144
/// This allows argument names to reflect nested structure.
11391145
static String _keysToArgName(Iterable<String> keys, [int skip = 1]) {
1140-
var argName = "${keys.skip(skip).join('-')}";
1146+
var argName = keys.skip(skip).join('-');
11411147
argName = argName.replaceAll('_', '-');
11421148
// Do not consume the lowercase character after the uppercase one, to handle
11431149
// two character words.

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
@@ -11,10 +11,10 @@ import 'package:dartdoc/src/model_utils.dart';
1111
/// it were.
1212
class EmptyGenerator extends Generator {
1313
@override
14-
Future<void> generate(PackageGraph _packageGraph, FileWriter writer) {
15-
logProgress(_packageGraph.defaultPackage.documentationAsHtml);
16-
for (var package in {_packageGraph.defaultPackage}
17-
..addAll(_packageGraph.localPackages)) {
14+
Future<void> generate(PackageGraph packageGraph, FileWriter writer) {
15+
logProgress(packageGraph.defaultPackage.documentationAsHtml);
16+
for (var package in {packageGraph.defaultPackage}
17+
..addAll(packageGraph.localPackages)) {
1818
for (var category in filterNonDocumented(package.categories)) {
1919
logProgress(category.documentationAsHtml);
2020
}

lib/src/generator/html_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class HtmlGeneratorBackend extends DartdocGeneratorBackend {
5959
}
6060

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

lib/src/generator/html_resources.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// WARNING: This file is auto-generated. Do not taunt.
1+
// WARNING: This file is auto-generated. Do not edit.
22

3-
const List<String> resource_names = [
3+
const List<String> resourceNames = [
44
'package:dartdoc/resources/favicon.png',
55
'package:dartdoc/resources/github.css',
66
'package:dartdoc/resources/highlight.pack.js',

lib/src/generator/templates.aot_renderers_for_html.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// the variable is not used; generally when the section is checking if a
88
// non-bool, non-Iterable field is non-null.
99
// ignore_for_file: unused_local_variable
10+
// ignore_for_file: non_constant_identifier_names, unnecessary_string_escapes
1011

1112
import 'dart:convert' as _i19;
1213

0 commit comments

Comments
 (0)