Skip to content

Commit

Permalink
Fix: keyword-spacing private name compat (refs #14857) (#14946)
Browse files Browse the repository at this point in the history
* Fix: keyword-spacing private name compat (refs #14857)

* Update tests/lib/rules/keyword-spacing.js

Co-authored-by: Milos Djermanovic <[email protected]>

Co-authored-by: Milos Djermanovic <[email protected]>
  • Loading branch information
nzakas and mdjermanovic authored Aug 20, 2021
1 parent 58840ac commit ee1b54f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/rules/keyword-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,15 @@ module.exports = {
*/
function checkSpacingForForInStatement(node) {
checkSpacingAroundFirstToken(node);
checkSpacingAroundTokenBefore(node.right);

const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
const previousToken = sourceCode.getTokenBefore(inToken);

if (previousToken.type !== "PrivateIdentifier") {
checkSpacingBefore(inToken);
}

checkSpacingAfter(inToken);
}

/**
Expand All @@ -419,7 +427,15 @@ module.exports = {
} else {
checkSpacingAroundFirstToken(node);
}
checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));

const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
const previousToken = sourceCode.getTokenBefore(ofToken);

if (previousToken.type !== "PrivateIdentifier") {
checkSpacingBefore(ofToken);
}

checkSpacingAfter(ofToken);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/keyword-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ ruleTester.run("keyword-spacing", rule, {
{ code: "<Foo onClick={class {}} />", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
{ code: "<Foo onClick={ class{}} />", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },

// private names
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },

//----------------------------------------------------------------------
// const
//----------------------------------------------------------------------
Expand Down

0 comments on commit ee1b54f

Please sign in to comment.