Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: Support arbitrary module namespace names in keyword-spacing (#1…
  • Loading branch information
mdjermanovic committed Jan 5, 2022
1 parent fd3683f commit 5563c45
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 2 deletions.
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

0 comments on commit 5563c45

Please sign in to comment.