Skip to content

Commit ee1b54f

Browse files
nzakasmdjermanovic
andauthoredAug 20, 2021
Fix: keyword-spacing private name compat (refs #14857) (#14946)
* Fix: keyword-spacing private name compat (refs #14857) * Update tests/lib/rules/keyword-spacing.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 58840ac commit ee1b54f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎lib/rules/keyword-spacing.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,15 @@ module.exports = {
403403
*/
404404
function checkSpacingForForInStatement(node) {
405405
checkSpacingAroundFirstToken(node);
406-
checkSpacingAroundTokenBefore(node.right);
406+
407+
const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
408+
const previousToken = sourceCode.getTokenBefore(inToken);
409+
410+
if (previousToken.type !== "PrivateIdentifier") {
411+
checkSpacingBefore(inToken);
412+
}
413+
414+
checkSpacingAfter(inToken);
407415
}
408416

409417
/**
@@ -419,7 +427,15 @@ module.exports = {
419427
} else {
420428
checkSpacingAroundFirstToken(node);
421429
}
422-
checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));
430+
431+
const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
432+
const previousToken = sourceCode.getTokenBefore(ofToken);
433+
434+
if (previousToken.type !== "PrivateIdentifier") {
435+
checkSpacingBefore(ofToken);
436+
}
437+
438+
checkSpacingAfter(ofToken);
423439
}
424440

425441
/**

‎tests/lib/rules/keyword-spacing.js

+4
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ ruleTester.run("keyword-spacing", rule, {
379379
{ code: "<Foo onClick={class {}} />", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
380380
{ code: "<Foo onClick={ class{}} />", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
381381

382+
// private names
383+
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
384+
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
385+
382386
//----------------------------------------------------------------------
383387
// const
384388
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.