Skip to content

Fix a few code style nits according to Effective Dart: #2610

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

Merged
merged 2 commits into from
Apr 8, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ class Dartdoc {
/// thrown if dartdoc fails in an expected way, for example if there is an
/// analysis error in the code.
Future<DartdocResults> generateDocsBase() async {
var _stopwatch = Stopwatch()..start();
var stopwatch = Stopwatch()..start();
double seconds;
packageGraph = await packageBuilder.buildPackageGraph();
seconds = _stopwatch.elapsedMilliseconds / 1000.0;
seconds = stopwatch.elapsedMilliseconds / 1000.0;
var libs = packageGraph.libraries.length;
logInfo("Initialized dartdoc with $libs librar${libs == 1 ? 'y' : 'ies'} "
'in ${seconds.toStringAsFixed(1)} seconds');
_stopwatch.reset();
stopwatch.reset();

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

seconds = _stopwatch.elapsedMilliseconds / 1000.0;
seconds = stopwatch.elapsedMilliseconds / 1000.0;
libs = packageGraph.localPublicLibraries.length;
logInfo("Documented $libs public librar${libs == 1 ? 'y' : 'ies'} "
'in ${seconds.toStringAsFixed(1)} seconds');
Expand Down
14 changes: 7 additions & 7 deletions lib/src/model/categorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ abstract class Categorization implements ModelElement {
String buildDocumentationAddition(String rawDocs) =>
_stripAndSetDartdocCategories(rawDocs ??= '');

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

rawDocs = rawDocs.replaceAllMapped(_categoryRegExp, (match) {
_hasCategorization = true;
switch (match[1]) {
case 'category':
case 'api':
_categorySet.add(match[2].trim());
categorySet.add(match[2].trim());
break;
case 'subCategory':
_subCategorySet.add(match[2].trim());
subCategorySet.add(match[2].trim());
break;
case 'image':
_image = match[2].trim();
Expand All @@ -46,8 +46,8 @@ abstract class Categorization implements ModelElement {
return '';
});

_categoryNames = _categorySet.toList()..sort();
_subCategoryNames = _subCategorySet.toList()..sort();
_categoryNames = categorySet.toList()..sort();
_subCategoryNames = subCategorySet.toList()..sort();
_image ??= '';
_samples ??= '';
return rawDocs;
Expand Down
11 changes: 5 additions & 6 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:collection';

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

// Initialize [packageGraph]'s cache of ModelNodes for relevant
// Initialize [packageGraph]'s cache of [ModelNode]s for relevant
// elements in this library.
var _compilationUnitMap = <String, CompilationUnit>{};
_compilationUnitMap.addEntries(resolvedLibrary.result.units
.map((ResolvedUnitResult u) => MapEntry(u.path, u.unit)));
var compilationUnitMap = <String, CompilationUnit>{
for (var unit in resolvedLibrary.result.units) unit.path: unit.unit,
};
_HashableChildLibraryElementVisitor((Element e) =>
packageGraph.populateModelNodeFor(e, _compilationUnitMap))
packageGraph.populateModelNodeFor(e, compilationUnitMap))
.visitElement(element);

var exportedAndLocalElements = {
Expand Down
4 changes: 2 additions & 2 deletions test/end2end/dartdoc_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ void main() {
}, timeout: Timeout.factor(2));

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

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

await subprocessLauncher.runStreamed(Platform.resolvedExecutable, args,
workingDirectory: _testPackagePath);
workingDirectory: testPackagePath);

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