Skip to content

Commit 39680a3

Browse files
authored
Quality of life developer tooling changes for dartdoc (#2070)
* Quality of life tooling changes for dartdoc * Add a CONTRIBUTING comment * Update appveyor call to grinder * Strip fragile checks from the sdk-analyzer test hack
1 parent 9263f70 commit 39680a3

File tree

10 files changed

+88
-34
lines changed

10 files changed

+88
-34
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ yet in the issue tracker, start by opening an issue. Thanks!
2626
3. Please include a test for your change. `dartdoc` has both `package:test`-style unittests as well as integration tests. To run the unittests, use `grind test`.
2727
4. For major changes, run `grind compare-sdk-warnings` and `grind compare-flutter-warnings`, and include the summary results in your pull request.
2828
5. Be sure to format your Dart code using `dartfmt -w`, otherwise travis will complain.
29-
6. Post your change via a pull request for review and integration!
29+
6. Use `grind presubmit` before creating a pull request to quickly check for common problems.
30+
7. Post your change via a pull request for review and integration!
3031

3132
## Testing
3233

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ install:
2323
build: off
2424

2525
test_script:
26-
- pub run grinder buildbot-no-publish
26+
- pub run grinder buildbot

lib/src/dartdoc_options.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ class DartdocOptionContext extends DartdocOptionContextBase
13761376

13771377
bool get injectHtml => optionSet['injectHtml'].valueAt(context);
13781378

1379-
bool get excludeFooterVersion => optionSet['excludeFooterVersion'].valueAt(context);
1379+
bool get excludeFooterVersion =>
1380+
optionSet['excludeFooterVersion'].valueAt(context);
13801381

13811382
ToolConfiguration get tools => optionSet['tools'].valueAt(context);
13821383

@@ -1420,8 +1421,7 @@ class DartdocOptionContext extends DartdocOptionContextBase
14201421
bool isPackageExcluded(String name) =>
14211422
excludePackages.any((pattern) => name == pattern);
14221423

1423-
String get templatesDir =>
1424-
optionSet['templatesDir'].valueAt(context);
1424+
String get templatesDir => optionSet['templatesDir'].valueAt(context);
14251425
}
14261426

14271427
/// Instantiate dartdoc's configuration file and options parser with the
@@ -1624,8 +1624,12 @@ Future<List<DartdocOption>> createDartdocOptions() async {
16241624
'exist. Executables for different platforms are specified by '
16251625
'giving the platform name as a key, and a list of strings as the '
16261626
'command.'),
1627-
DartdocOptionArgOnly<String>("templatesDir", null, isDir: true, mustExist: true, hide: true,
1628-
help: 'Path to a directory containing templates to use instead of the default ones. '
1627+
DartdocOptionArgOnly<String>("templatesDir", null,
1628+
isDir: true,
1629+
mustExist: true,
1630+
hide: true,
1631+
help:
1632+
'Path to a directory containing templates to use instead of the default ones. '
16291633
'Directory must contain an html file for each of the following: 404error, category, '
16301634
'class, constant, constructor, enum, function, index, library, method, mixin, '
16311635
'property, top_level_constant, top_level_property, typedef. Partial templates are '

lib/src/element_type.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ abstract class DefinedElementType extends ElementType {
329329
DartType get instantiatedType {
330330
if (_instantiatedType == null) {
331331
if (!interfaceType.typeArguments.every((t) => t is InterfaceType)) {
332-
_instantiatedType = packageGraph.typeSystem.instantiateToBounds(interfaceType);
332+
_instantiatedType =
333+
packageGraph.typeSystem.instantiateToBounds(interfaceType);
333334
} else {
334335
_instantiatedType = interfaceType;
335336
}

lib/src/html/html_generator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class HtmlGenerator extends Generator {
5959
String dirname = options?.templatesDir;
6060
if (dirname != null) {
6161
Directory templateDir = Directory(dirname);
62-
templates = await Templates.fromDirectory(
63-
templateDir,
62+
templates = await Templates.fromDirectory(templateDir,
6463
headerPaths: headers,
6564
footerPaths: footers,
6665
footerTextPaths: footerTexts);

lib/src/html/template_data.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ class MethodTemplateData extends TemplateData<Method> {
295295
@override
296296
Method get self => method;
297297
@override
298-
String get title => '${method.name} method - ${container.name} ${containerDesc} - '
298+
String get title =>
299+
'${method.name} method - ${container.name} ${containerDesc} - '
299300
'${library.name} library - Dart API';
300301
@override
301302
String get layoutTitle => _layoutTitle(
@@ -328,7 +329,8 @@ class PropertyTemplateData extends TemplateData<Field> {
328329
Field get self => property;
329330

330331
@override
331-
String get title => '${property.name} $type - ${container.name} ${containerDesc} - '
332+
String get title =>
333+
'${property.name} $type - ${container.name} ${containerDesc} - '
332334
'${library.name} library - Dart API';
333335
@override
334336
String get layoutTitle =>

lib/src/model/categorization.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
65
import 'package:dartdoc/src/model/model.dart';
76

87
final categoryRegexp = RegExp(
@@ -115,7 +114,7 @@ abstract class Categorization implements ModelElement {
115114
.map((n) => package.nameToCategory[n])
116115
.where((c) => c != null)
117116
.toList()
118-
..sort();
117+
..sort();
119118
}
120119
return _categories;
121120
}

lib/src/model/category.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:dartdoc/src/model/model.dart';
1010
import 'package:dartdoc/src/package_meta.dart';
1111
import 'package:dartdoc/src/warnings.dart';
1212

13-
1413
/// A category is a subcategory of a package, containing libraries tagged
1514
/// with a @category identifier.
1615
class Category extends Nameable

tool/grind.dart

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,42 @@ void analyze() async {
224224
);
225225
}
226226

227-
@Task('analyze, test, and self-test dartdoc')
228-
@Depends(analyze, checkBuild, test, testDartdoc)
229-
void buildbotNoPublish() => null;
227+
@Task('Check for dartfmt cleanliness')
228+
void dartfmt() async {
229+
if (Platform.version.contains('dev')) {
230+
List<String> filesToFix = [];
231+
// Filter out test packages as they always have strange formatting.
232+
// Passing parameters to dartfmt for directories to search results in
233+
// filenames being stripped of the dirname so we have to filter here.
234+
void addFileToFix(String fileName) {
235+
if (path.split(fileName).first == 'testing') return;
236+
filesToFix.add(fileName);
237+
}
230238

231-
@Task('analyze, test, and self-test dartdoc')
232-
@Depends(analyze, checkBuild, test, testDartdoc, tryPublish)
239+
log('Validating dartfmt with version ${Platform.version}');
240+
await SubprocessLauncher('dartfmt').runStreamed(
241+
sdkBin('dartfmt'),
242+
[
243+
'-n',
244+
'.',
245+
],
246+
perLine: addFileToFix);
247+
if (filesToFix.isNotEmpty) {
248+
fail(
249+
'dartfmt found files needing reformatting. Use this command to reformat:\n'
250+
'dartfmt -w ${filesToFix.map((f) => "\'$f\'").join(' ')}');
251+
}
252+
} else {
253+
log('Skipping dartfmt check, requires latest dev version of SDK');
254+
}
255+
}
256+
257+
@Task('Run quick presubmit checks.')
258+
@Depends(analyze, checkBuild, smokeTest, dartfmt, tryPublish)
259+
void presubmit() => null;
260+
261+
@Task('Run long tests, self-test dartdoc, and run the publish test')
262+
@Depends(presubmit, test, testDartdoc)
233263
void buildbot() => null;
234264

235265
@Task('Generate docs for the Dart SDK')
@@ -846,26 +876,49 @@ Future<void> checkBuild() async {
846876
@Task('Dry run of publish to pub.dartlang')
847877
@Depends(checkChangelogHasVersion)
848878
Future<void> tryPublish() async {
849-
var launcher = SubprocessLauncher('try-publish');
850-
await launcher.runStreamed(sdkBin('pub'), ['publish', '-n']);
879+
if (Platform.version.contains('dev')) {
880+
log('Skipping publish check -- requires a stable version of the SDK');
881+
} else {
882+
var launcher = SubprocessLauncher('try-publish');
883+
await launcher.runStreamed(sdkBin('pub'), ['publish', '-n']);
884+
}
885+
}
886+
887+
@Task('Run a smoke test, only')
888+
Future<void> smokeTest() async {
889+
await testDart2(smokeTestFiles);
890+
await testFutures.wait();
891+
}
892+
893+
@Task('Run non-smoke tests, only')
894+
Future<void> longTest() async {
895+
await testDart2(testFiles);
896+
await testFutures.wait();
851897
}
852898

853899
@Task('Run all the tests.')
854900
Future<void> test() async {
855-
await testDart2();
901+
await testDart2(smokeTestFiles.followedBy(testFiles));
856902
await testFutures.wait();
857903
}
858904

905+
List<File> get smokeTestFiles => Directory('test')
906+
.listSync(recursive: true)
907+
.whereType<File>()
908+
.where((e) => path.basename(e.path) == 'model_test.dart')
909+
.toList();
910+
859911
List<File> get testFiles => Directory('test')
860912
.listSync(recursive: true)
861-
.where((e) => e is File && e.path.endsWith('test.dart'))
862-
.cast<File>()
913+
.whereType<File>()
914+
.where((e) => e.path.endsWith('test.dart'))
915+
.where((e) => path.basename(e.path) != 'model_test.dart')
863916
.toList();
864917

865-
Future<void> testDart2() async {
918+
Future<void> testDart2(Iterable<File> tests) async {
866919
List<String> parameters = ['--enable-asserts'];
867920

868-
for (File dartFile in testFiles) {
921+
for (File dartFile in tests) {
869922
await testFutures.addFutureFromClosure(() =>
870923
CoverageSubprocessLauncher('dart2-${path.basename(dartFile.path)}')
871924
.runStreamed(

tool/travis.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ elif [ "$DARTDOC_BOT" = "packages" ]; then
3737
PACKAGE_NAME=flutter_plugin_tools PACKAGE_VERSION=">=0.0.14+1" pub run grinder build-pub-package 2>&1 | grep "dartdoc failed: dartdoc could not find any libraries to document.$"
3838
PACKAGE_NAME=shelf_exception_handler PACKAGE_VERSION=">=0.2.0" pub run grinder build-pub-package
3939
elif [ "$DARTDOC_BOT" = "sdk-analyzer" ]; then
40-
echo "Running main dartdoc bot against the SDK analyzer"
40+
echo "Running all tests against the SDK analyzer"
4141
unset COVERAGE_TOKEN
42-
DARTDOC_GRIND_STEP=buildbot-no-publish pub run grinder test-with-analyzer-sdk
42+
pub run grinder test-with-analyzer-sdk
4343
else
4444
echo "Running main dartdoc bot"
45-
if echo "${DART_VERSION}" | grep -q dev ; then
46-
pub run grinder buildbot-no-publish
47-
else
48-
pub run grinder buildbot
49-
fi
45+
pub run grinder buildbot
5046
if [ -n "$COVERAGE_TOKEN" ] ; then
5147
coveralls-lcov --repo-token="${COVERAGE_TOKEN}" lcov.info
5248
fi

0 commit comments

Comments
 (0)