-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
tools: auto fix custom eslint rule for lowercase-name-for-primitive.js #17715
Changes from 1 commit
a389548
b2d1f5b
42009c2
1799ec3
a23ca88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
1. Fixer for lowercase-name-for-primitive.js 2. Modified the node passed to fix it. Refs : #16636
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,11 @@ module.exports = function(context) { | |
|
||
switch (names.type) { | ||
case 'Literal': | ||
checkName(node, names.value); | ||
checkName(names, names.value); | ||
break; | ||
case 'ArrayExpression': | ||
names.elements.forEach((name) => { | ||
checkName(node, name.value); | ||
names.elements.forEach((name, index) => { | ||
checkName(names.elements[index], name.value); | ||
}); | ||
break; | ||
} | ||
|
@@ -36,8 +36,18 @@ module.exports = function(context) { | |
const lowercaseName = name.toLowerCase(); | ||
if (primitives.includes(lowercaseName) && !primitives.includes(name)) { | ||
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.
Also, pretty sure 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. Made the changes. |
||
const msg = `primitive should use lowercase: ${name}`; | ||
context.report(node, msg); | ||
context.report({ | ||
node, | ||
message: msg, | ||
fix: (fixer) => { | ||
return fixer.replaceText( | ||
node, | ||
`'${lowercaseName}'` | ||
); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
return { | ||
|
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.
Couldn't this just be
name
instead ofnames.elements[index]
? Pretty sure we can also get rid of the second argument here and above.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.
👍🏻