-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add warnings for "free-hanging" generics in docs [#1250] #1313
Conversation
@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.
import 'reporting.dart'; | ||
|
||
const validHtmlTags = const [ | ||
"a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From there: http://www.htmldog.com/references/html/tags/
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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}"); | ||
} | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
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? |
Warnings:
|
@devoncarew PTAL |
@Hixie asked for warnings when the generics are "free-hanging", and not
wrapped into [] block (like
Apple<Cat>
, but not[Apple<Cat>]
). Thiscommit 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:
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