-
-
Notifications
You must be signed in to change notification settings - Fork 357
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 isNotDomNode
check prefer-node-append
#512
Conversation
1330de5
to
6e32af0
Compare
LGTM... However, in cases where one polyfills the DOM (e.g., in my dominum project), an |
Can you explain what use case exactly. I can't understand, how to make a Node with |
One can polyfill DOM for the sake of such as server-side methods which build DOM trees, and allow one to use libraries with familiar semantics such as jQuery which understand the DOM, but only use the DOM to ultimately serialize it back to a string. For example, we might have: const div = {
nodeName: 'div',
nodeType: 1,
append () {/**/},
childNodes: [
{nodeType: 3, nodeValue: 'Hello'} // A text node
],
get innerHTML () {/**/}
};
// Adding the string result, e.g., as part of a Node server response
resp.end(
div.appendChild({
nodeType: 1,
nodeName: 'b',
textContent: 'world'
}).parentElement.innerHTML
); The above is just a simplified example, and probably there wouldn't be many people passing in object literals. Such objects would usually be generated by a library, e.g., jQuery (since such libraries as jQuery are not typically doing checks for native code, e.g., checking whether const parentTemplate = '<div>Hello</div>';
const childTemplate = '<b>world</b>';
resp.end(
$(parentTemplate).append(childTemplate).html()
); This example may not seem particularly useful, but just mentioning there are cases where one may polyfill the DOM, and these may be implemented as objects. |
Ya, I got it, a fake Node, but I don't think we should consider this case. |
Alrightee... |
I think in such obscure cases, you can use an ESLint disable comment. |
@sindresorhus What I'm going to do is ignore that case, so he can't use disable comment. I mean |
notNode
to check impossible type of Node
isNotDomNode
check prefer-node-append
I took the selector is so strict now
So we are not reporting following anymore [].appendChild(foo);
foo.appendChild('not a dom node');
// and many others |
e5c6d86
to
1e0ed5f
Compare
5321752
to
2b08a2a
Compare
Attempt to implement a function
notNode
to check a AST node impossible type ofNode
(DOM), so we can use on ourprefer-modern-dom-apis
,prefer-node-append
,prefer-node-remove
prevent accidentally wrong fix on some case.Eg:
I've add some, I'm sure can't be
Node
//cc @brettz9 WDYT?