Skip to content

Commit d40b877

Browse files
authored
Fix a few code style nits according to Effective Dart: (#2610)
Fix a few code style nits according to Effective Dart: * [DON’T use a leading underscore for identifiers that aren’t private.](https://dart.dev/guides/language/effective-dart/style#dont-use-a-leading-underscore-for-identifiers-that-arent-private) * [DO follow a consistent rule for `var` and `final` on local variables.](https://dart.dev/guides/language/effective-dart/usage#do-follow-a-consistent-rule-for-var-and-final-on-local-variables) Additionally: * cleaned up comments to use backticks and references * use collection-for when declaring a Map, instead of using MapEntries.
1 parent 837d112 commit d40b877

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

lib/dartdoc.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ class Dartdoc {
171171
/// thrown if dartdoc fails in an expected way, for example if there is an
172172
/// analysis error in the code.
173173
Future<DartdocResults> generateDocsBase() async {
174-
var _stopwatch = Stopwatch()..start();
174+
var stopwatch = Stopwatch()..start();
175175
double seconds;
176176
packageGraph = await packageBuilder.buildPackageGraph();
177-
seconds = _stopwatch.elapsedMilliseconds / 1000.0;
177+
seconds = stopwatch.elapsedMilliseconds / 1000.0;
178178
var libs = packageGraph.libraries.length;
179179
logInfo("Initialized dartdoc with $libs librar${libs == 1 ? 'y' : 'ies'} "
180180
'in ${seconds.toStringAsFixed(1)} seconds');
181-
_stopwatch.reset();
181+
stopwatch.reset();
182182

183-
final generator = this.generator;
183+
var generator = this.generator;
184184
if (generator != null) {
185185
// Create the out directory.
186186
if (!outputDir.exists) outputDir.create();
@@ -203,7 +203,7 @@ class Dartdoc {
203203
"and $errors ${pluralize('error', errors)}.");
204204
}
205205

206-
seconds = _stopwatch.elapsedMilliseconds / 1000.0;
206+
seconds = stopwatch.elapsedMilliseconds / 1000.0;
207207
libs = packageGraph.localPublicLibraries.length;
208208
logInfo("Documented $libs public librar${libs == 1 ? 'y' : 'ies'} "
209209
'in ${seconds.toStringAsFixed(1)} seconds');

lib/src/model/categorization.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ abstract class Categorization implements ModelElement {
1818
String buildDocumentationAddition(String rawDocs) =>
1919
_stripAndSetDartdocCategories(rawDocs ??= '');
2020

21-
/// Parse {@category ...} and related information in API comments, stripping
21+
/// Parse `{@category ...}` and related information in API comments, stripping
2222
/// out that information from the given comments and returning the stripped
2323
/// version.
2424
String _stripAndSetDartdocCategories(String rawDocs) {
25-
var _categorySet = <String>{};
26-
var _subCategorySet = <String>{};
25+
var categorySet = <String>{};
26+
var subCategorySet = <String>{};
2727
_hasCategorization = false;
2828

2929
rawDocs = rawDocs.replaceAllMapped(_categoryRegExp, (match) {
3030
_hasCategorization = true;
3131
switch (match[1]) {
3232
case 'category':
3333
case 'api':
34-
_categorySet.add(match[2].trim());
34+
categorySet.add(match[2].trim());
3535
break;
3636
case 'subCategory':
37-
_subCategorySet.add(match[2].trim());
37+
subCategorySet.add(match[2].trim());
3838
break;
3939
case 'image':
4040
_image = match[2].trim();
@@ -46,8 +46,8 @@ abstract class Categorization implements ModelElement {
4646
return '';
4747
});
4848

49-
_categoryNames = _categorySet.toList()..sort();
50-
_subCategoryNames = _subCategorySet.toList()..sort();
49+
_categoryNames = categorySet.toList()..sort();
50+
_subCategoryNames = subCategorySet.toList()..sort();
5151
_image ??= '';
5252
_samples ??= '';
5353
return rawDocs;

lib/src/model/library.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:collection';
66

7-
import 'package:analyzer/dart/analysis/results.dart';
87
import 'package:analyzer/dart/ast/ast.dart';
98
import 'package:analyzer/dart/element/element.dart';
109
import 'package:analyzer/dart/element/type_system.dart';
@@ -73,13 +72,13 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
7372
var element = resolvedLibrary.result.element;
7473
if (element == null) throw ArgumentError.notNull('element');
7574

76-
// Initialize [packageGraph]'s cache of ModelNodes for relevant
75+
// Initialize [packageGraph]'s cache of [ModelNode]s for relevant
7776
// elements in this library.
78-
var _compilationUnitMap = <String, CompilationUnit>{};
79-
_compilationUnitMap.addEntries(resolvedLibrary.result.units
80-
.map((ResolvedUnitResult u) => MapEntry(u.path, u.unit)));
77+
var compilationUnitMap = <String, CompilationUnit>{
78+
for (var unit in resolvedLibrary.result.units) unit.path: unit.unit,
79+
};
8180
_HashableChildLibraryElementVisitor((Element e) =>
82-
packageGraph.populateModelNodeFor(e, _compilationUnitMap))
81+
packageGraph.populateModelNodeFor(e, compilationUnitMap))
8382
.visitElement(element);
8483

8584
var exportedAndLocalElements = {

test/end2end/dartdoc_integration_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ void main() {
227227
}, timeout: Timeout.factor(2));
228228

229229
test('--footer-text excludes version', () async {
230-
var _testPackagePath = path.fromUri(
230+
var testPackagePath = path.fromUri(
231231
_currentFileUri.resolve('../../testing/test_package_options'));
232232

233233
var args = <String>[dartdocPath, '--output', tempDir.path];
234234

235235
await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
236-
workingDirectory: _testPackagePath);
236+
workingDirectory: testPackagePath);
237237

238238
var outFile = File(path.join(tempDir.path, 'index.html'));
239239
var footerRegex =

0 commit comments

Comments
 (0)