Skip to content

Add warnings for "free-hanging" generics in docs [#1250] #1313

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

Conversation

astashov
Copy link
Contributor

@Hixie asked for warnings when the generics are "free-hanging", and not
wrapped into [] block (like Apple<Cat>, but not [Apple<Cat>]). This
commit adds those warnings. We try to find the tags, which are not
wrapped into square brackets, which are not from the whitelist of
possible HTML tags.

Also, now output all the warnings to the console:

  • When there's a missing reference in the comments
  • When there're ambiguous reference in the comments
  • When there're "free-hanging" generics

But that generates TONS AND TONS of warnings when you e.g. generate Dart
SDK docs or Flutter docs. So, I've added the flag --show-warnings,
without it we don't show the warnings.

Fixes #1250

@Hixie asked for warnings when the generics are "free-hanging", and not
wrapped into [] block (like `Apple<Cat>`, but not `[Apple<Cat>]`). This
commit adds those warnings. We try to find the tags, which are not
wrapped into square brackets, which are not from the whitelist of
possible HTML tags.

Also, now output all the warnings to the console:

* When there's a missing reference in the comments
* When there're ambiguous reference in the comments
* When there're "free-hanging" generics

But that generates TONS AND TONS of warnings when you e.g. generate Dart
SDK docs or Flutter docs. So, I've added the flag `--show-warnings`,
without it we don't show the warnings.
@googlebot googlebot added the cla: yes Google CLA check succeeded. label Dec 29, 2016
import 'reporting.dart';

const validHtmlTags = const [
"a", "abbr", "address", "area", "article", "aside", "audio", "b", "base",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably comment out the following tags:

  • base
  • body
  • embed
  • head
  • html
  • rb
  • rtc

Where did you get the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://html.spec.whatwg.org/#elements-3 would be a more authoritative source

// TODO: Could handle fatal warnings here, or print to stderr, or remember
// that we had at least one warning, and exit with non-null exit code in this case.
if (config != null && config.showWarnings) {
print("warning: ${message}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably print to stderr here (stderr.writeln()).

@@ -0,0 +1,11 @@
library reporting;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a copyright header (available in the other files).

if (config != null && config.showWarnings) {
print("warning: ${message}");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: end in an eol

@@ -0,0 +1,27 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2016

// TODO: add --fatal-warning, which would make the app crash in case of ambiguous references
print(
"Ambiguous reference to [${codeRef}] in '${element.fullyQualifiedName}' (${element.sourceFileName}:${element.lineNumber}). " +
warning(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to adding a warning() method

return '<code>${HTML_ESCAPE.convert(label)}</code>';
}
}

String _elementSource(ModelElement element) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_elementLocation?

List<int> tagPositions = findFreeHangingGenericsPositions(text);
if (tagPositions.isNotEmpty) {
tagPositions.forEach((int position) {
String errorMessage = "There's a generic type handled as HTML";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps: Generic type handled as HTML .

int squareBracketsDepth = 0;
List<int> results = [];
while (true) {
final nextOpenBracket = string.indexOf("[", currentPosition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a type annotation here (and below)

@devoncarew
Copy link
Member

Awesome! Some suggested changes (in addition to the one that @Hixie pointed out). Can you also include some sample output (just in a reply to the PR) of it finding warnings?

@astashov
Copy link
Contributor Author

astashov commented Jan 3, 2017

Warnings:

warning: Generic type handled as HTML in 'material.AppBar.actions' (/Users/anton/projects/flutter/packages/flutter/lib/src/material/app_bar.dart:205) - 'rld'),
    actions: <Widget>[
      new '
warning: unresolved doc reference 'Scaffold' (in 'material.AppBar.bottomHeight' (/Users/anton/projects/flutter/packages/flutter/lib/src/material/app_bar.dart:null)
warning: Ambiguous reference to [WidgetsBinding.beginFrame] in 'widgets.debugPrintBuildScope' (/Users/anton/projects/flutter/packages/flutter/lib/src/widgets/debug.dart:35). We found matches to the following elements: 'widgets.WidgetsBinding.beginFrame', 'material.WidgetsBinding.beginFrame'

@astashov
Copy link
Contributor Author

astashov commented Jan 3, 2017

@devoncarew PTAL

@keertip keertip merged commit 91c9ed9 into dart-lang:master Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants