Skip to content

Commit 604767f

Browse files
authored
Allow fine-grained warning control with flags and dartdoc_options.yaml files (#1891)
* basic tests working * dartfmt * Rebuild test package docs * update test package docs * handle some nulls * seems to work now even in mixed prefix case * rebuild stable docs * dartfmt * Rebuild test package docs * Beginnings of some better warning support * add comment * Rewritten warnings pass original tests (but no new tests yet) * Disallow local by default * fix null element warnings * add test for warning control * dartfmt * Update README * Remove an unused getter and fix typo in README
1 parent ea0392e commit 604767f

File tree

6 files changed

+435
-170
lines changed

6 files changed

+435
-170
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ authoring doc comments for Dart with `dartdoc`.
102102
Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc
103103
generates docs.
104104

105-
An example:
105+
An example (not necessarily recommended settings):
106106

107107
```yaml
108108
dartdoc:
@@ -119,6 +119,12 @@ dartdoc:
119119
linkTo:
120120
url: "https://my.dartdocumentationsite.org/dev/%v%"
121121
showUndocumentedCategories: true
122+
ignore:
123+
- ambiguous-doc-reference
124+
errors:
125+
- unresolved-doc-reference
126+
warnings:
127+
- tool-error
122128
```
123129
124130
Unrecognized options will be ignored. Supported options:
@@ -133,10 +139,14 @@ Unrecognized options will be ignored. Supported options:
133139
directives.
134140
* **exclude**: Specify a list of library names to avoid generating docs for,
135141
overriding any specified in include.
142+
* **errors**: Specify warnings to be treated as errors. See the lists of valid warnings in the command
143+
line help for `--errors`, `--warnings`, and `--ignore`.
136144
* **favicon**: A path to a favicon for the generated docs.
137145
* **footer**: A list of paths to footer files containing HTML text.
138146
* **footerText**: A list of paths to text files for optional text next to the package name and version
139147
* **header**: A list of paths to header files containing HTML text.
148+
* **ignore**: Specify warnings to be completely ignored. See the lists of valid warnings in the command
149+
line help for `--errors`, `--warnings`, and `--ignore`.
140150
* **include**: Specify a list of library names to generate docs for, ignoring all others.
141151
* **includeExternal**: Specify a list of library filenames to add to the list of documented libraries.
142152
* **linkTo**: For other packages depending on this one, if this map is defined those packages
@@ -152,6 +162,8 @@ Unrecognized options will be ignored. Supported options:
152162
No branch is considered to be "stable".
153163
* `%n%`: The name of this package, as defined in pubspec.yaml.
154164
* `%v%`: The version of this package as defined in pubspec.yaml.
165+
* **warnings**: Specify otherwise ignored or set-to-error warnings to simply warn. See the lists
166+
of valid warnings in the command line help for `--errors`, `--warnings`, and `--ignore`.
155167

156168
In general, paths are relative to the directory the dartdoc_options.yaml the option is defined in
157169
and should be specified as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.

lib/dartdoc.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class Dartdoc extends PackageBuilder {
131131
final int errorCount =
132132
dartdocResults.packageGraph.packageWarningCounter.errorCount;
133133
if (errorCount > 0) {
134-
dartdocResults.packageGraph.flushWarnings();
135134
throw new DartdocFailure(
136135
"dartdoc encountered $errorCount} errors while processing.");
137136
}

lib/src/dartdoc_options.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'package:dartdoc/src/experiment_options.dart';
2424
import 'package:dartdoc/src/io_utils.dart';
2525
import 'package:dartdoc/src/tool_runner.dart';
2626
import 'package:dartdoc/src/tuple.dart';
27+
import 'package:dartdoc/src/warnings.dart';
2728
import 'package:path/path.dart' as pathLib;
2829
import 'package:yaml/yaml.dart';
2930

@@ -1271,7 +1272,7 @@ abstract class DartdocOptionContextBase {
12711272
/// a single [ModelElement], [Package], [Category] and so forth has a single context
12721273
/// and so this can be made a member variable of those structures.
12731274
class DartdocOptionContext extends DartdocOptionContextBase
1274-
with DartdocExperimentOptionContext {
1275+
with DartdocExperimentOptionContext, PackageWarningOptionContext {
12751276
@override
12761277
final DartdocOptionSet optionSet;
12771278
@override
@@ -1357,12 +1358,10 @@ class DartdocOptionContext extends DartdocOptionContextBase
13571358
String get sdkDir => optionSet['sdkDir'].valueAt(context);
13581359
bool get showUndocumentedCategories =>
13591360
optionSet['showUndocumentedCategories'].valueAt(context);
1360-
bool get showWarnings => optionSet['showWarnings'].valueAt(context);
13611361
PackageMeta get topLevelPackageMeta =>
13621362
optionSet['topLevelPackageMeta'].valueAt(context);
13631363
bool get useCategories => optionSet['useCategories'].valueAt(context);
13641364
bool get validateLinks => optionSet['validateLinks'].valueAt(context);
1365-
bool get verboseWarnings => optionSet['verboseWarnings'].valueAt(context);
13661365

13671366
bool isLibraryExcluded(String name) =>
13681367
exclude.any((pattern) => name == pattern);
@@ -1540,8 +1539,6 @@ Future<List<DartdocOption>> createDartdocOptions() async {
15401539
}, help: 'Path to the SDK directory.', isDir: true, mustExist: true),
15411540
new DartdocOptionArgFile<bool>('showUndocumentedCategories', false,
15421541
help: "Label categories that aren't documented", negatable: true),
1543-
new DartdocOptionArgOnly<bool>('showWarnings', false,
1544-
help: 'Display all warnings.'),
15451542
new DartdocOptionSyntheticOnly<PackageMeta>('topLevelPackageMeta',
15461543
(DartdocSyntheticOption<PackageMeta> option, Directory dir) {
15471544
PackageMeta packageMeta = new PackageMeta.fromDir(
@@ -1574,5 +1571,7 @@ Future<List<DartdocOption>> createDartdocOptions() async {
15741571
'command.'),
15751572
// TODO(jcollins-g): refactor so there is a single static "create" for
15761573
// each DartdocOptionContext that traverses the inheritance tree itself.
1577-
]..addAll(await createExperimentOptions());
1574+
]
1575+
..addAll(await createExperimentOptions())
1576+
..addAll(await createPackageWarningOptions());
15781577
}

lib/src/model.dart

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,7 @@ abstract class ModelElement extends Canonicalization
36323632
@override
36333633
PackageGraph get packageGraph => _packageGraph;
36343634

3635+
@override
36353636
Package get package => library.package;
36363637

36373638
bool get isPublicAndPackageDocumented =>
@@ -4621,15 +4622,10 @@ class Operator extends Method {
46214622

46224623
class PackageGraph {
46234624
PackageGraph.UninitializedPackageGraph(
4624-
this.config,
4625-
PackageWarningOptions packageWarningOptions,
4626-
this.driver,
4627-
this.sdk,
4628-
this.hasEmbedderSdk)
4625+
this.config, this.driver, this.sdk, this.hasEmbedderSdk)
46294626
: packageMeta = config.topLevelPackageMeta,
4630-
session = driver.currentSession,
4631-
_packageWarningCounter =
4632-
new PackageWarningCounter(packageWarningOptions) {
4627+
session = driver.currentSession {
4628+
_packageWarningCounter = new PackageWarningCounter(this);
46334629
// Make sure the default package exists, even if it has no libraries.
46344630
// This can happen for packages that only contain embedder SDKs.
46354631
new Package.fromPackageMeta(packageMeta, this);
@@ -4815,14 +4811,6 @@ class PackageGraph {
48154811
return (_allRootDirs.contains(element.library.packageMeta?.resolvedDir));
48164812
}
48174813

4818-
/// Flush out any warnings we might have collected while
4819-
/// [PackageWarningOptions.autoFlush] was false.
4820-
void flushWarnings() {
4821-
_packageWarningCounter.maybeFlush();
4822-
}
4823-
4824-
Tuple2<int, int> get lineAndColumn => null;
4825-
48264814
PackageWarningCounter get packageWarningCounter => _packageWarningCounter;
48274815

48284816
final Set<Tuple3<Element, PackageWarning, String>> _warnAlreadySeen =
@@ -4871,6 +4859,7 @@ class PackageGraph {
48714859
return;
48724860
}
48734861
// Some kinds of warnings it is OK to drop if we're not documenting them.
4862+
// TODO(jcollins-g): drop this and use new flag system instead.
48744863
if (warnable != null &&
48754864
skipWarningIfNotDocumentedFor.contains(kind) &&
48764865
!warnable.isDocumented) {
@@ -5610,6 +5599,7 @@ class Category extends Nameable
56105599
Indexable
56115600
implements Documentable {
56125601
/// All libraries in [libraries] must come from [package].
5602+
@override
56135603
Package package;
56145604
String _name;
56155605
@override
@@ -5965,6 +5955,9 @@ class Package extends LibraryContainer
59655955
@override
59665956
String get name => _name;
59675957

5958+
@override
5959+
Package get package => this;
5960+
59685961
@override
59695962
PackageGraph get packageGraph => _packageGraph;
59705963

@@ -6360,7 +6353,7 @@ class PackageBuilder {
63606353
}
63616354

63626355
PackageGraph newGraph = new PackageGraph.UninitializedPackageGraph(
6363-
config, getWarningOptions(), driver, sdk, hasEmbedderSdkFiles);
6356+
config, driver, sdk, hasEmbedderSdkFiles);
63646357
await getLibraries(newGraph);
63656358
await newGraph.initializePackageGraph();
63666359
return newGraph;
@@ -6480,25 +6473,6 @@ class PackageBuilder {
64806473
return _driver;
64816474
}
64826475

6483-
PackageWarningOptions getWarningOptions() {
6484-
PackageWarningOptions warningOptions =
6485-
new PackageWarningOptions(config.verboseWarnings);
6486-
// TODO(jcollins-g): explode this into detailed command line options.
6487-
for (PackageWarning kind in PackageWarning.values) {
6488-
switch (kind) {
6489-
case PackageWarning.toolError:
6490-
case PackageWarning.invalidParameter:
6491-
case PackageWarning.unresolvedExport:
6492-
warningOptions.error(kind);
6493-
break;
6494-
default:
6495-
if (config.showWarnings) warningOptions.warn(kind);
6496-
break;
6497-
}
6498-
}
6499-
return warningOptions;
6500-
}
6501-
65026476
/// Return an Iterable with the sdk files we should parse.
65036477
/// Filter can be String or RegExp (technically, anything valid for
65046478
/// [String.contains])

0 commit comments

Comments
 (0)