summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/quotes.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/quotes.js')
-rw-r--r--tools/eslint/lib/rules/quotes.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/tools/eslint/lib/rules/quotes.js b/tools/eslint/lib/rules/quotes.js
index 29ef600c42..90e68289e0 100644
--- a/tools/eslint/lib/rules/quotes.js
+++ b/tools/eslint/lib/rules/quotes.js
@@ -123,12 +123,26 @@ module.exports = {
/**
* Determines if a given node is part of JSX syntax.
- * @param {ASTNode} node The node to check.
- * @returns {boolean} True if the node is a JSX node, false if not.
+ *
+ * This function returns `true` in the following cases:
+ *
+ * - `<div className="foo"></div>` ... If the literal is an attribute value, the parent of the literal is `JSXAttribute`.
+ * - `<div>foo</div>` ... If the literal is a text content, the parent of the literal is `JSXElement`.
+ *
+ * In particular, this function returns `false` in the following cases:
+ *
+ * - `<div className={"foo"}></div>`
+ * - `<div>{"foo"}</div>`
+ *
+ * In both cases, inside of the braces is handled as normal JavaScript.
+ * The braces are `JSXExpressionContainer` nodes.
+ *
+ * @param {ASTNode} node The Literal node to check.
+ * @returns {boolean} True if the node is a part of JSX, false if not.
* @private
*/
- function isJSXElement(node) {
- return node.type.indexOf("JSX") === 0;
+ function isJSXLiteral(node) {
+ return node.parent.type === "JSXAttribute" || node.parent.type === "JSXElement";
}
/**
@@ -215,7 +229,7 @@ module.exports = {
if (settings && typeof val === "string") {
isValid = (quoteOption === "backtick" && isAllowedAsNonBacktick(node)) ||
- isJSXElement(node.parent) ||
+ isJSXLiteral(node) ||
astUtils.isSurroundedBy(rawVal, settings.quote);
if (!isValid && avoidEscape) {