Skip to content
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

Fix: keyword-spacing private name compat (refs #14857) #14946

Merged
merged 2 commits into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/rules/keyword-spacing.js
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
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