-
Notifications
You must be signed in to change notification settings - Fork 25
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
Ignore dfns that have an invalid type #659
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,77 @@ import {parse} from "../../node_modules/webidl2/index.js"; | |
* @return {Array(Object)} An Array of definitions | ||
*/ | ||
|
||
function definitionMapper(el, idToHeading) { | ||
function normalize(str) { | ||
return str.trim().replace(/\s+/g, ' '); | ||
function normalize(str) { | ||
return str.trim().replace(/\s+/g, ' '); | ||
} | ||
|
||
// Valid types defined in https://tabatkins.github.io/bikeshed/#dfn-types | ||
// (+ "namespace" and "event" which are not yet in the doc) | ||
function hasValidType(el) { | ||
const validDfnTypes = [ | ||
// CSS types | ||
'property', | ||
'descriptor', | ||
'value', | ||
'type', | ||
'at-rule', | ||
'function', | ||
'selector', | ||
|
||
// Web IDL types | ||
'namespace', | ||
'interface', | ||
'constructor', | ||
'method', | ||
'argument', | ||
'attribute', | ||
'callback', | ||
'dictionary', | ||
'dict-member', | ||
'enum', | ||
'enum-value', | ||
'exception', | ||
'const', | ||
'typedef', | ||
'stringifier', | ||
'serializer', | ||
'iterator', | ||
'maplike', | ||
'setlike', | ||
'extended-attribute', | ||
'event', | ||
|
||
// Element types | ||
'element', | ||
'element-state', | ||
'element-attr', | ||
'attr-value', | ||
|
||
|
||
// URL scheme | ||
'scheme', | ||
|
||
// HTTP header | ||
'http-header', | ||
|
||
// Grammar type | ||
'grammar', | ||
|
||
// "English" terms | ||
'abstract-op', | ||
'dfn' | ||
]; | ||
|
||
const type = el.getAttribute('data-dfn-type') ?? 'dfn'; | ||
const isValid = validDfnTypes.includes(type); | ||
if (!isValid) { | ||
console.warn('[reffy]', `"${type}" is an invalid dfn type for "${normalize(el.textContent)}"`); | ||
} | ||
return isValid; | ||
} | ||
|
||
|
||
function definitionMapper(el, idToHeading) { | ||
let definedIn = 'prose'; | ||
const enclosingEl = el.closest('dt,pre,table,h1,h2,h3,h4,h5,h6,.note,.example') || el; | ||
switch (enclosingEl.nodeName) { | ||
|
@@ -140,6 +206,18 @@ export default function (spec, idToHeading = {}) { | |
} | ||
|
||
return [...document.querySelectorAll(definitionsSelector)] | ||
.map(node => { | ||
// 2021-06-21: Temporary preprocessing of invalid "idl" dfn type (used for | ||
// internal slots) while fix for https://github.com/w3c/respec/issues/3644 | ||
// propagates to all EDs and /TR specs. To be dropped once crawls no | ||
// longer produce warnings. | ||
if (node.getAttribute('data-dfn-type') === 'idl') { | ||
node.setAttribute('data-dfn-type', 'attribute'); | ||
console.warn('[reffy]', `Fixed invalid "idl" dfn type "${normalize(node.textContent)}"`); | ||
} | ||
return node; | ||
}) | ||
.filter(hasValidType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking some more - instead of removing definitions with an invalid type, shouldn't we default them back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitant to do that. The good thing about removing definitions with an invalid type is that no one can reference them. When someone needs to do that, they will notice that the dfn is missing and raise an issue somewhere to have that fixed, and this should eventually appear on our radar. If we default these definitions to Obviously, we could notice if we had a proper way to deal with the "warnings" that Reffy logs. I'm not utterly confident that we'll look into the workflow logs, and it's more work to have a better alert mechanism. Useful work but more work... Plus, if we do that, we can just as well remove the dfns: we would have them fixed in the source spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I can see that making kind of sense; the risks are probably limited in any case if ReSpec starts flagging unknown definition types the same way bikeshed does. |
||
.map(node => definitionMapper(node, idToHeading)); | ||
} | ||
|
||
|
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.
I've commented in https://github.com/w3c/respec/issues/3644#issuecomment-864894696 - I'm not convinced
attribute
is the right approach.Code looks good otherwise.
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're still discussing whether it would be worth creating an additional type in speced/spec-dfn-contract#1.
In the meantime, w3c/respec#3644 was closed with ReSpec now flagging internal slots with an
attribute
type and internal methods with amethod
type. I've updated the code to the same here and propose to go ahead with this while we converge on new types (or on making these dfns private by default one way or another).