From 62fd2b93448966331db3eb2dfbe4e1273eb032b2 Mon Sep 17 00:00:00 2001 From: Bin Ury <1146921+teddy-error@users.noreply.github.com> Date: Mon, 3 Dec 2018 07:38:33 -0600 Subject: [PATCH] Update: Amend keyword-spacing to validate `default` keywords (#11097) * Fix: Amend keyword-spacing to validate `default` keywords * Chore: Add keyword-spacing test for `default` keyword --- lib/rules/keyword-spacing.js | 6 +++++- tests/lib/rules/keyword-spacing.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rules/keyword-spacing.js b/lib/rules/keyword-spacing.js index 66ce2cb34c0..790d7b031d8 100644 --- a/lib/rules/keyword-spacing.js +++ b/lib/rules/keyword-spacing.js @@ -453,6 +453,10 @@ module.exports = { checkSpacingBefore(firstToken, PREV_TOKEN_M); checkSpacingAfter(firstToken, NEXT_TOKEN_M); + if (node.type === "ExportDefaultDeclaration") { + checkSpacingAround(sourceCode.getTokenAfter(firstToken)); + } + if (node.source) { const fromToken = sourceCode.getTokenBefore(node.source); @@ -554,7 +558,7 @@ module.exports = { // Statements - Declarations ClassDeclaration: checkSpacingForClass, ExportNamedDeclaration: checkSpacingForModuleDeclaration, - ExportDefaultDeclaration: checkSpacingAroundFirstToken, + ExportDefaultDeclaration: checkSpacingForModuleDeclaration, ExportAllDeclaration: checkSpacingForModuleDeclaration, FunctionDeclaration: checkSpacingForFunction, ImportDeclaration: checkSpacingForModuleDeclaration, diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 33a9d50683e..cebd163673e 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -2023,6 +2023,12 @@ ruleTester.run("keyword-spacing", rule, { parserOptions: { sourceType: "module" }, errors: expectedBefore("export") }, + { + code: "export default{a}", + output: "export default {a}", + parserOptions: { sourceType: "module" }, + errors: expectedAfter("default") + }, { code: "{}export* from \"a\"", output: "{} export * from \"a\"",