-
-
Notifications
You must be signed in to change notification settings - Fork 368
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-query-selector
rule
#198
Add prefer-query-selector
rule
#198
Conversation
prefer-query-selector
rule
rules/prefer-query-selector.js
Outdated
|
||
const VALID_QUOTES = /([',",`])/; | ||
const getRange = (prop, node) => [prop.start, node.arguments[0].end]; | ||
const getReplacement = (ctx, identifierName, node) => { |
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.
ctx
=> context
Generally, use readable names instead of abbreviations.
test/prefer-query-selector.js
Outdated
}, | ||
{ | ||
code: 'document.getElementsByClassName("foo bar");', | ||
errors: [{message: 'Prefer `querySelector` over `getElementsByClassName`.'}], |
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.
No need to repeat the error in every assertion. Just build them upfront, like done in https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/test/new-for-builtins.js
The rule needs to be added to the bottom of the list here: https://github.com/sindresorhus/eslint-plugin-unicorn#rules |
@janowsiany Ping :) |
…plugin-unicorn into prefer-query-selector
@sindresorhus sorry for such long delay, please revalidate. I decided to make it partly fixable only because i found template strings and other corner cases hard or impossible to fix. |
This looks good to me now. Very nice work, @janowsiany 👍 |
fixes #171