Skip to content

Commit b76bd25

Browse files
committed
Fix comment handling in jsx-curly-spacing
1 parent e882a18 commit b76bd25

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

lib/rules/jsx-curly-spacing.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ module.exports = function(context) {
3434
return left.loc.start.line !== right.loc.start.line;
3535
}
3636

37-
/**
38-
* Determines whether two adjacent tokens have whitespace between them.
39-
* @param {Object} left - The left token object.
40-
* @param {Object} right - The right token object.
41-
* @returns {boolean} Whether or not there is space between the tokens.
42-
*/
43-
function isSpaced(left, right) {
44-
return left.range[1] < right.range[0];
45-
}
46-
4737
/**
4838
* Reports that there shouldn't be a newline after the first token
4939
* @param {ASTNode} node - The node to report in the event of an error.
@@ -161,13 +151,13 @@ module.exports = function(context) {
161151
*/
162152
function validateBraceSpacing(node, first, second, penultimate, last) {
163153
if (spaced) {
164-
if (!isSpaced(first, second)) {
154+
if (!sourceCode.isSpaceBetweenTokens(first, second)) {
165155
reportRequiredBeginningSpace(node, first);
166156
} else if (!multiline && isMultiline(first, second)) {
167157
reportNoBeginningNewline(node, first);
168158
}
169159

170-
if (!isSpaced(penultimate, last)) {
160+
if (!sourceCode.isSpaceBetweenTokens(penultimate, last)) {
171161
reportRequiredEndingSpace(node, last);
172162
} else if (!multiline && isMultiline(penultimate, last)) {
173163
reportNoEndingNewline(node, last);
@@ -177,11 +167,11 @@ module.exports = function(context) {
177167
}
178168

179169
// "never" setting if we get here.
180-
if (isSpaced(first, second) && !(multiline && isMultiline(first, second))) {
170+
if (sourceCode.isSpaceBetweenTokens(first, second) && !(multiline && isMultiline(first, second))) {
181171
reportNoBeginningSpace(node, first);
182172
}
183173

184-
if (isSpaced(penultimate, last) && !(multiline && isMultiline(penultimate, last))) {
174+
if (sourceCode.isSpaceBetweenTokens(penultimate, last) && !(multiline && isMultiline(penultimate, last))) {
185175
reportNoEndingSpace(node, last);
186176
}
187177
}
@@ -193,13 +183,9 @@ module.exports = function(context) {
193183
return {
194184
JSXExpressionContainer: function(node) {
195185
var first = context.getFirstToken(node);
196-
var second = context.getFirstToken(node, 1);
197-
var penultimate = sourceCode.getLastToken(node, 1);
198186
var last = sourceCode.getLastToken(node);
199-
200-
if (first === penultimate && second === last) {
201-
return;
202-
}
187+
var second = context.getTokenAfter(first);
188+
var penultimate = sourceCode.getTokenBefore(last);
203189

204190
validateBraceSpacing(node, first, second, penultimate, last);
205191
}

0 commit comments

Comments
 (0)