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

feat: Support arbitrary module namespace names in keyword-spacing #15481

Merged
merged 1 commit into from Jan 5, 2022
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
7 changes: 5 additions & 2 deletions docs/rules/keyword-spacing.md
Expand Up @@ -243,14 +243,15 @@ if(foo) {

### overrides

Examples of **correct** code for this rule with the `{ "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false }, "static": { "after": false } } }` option:
Examples of **correct** code for this rule with the `{ "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false }, "static": { "after": false }, "as": { "after": false } } }` option:

```js
/*eslint keyword-spacing: ["error", { "overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false },
"static": { "after": false }
"static": { "after": false },
"as": { "after": false }
} }]*/

if(foo) {
Expand All @@ -272,6 +273,8 @@ class C {
//...
}
}

export { C as"my class" };
```

## When Not To Use It
Expand Down
32 changes: 32 additions & 0 deletions lib/rules/keyword-spacing.js
Expand Up @@ -469,6 +469,7 @@ module.exports = {
const asToken = sourceCode.getTokenBefore(node.exported);

checkSpacingBefore(asToken, PREV_TOKEN_M);
checkSpacingAfter(asToken, NEXT_TOKEN_M);
}

if (node.source) {
Expand All @@ -479,6 +480,35 @@ module.exports = {
}
}

/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
* @param {ASTNode} node An `ImportSpecifier` node to check.
* @returns {void}
*/
function checkSpacingForImportSpecifier(node) {
if (node.imported.range[0] !== node.local.range[0]) {
const asToken = sourceCode.getTokenBefore(node.local);

checkSpacingBefore(asToken, PREV_TOKEN_M);
}
}

/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
* @param {ASTNode} node An `ExportSpecifier` node to check.
* @returns {void}
*/
function checkSpacingForExportSpecifier(node) {
if (node.local.range[0] !== node.exported.range[0]) {
const asToken = sourceCode.getTokenBefore(node.exported);

checkSpacingBefore(asToken, PREV_TOKEN_M);
checkSpacingAfter(asToken, NEXT_TOKEN_M);
}
}

/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
Expand Down Expand Up @@ -588,6 +618,8 @@ module.exports = {
YieldExpression: checkSpacingBeforeFirstToken,

// Others
ImportSpecifier: checkSpacingForImportSpecifier,
ExportSpecifier: checkSpacingForExportSpecifier,
ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
MethodDefinition: checkSpacingForProperty,
PropertyDefinition: checkSpacingForProperty,
Expand Down