Skip to content

Allow fine-grained warning control with flags and dartdoc_options.yaml files #1891

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 24 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f88067b
basic tests working
jcollins-g Dec 18, 2018
c4a1018
dartfmt
jcollins-g Dec 18, 2018
de5d816
Rebuild test package docs
jcollins-g Dec 18, 2018
8950883
update test package docs
jcollins-g Dec 18, 2018
491a4c9
handle some nulls
jcollins-g Dec 19, 2018
1acde1b
seems to work now even in mixed prefix case
jcollins-g Dec 19, 2018
f2a3b61
rebuild stable docs
jcollins-g Dec 19, 2018
4ecbffa
dartfmt
jcollins-g Dec 19, 2018
1cb8d3e
Merge branch 'master' into prefix-support-dartdoc
jcollins-g Dec 19, 2018
b02b323
Rebuild test package docs
jcollins-g Dec 19, 2018
dbfa46d
Beginnings of some better warning support
jcollins-g Dec 19, 2018
747a738
add comment
jcollins-g Dec 20, 2018
b2f3f32
Merge branch 'prefix-support-dartdoc' into prefix-support-dartdoc+war…
jcollins-g Jan 2, 2019
82eaa34
Merge branch 'master' into prefix-support-dartdoc+warning-control
jcollins-g Jan 7, 2019
d8a6146
Merge branch 'master' into warning-control
jcollins-g Jan 7, 2019
41d6192
Rewritten warnings pass original tests (but no new tests yet)
jcollins-g Jan 8, 2019
955fc93
Disallow local by default
jcollins-g Jan 8, 2019
28277fe
fix null element warnings
jcollins-g Jan 8, 2019
9cb277f
add test for warning control
jcollins-g Jan 8, 2019
530af4f
dartfmt
jcollins-g Jan 8, 2019
9897f83
Update README
jcollins-g Jan 8, 2019
79597f2
Merge branch 'master' into warning-control
jcollins-g Jan 8, 2019
88480bd
Remove an unused getter and fix typo in README
jcollins-g Jan 8, 2019
0328e04
Merge branch 'master' into warning-control
jcollins-g Jan 9, 2019
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ authoring doc comments for Dart with `dartdoc`.
Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc
generates docs.

An example:
An example (not necessarily recommended settings):

```yaml
dartdoc:
Expand All @@ -119,6 +119,12 @@ dartdoc:
linkTo:
url: "https://my.dartdocumentationsite.org/dev/%v%"
showUndocumentedCategories: true
ignore:
- ambiguous-doc-reference
errors:
- unresolved-doc-reference
warnings:
- tool-error
```

Unrecognized options will be ignored. Supported options:
Expand All @@ -133,10 +139,14 @@ Unrecognized options will be ignored. Supported options:
directives.
* **exclude**: Specify a list of library names to avoid generating docs for,
overriding any specified in include.
* **errors**: Specify warnings to be treated as errors. See the lists of valid warnings in the command
line help for `--errors`, `--warnings`, and `--ignore`.
* **favicon**: A path to a favicon for the generated docs.
* **footer**: A list of paths to footer files containing HTML text.
* **footerText**: A list of paths to text files for optional text next to the package name and version
* **header**: A list of paths to header files containing HTML text.
* **ignore**: Specify warnings to be completely ignored. See the lists of valid warnings in the command
line help for `--errors`, `--warnings`, and `--ignore`.
* **include**: Specify a list of library names to generate docs for, ignoring all others.
* **includeExternal**: Specify a list of library filenames to add to the list of documented libraries.
* **linkTo**: For other packages depending on this one, if this map is defined those packages
Expand All @@ -152,6 +162,8 @@ Unrecognized options will be ignored. Supported options:
No branch is considered to be "stable".
* `%n%`: The name of this package, as defined in pubspec.yaml.
* `%v%`: The version of this package as defined in pubspec.yaml.
* **warnings**: Specify otherwise ignored or set-to-error warnings to simply warn. See the lists
of valid warnings in the command line help for `--errors`, `--warnings`, and `--ignore`.

In general, paths are relative to the directory the dartdoc_options.yaml the option is defined in
and should be specified as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.
Expand Down
1 change: 0 additions & 1 deletion lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class Dartdoc extends PackageBuilder {
final int errorCount =
dartdocResults.packageGraph.packageWarningCounter.errorCount;
if (errorCount > 0) {
dartdocResults.packageGraph.flushWarnings();
throw new DartdocFailure(
"dartdoc encountered $errorCount} errors while processing.");
}
Expand Down
11 changes: 5 additions & 6 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:dartdoc/src/experiment_options.dart';
import 'package:dartdoc/src/io_utils.dart';
import 'package:dartdoc/src/tool_runner.dart';
import 'package:dartdoc/src/tuple.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:path/path.dart' as pathLib;
import 'package:yaml/yaml.dart';

Expand Down Expand Up @@ -1271,7 +1272,7 @@ abstract class DartdocOptionContextBase {
/// a single [ModelElement], [Package], [Category] and so forth has a single context
/// and so this can be made a member variable of those structures.
class DartdocOptionContext extends DartdocOptionContextBase
with DartdocExperimentOptionContext {
with DartdocExperimentOptionContext, PackageWarningOptionContext {
@override
final DartdocOptionSet optionSet;
@override
Expand Down Expand Up @@ -1357,12 +1358,10 @@ class DartdocOptionContext extends DartdocOptionContextBase
String get sdkDir => optionSet['sdkDir'].valueAt(context);
bool get showUndocumentedCategories =>
optionSet['showUndocumentedCategories'].valueAt(context);
bool get showWarnings => optionSet['showWarnings'].valueAt(context);
PackageMeta get topLevelPackageMeta =>
optionSet['topLevelPackageMeta'].valueAt(context);
bool get useCategories => optionSet['useCategories'].valueAt(context);
bool get validateLinks => optionSet['validateLinks'].valueAt(context);
bool get verboseWarnings => optionSet['verboseWarnings'].valueAt(context);

bool isLibraryExcluded(String name) =>
exclude.any((pattern) => name == pattern);
Expand Down Expand Up @@ -1540,8 +1539,6 @@ Future<List<DartdocOption>> createDartdocOptions() async {
}, help: 'Path to the SDK directory.', isDir: true, mustExist: true),
new DartdocOptionArgFile<bool>('showUndocumentedCategories', false,
help: "Label categories that aren't documented", negatable: true),
new DartdocOptionArgOnly<bool>('showWarnings', false,
help: 'Display all warnings.'),
new DartdocOptionSyntheticOnly<PackageMeta>('topLevelPackageMeta',
(DartdocSyntheticOption<PackageMeta> option, Directory dir) {
PackageMeta packageMeta = new PackageMeta.fromDir(
Expand Down Expand Up @@ -1574,5 +1571,7 @@ Future<List<DartdocOption>> createDartdocOptions() async {
'command.'),
// TODO(jcollins-g): refactor so there is a single static "create" for
// each DartdocOptionContext that traverses the inheritance tree itself.
]..addAll(await createExperimentOptions());
]
..addAll(await createExperimentOptions())
..addAll(await createPackageWarningOptions());
}
46 changes: 10 additions & 36 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,7 @@ abstract class ModelElement extends Canonicalization
@override
PackageGraph get packageGraph => _packageGraph;

@override
Package get package => library.package;

bool get isPublicAndPackageDocumented =>
Expand Down Expand Up @@ -4621,15 +4622,10 @@ class Operator extends Method {

class PackageGraph {
PackageGraph.UninitializedPackageGraph(
this.config,
PackageWarningOptions packageWarningOptions,
this.driver,
this.sdk,
this.hasEmbedderSdk)
this.config, this.driver, this.sdk, this.hasEmbedderSdk)
: packageMeta = config.topLevelPackageMeta,
session = driver.currentSession,
_packageWarningCounter =
new PackageWarningCounter(packageWarningOptions) {
session = driver.currentSession {
_packageWarningCounter = new PackageWarningCounter(this);
// Make sure the default package exists, even if it has no libraries.
// This can happen for packages that only contain embedder SDKs.
new Package.fromPackageMeta(packageMeta, this);
Expand Down Expand Up @@ -4815,14 +4811,6 @@ class PackageGraph {
return (_allRootDirs.contains(element.library.packageMeta?.resolvedDir));
}

/// Flush out any warnings we might have collected while
/// [PackageWarningOptions.autoFlush] was false.
void flushWarnings() {
_packageWarningCounter.maybeFlush();
}

Tuple2<int, int> get lineAndColumn => null;

PackageWarningCounter get packageWarningCounter => _packageWarningCounter;

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

@override
Package get package => this;

@override
PackageGraph get packageGraph => _packageGraph;

Expand Down Expand Up @@ -6360,7 +6353,7 @@ class PackageBuilder {
}

PackageGraph newGraph = new PackageGraph.UninitializedPackageGraph(
config, getWarningOptions(), driver, sdk, hasEmbedderSdkFiles);
config, driver, sdk, hasEmbedderSdkFiles);
await getLibraries(newGraph);
await newGraph.initializePackageGraph();
return newGraph;
Expand Down Expand Up @@ -6480,25 +6473,6 @@ class PackageBuilder {
return _driver;
}

PackageWarningOptions getWarningOptions() {
PackageWarningOptions warningOptions =
new PackageWarningOptions(config.verboseWarnings);
// TODO(jcollins-g): explode this into detailed command line options.
for (PackageWarning kind in PackageWarning.values) {
switch (kind) {
case PackageWarning.toolError:
case PackageWarning.invalidParameter:
case PackageWarning.unresolvedExport:
warningOptions.error(kind);
break;
default:
if (config.showWarnings) warningOptions.warn(kind);
break;
}
}
return warningOptions;
}

/// Return an Iterable with the sdk files we should parse.
/// Filter can be String or RegExp (technically, anything valid for
/// [String.contains])
Expand Down
Loading