Skip to content
Permalink
Browse files
feat: Support arbitrary module namespace names in keyword-spacing (#1…
  • Loading branch information
mdjermanovic committed Jan 5, 2022
1 parent fd3683f commit 5563c454901aafd54e01521e923cdcbaf051b08d
Showing with 265 additions and 2 deletions.
  1. +5 −2 docs/rules/keyword-spacing.md
  2. +32 −0 lib/rules/keyword-spacing.js
  3. +228 −0 tests/lib/rules/keyword-spacing.js
@@ -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) {
@@ -272,6 +273,8 @@ class C {
//...
}
}
export { C as"my class" };
```

## When Not To Use It
@@ -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) {
@@ -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.
@@ -588,6 +618,8 @@ module.exports = {
YieldExpression: checkSpacingBeforeFirstToken,

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

0 comments on commit 5563c45

Please sign in to comment.