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 prefer-modern-dom-apis
rule
#362
Add prefer-modern-dom-apis
rule
#362
Conversation
rules/prefer-modern-dom-apis.js
Outdated
} | ||
|
||
return null; | ||
}; |
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.
Move this helper function out of checkForReplaceChildOrInsertBefore
. There may be a suitable util here: https://github.com/sindresorhus/eslint-plugin-unicorn/tree/master/rules/utils. Perhaps is-method-named
?
Also, args
is not a very good argument name. Perhaps nodeArgument
?
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.
is-method-named
would not help me, since i cannot say what the argument name will be.
There are multiple other rules with const args = node.arguments;
and their own scoped helper functions, e.g: prefer-node-remove
in the code already, but I am also fine with renaming it ;)
rules/prefer-modern-dom-apis.js
Outdated
} | ||
|
||
return null; | ||
}; |
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.
Same comment as before. This should be moved to the parent scope.
CallExpression(node) { | ||
if ( | ||
node.callee.type === 'MemberExpression' && | ||
node.arguments.length === 2 |
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.
You can include these checks in the selector pattern for the rule. Not required for the PR but in case you hadn't seen it yet, here are the docs: https://eslint.org/docs/developer-guide/selectors
added additional test cases Signed-off-by: mhatvan <markus_hatvan@aon.at>
@MrHen I pushed some code adaptions in the newest commit. |
@MrHen can you take another look at the changes you requested? I implemented your recommendations a while ago. |
@mhatvan Sorry, I'm actually in the middle of changing employers right now and am transitioning a ton of stuff across teams. I probably won't get a chance to look at it in the next couple weeks. |
since also
so, maybe you want do a similar check like #321 |
…n into feat/344-prefer-modern-dom-apis
* Change getDocsUrl to getDocumentationUrl * Change formatting of plugins property in index.js Signed-off-by: mhatvan <markus_hatvan@aon.at>
…rule Signed-off-by: mhatvan <markus_hatvan@aon.at>
@fisker I pushed some code adaptions in the newest commit. |
what about this?
|
you linked the complete PR without specifying what you exactly want me to change, I need more details here. |
@mhatvan I mean some methods returns different result, so we need check if the return value is used. |
* change fenced code block language in readme.md from bash to console Signed-off-by: mhatvan <markus_hatvan@aon.at>
@sindresorhus I implemented the changes you requested, can we get this merged now? I still don't understand @fisker feedback:
I implemented it according to the examples in MDN and they return the expected result. |
@mhatvan |
…n into feat/344-prefer-modern-dom-apis
…Before() and .insertAdjacentElement() methods * add additional test cases for .replaceWith(), .insertBefore() and .insertAdjacentElement() methods Signed-off-by: mhatvan <markus_hatvan@aon.at>
@sindresorhus Sorry, I missed that you already left a comment a while ago. I pushed another commit which implements the requested changes and added additional tests. |
@mhatvan I think we should still report an error, just can't fix |
👍 |
… methods to be reported but no autofix option when part of variable assignment * update test cases to verify changed rule logic Signed-off-by: mhatvan <markus_hatvan@aon.at>
@sindresorhus @fisker feedback implemented, I pushed another commit ;) |
Looks good. Thanks for contributing 👌 |
Awesome! |
const isPartOfVariableAssignment = nodeParentType => { | ||
if (nodeParentType === 'VariableDeclarator' || nodeParentType === 'AssignmentExpression') { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; |
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 don't think this is enough,
simple one:
console.log(referenceNode.insertAdjacentElement("beforebegin", newNode));
Fixes #344.
The rule can be tested in this gist here: https://astexplorer.net/#/gist/338d492213d95b40122046fb29abd1bc/bb5030be4689f651524402efad8d24d2b310d588
The links in the description for
prepend()
andappend()
from MDN are returning 404 by the way, they should be updated.IssueHunt Summary
Referenced issues
This pull request has been submitted to:
prefer-modern-dom-apis
IssueHunt has been backed by the following sponsors. Become a sponsor