From 16b5b1b2cd9ccafc26f878af39698c0d5002ab74 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:05:07 +0100 Subject: [PATCH 01/31] keyword-spacing --- packages/eslint-plugin/src/rules/index.ts | 2 + .../src/rules/keyword-spacing.ts | 601 ++++ .../src/rules/space-before-function-paren.ts | 10 +- packages/eslint-plugin/src/types/eslint.d.ts | 4 + .../tests/rules/keyword-spacing.test.ts | 3152 +++++++++++++++++ yarn.lock | 6 +- 6 files changed, 3766 insertions(+), 9 deletions(-) create mode 100644 packages/eslint-plugin/src/rules/keyword-spacing.ts create mode 100644 packages/eslint-plugin/src/types/eslint.d.ts create mode 100644 packages/eslint-plugin/tests/rules/keyword-spacing.test.ts diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index 901d31a8b9fb..4f1433275855 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -19,6 +19,7 @@ import funcCallSpacing from './func-call-spacing'; import genericTypeNaming from './generic-type-naming'; import indent from './indent'; import interfaceNamePrefix from './interface-name-prefix'; +import keywordSpacing from './keyword-spacing'; import memberDelimiterStyle from './member-delimiter-style'; import memberNaming from './member-naming'; import memberOrdering from './member-ordering'; @@ -118,6 +119,7 @@ export default { 'generic-type-naming': genericTypeNaming, indent: indent, 'interface-name-prefix': interfaceNamePrefix, + 'keyword-spacing': keywordSpacing, 'member-delimiter-style': memberDelimiterStyle, 'member-naming': memberNaming, 'member-ordering': memberOrdering, diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts new file mode 100644 index 000000000000..4069f62f9c28 --- /dev/null +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -0,0 +1,601 @@ +import keywords from 'eslint/lib/rules/utils/keywords'; +import * as util from '../util'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; +import { JSONSchema4 } from 'json-schema'; +import { + isTokenOnSameLine, + isKeywordToken, + isNotOpeningParenToken, +} from '../util/astUtils'; + +export type Option = Partial<{ + before: boolean; + after: boolean; +}>; + +export type RootOption = Option & { + overrides?: { [keywordName: string]: Option }; +}; + +export type Options = [RootOption]; +export type MessageIds = + | 'expectedBefore' + | 'expectedAfter' + | 'unexpectedBefore' + | 'unexpectedAfter'; + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +const PREV_TOKEN = /^[)\]}>]$/u; +const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; +const PREV_TOKEN_M = /^[)\]}>*]$/u; +const NEXT_TOKEN_M = /^[{*]$/u; +const TEMPLATE_OPEN_PAREN = /\$\{$/u; +const TEMPLATE_CLOSE_PAREN = /^\}/u; +const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; +const KEYS = keywords.concat([ + 'as', + 'async', + 'await', + 'from', + 'get', + 'let', + 'of', + 'set', + 'yield', +]); + +// check duplications. +(function() { + KEYS.sort(); + for (let i = 1; i < KEYS.length; ++i) { + if (KEYS[i] === KEYS[i - 1]) { + throw new Error(`Duplication was found in the keyword list: ${KEYS[i]}`); + } + } +})(); + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Checks whether or not a given token is a "Template" token ends with "${". + * @param token A token to check. + * @returns `true` if the token is a "Template" token ends with "${". + */ +function isOpenParenOfTemplate(token: TSESTree.Token) { + return token.type === 'Template' && TEMPLATE_OPEN_PAREN.test(token.value); +} + +/** + * Checks whether or not a given token is a "Template" token starts with "}". + * @param token A token to check. + * @returns `true` if the token is a "Template" token starts with "}". + */ +function isCloseParenOfTemplate(token: TSESTree.Token) { + return token.type === 'Template' && TEMPLATE_CLOSE_PAREN.test(token.value); +} + +export default util.createRule({ + name: 'keyword-spacing', + meta: { + type: 'layout', + docs: { + description: 'enforce consistent spacing before and after keywords', + category: 'Stylistic Issues', + recommended: false, + extendsBaseRule: true, + }, + fixable: 'whitespace', + schema: [ + { + type: 'object', + properties: { + before: { type: 'boolean', default: true }, + after: { type: 'boolean', default: true }, + overrides: { + type: 'object', + properties: KEYS.reduce((retv: JSONSchema4, key) => { + retv[key] = { + type: 'object', + properties: { + before: { type: 'boolean' }, + after: { type: 'boolean' }, + }, + additionalProperties: false, + }; + return retv; + }, {}), + additionalProperties: false, + }, + }, + additionalProperties: false, + }, + ], + messages: { + expectedBefore: 'Expected space(s) before "{{value}}".', + expectedAfter: 'Expected space(s) after "{{value}}".', + unexpectedBefore: 'Unexpected space(s) before "{{value}}".', + unexpectedAfter: 'Unexpected space(s) after "{{value}}".', + }, + }, + defaultOptions: [{ before: true, after: true }], + + create(context) { + const sourceCode = context.getSourceCode(); + /** + * Reports a given token if there are not space(s) before the token. + * @param token A token to report. + * @param pattern A pattern of the previous token to check. + */ + function expectSpaceBefore(token: TSESTree.Token, pattern: RegExp) { + const prevToken = sourceCode.getTokenBefore(token); + + if ( + prevToken && + (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && + !isOpenParenOfTemplate(prevToken) && + isTokenOnSameLine(prevToken, token) && + !sourceCode.isSpaceBetweenTokens(prevToken, token) + ) { + context.report({ + loc: token.loc.start, + messageId: 'expectedBefore', + data: { + value: token.value, + }, + fix(fixer) { + return fixer.insertTextBefore(token, ' '); + }, + }); + } + } + + /** + * Reports a given token if there are space(s) before the token. + * @param token A token to report. + * @param pattern A pattern of the previous token to check. + */ + function unexpectSpaceBefore(token: TSESTree.Token, pattern: RegExp) { + const prevToken = sourceCode.getTokenBefore(token); + + if ( + prevToken && + (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && + !isOpenParenOfTemplate(prevToken) && + isTokenOnSameLine(prevToken, token) && + sourceCode.isSpaceBetweenTokens(prevToken, token) + ) { + context.report({ + loc: token.loc.start, + messageId: 'unexpectedBefore', + data: { + value: token.value, + }, + fix(fixer) { + return fixer.removeRange([prevToken.range[1], token.range[0]]); + }, + }); + } + } + + /** + * Reports a given token if there are not space(s) after the token. + * @param token A token to report. + * @param pattern A pattern of the next token to check. + */ + function expectSpaceAfter(token: TSESTree.Token, pattern: RegExp) { + const nextToken = sourceCode.getTokenAfter(token); + + if ( + nextToken && + (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && + !isCloseParenOfTemplate(nextToken) && + isTokenOnSameLine(token, nextToken) && + !sourceCode.isSpaceBetweenTokens(token, nextToken) + ) { + context.report({ + loc: token.loc.start, + messageId: 'expectedAfter', + data: { + value: token.value, + }, + fix(fixer) { + return fixer.insertTextAfter(token, ' '); + }, + }); + } + } + + /** + * Reports a given token if there are space(s) after the token. + * @param token A token to report. + * @param pattern A pattern of the next token to check. + */ + function unexpectSpaceAfter(token: TSESTree.Token, pattern: RegExp) { + const nextToken = sourceCode.getTokenAfter(token); + + if ( + nextToken && + (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && + !isCloseParenOfTemplate(nextToken) && + isTokenOnSameLine(token, nextToken) && + sourceCode.isSpaceBetweenTokens(token, nextToken) + ) { + context.report({ + loc: token.loc.start, + messageId: 'unexpectedAfter', + data: { + value: token.value, + }, + fix(fixer) { + return fixer.removeRange([token.range[1], nextToken.range[0]]); + }, + }); + } + } + + /** + * Parses the option object and determines check methods for each keyword. + * @param options The option object to parse. + * @returns Normalized option object. + * Keys are keywords (there are for every keyword). + * Values are instances of `{"before": function, "after": function}`. + */ + function parseOptions( + options: RootOption = {}, + ): { [keyword: string]: { before: Function; after: Function } } { + const before = options.before !== false; + const after = options.after !== false; + const defaultValue = { + before: before ? expectSpaceBefore : unexpectSpaceBefore, + after: after ? expectSpaceAfter : unexpectSpaceAfter, + }; + const overrides = (options && options.overrides) || {}; + const retv = Object.create(null); + + for (let i = 0; i < KEYS.length; ++i) { + const key = KEYS[i]; + const override = overrides[key]; + + if (override) { + const thisBefore = 'before' in override ? override.before : before; + const thisAfter = 'after' in override ? override.after : after; + + retv[key] = { + before: thisBefore ? expectSpaceBefore : unexpectSpaceBefore, + after: thisAfter ? expectSpaceAfter : unexpectSpaceAfter, + }; + } else { + retv[key] = defaultValue; + } + } + return retv; + } + + const checkMethodMap = parseOptions(context.options[0]); + + /** + * Reports a given token if usage of spacing followed by the token is invalid. + * @param token A token to report. + * @param pattern A pattern of the previous token to check. + */ + function checkSpacingBefore(token: TSESTree.Token, pattern?: RegExp) { + checkMethodMap[token.value].before(token, pattern || PREV_TOKEN); + } + + /** + * Reports a given token if usage of spacing preceded by the token is invalid. + * @param token A token to report. + * @param pattern A pattern of the next token to check. + */ + function checkSpacingAfter(token: TSESTree.Token, pattern?: RegExp) { + checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN); + } + + /** + * Reports a given token if usage of spacing around the token is invalid. + * @param token A token to report. + */ + function checkSpacingAround(token: TSESTree.Token) { + checkSpacingBefore(token); + checkSpacingAfter(token); + } + + /** + * Reports the first token of a given node if the first token is a keyword + * and usage of spacing around the token is invalid. + * @param node A node to report. + */ + function checkSpacingAroundFirstToken(node: TSESTree.Node) { + const firstToken = node && sourceCode.getFirstToken(node); + + if (firstToken && firstToken.type === 'Keyword') { + checkSpacingAround(firstToken); + } + } + + /** + * Reports the first token of a given node if the first token is a keyword + * and usage of spacing followed by the token is invalid. + * + * This is used for unary operators (e.g. `typeof`), `function`, and `super`. + * Other rules are handling usage of spacing preceded by those keywords. + * @param node A node to report. + */ + function checkSpacingBeforeFirstToken( + node: + | TSESTree.NewExpression + | TSESTree.Super + | TSESTree.ThisExpression + | TSESTree.UnaryExpression + | TSESTree.YieldExpression, + ) { + const firstToken = node && sourceCode.getFirstToken(node); + + if (firstToken && firstToken.type === 'Keyword') { + checkSpacingBefore(firstToken); + } + } + + /** + * Reports the previous token of a given node if the token is a keyword and + * usage of spacing around the token is invalid. + * @param node A node to report. + */ + function checkSpacingAroundTokenBefore(node: TSESTree.Node) { + if (node) { + const token = sourceCode.getTokenBefore(node, isKeywordToken)!; + + checkSpacingAround(token); + } + } + + /** + * Reports `async` or `function` keywords of a given node if usage of + * spacing around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForFunction( + node: + | TSESTree.FunctionDeclaration + | TSESTree.ArrowFunctionExpression + | TSESTree.FunctionExpression, + ) { + const firstToken = node && sourceCode.getFirstToken(node); + + if ( + firstToken && + ((firstToken.type === 'Keyword' && firstToken.value === 'function') || + firstToken.value === 'async') + ) { + checkSpacingBefore(firstToken); + } + } + + /** + * Reports `class` and `extends` keywords of a given node if usage of + * spacing around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForClass( + node: TSESTree.ClassExpression | TSESTree.ClassDeclaration, + ) { + checkSpacingAroundFirstToken(node); + checkSpacingAroundTokenBefore(node.superClass!); + } + + /** + * Reports `if` and `else` keywords of a given node if usage of spacing + * around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForIfStatement(node: TSESTree.IfStatement) { + checkSpacingAroundFirstToken(node); + checkSpacingAroundTokenBefore((node as any).alternate); + } + + /** + * Reports `try`, `catch`, and `finally` keywords of a given node if usage + * of spacing around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForTryStatement(node: TSESTree.TryStatement) { + checkSpacingAroundFirstToken(node); + checkSpacingAroundFirstToken(node.handler!); + checkSpacingAroundTokenBefore(node.finalizer); + } + + /** + * Reports `do` and `while` keywords of a given node if usage of spacing + * around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForDoWhileStatement(node: TSESTree.DoWhileStatement) { + checkSpacingAroundFirstToken(node); + checkSpacingAroundTokenBefore(node.test); + } + + /** + * Reports `for` and `in` keywords of a given node if usage of spacing + * around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForForInStatement(node: TSESTree.ForInStatement) { + checkSpacingAroundFirstToken(node); + checkSpacingAroundTokenBefore(node.right); + } + + /** + * Reports `for` and `of` keywords of a given node if usage of spacing + * around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForForOfStatement(node: TSESTree.ForOfStatement) { + if (node.await) { + checkSpacingBefore(sourceCode.getFirstToken(node, 0)!); + checkSpacingAfter(sourceCode.getFirstToken(node, 1)!); + } else { + checkSpacingAroundFirstToken(node); + } + checkSpacingAround( + sourceCode.getTokenBefore(node.right, isNotOpeningParenToken)!, + ); + } + + /** + * Reports `import`, `export`, `as`, and `from` keywords of a given node if + * usage of spacing around those keywords is invalid. + * + * This rule handles the `*` token in module declarations. + * + * import*as A from "./a"; /*error Expected space(s) after "import". + * error Expected space(s) before "as". + * @param node A node to report. + */ + function checkSpacingForModuleDeclaration( + node: + | TSESTree.ExportNamedDeclaration + | TSESTree.ExportDefaultDeclaration + | TSESTree.ExportAllDeclaration + | TSESTree.ImportDeclaration, + ) { + const firstToken = sourceCode.getFirstToken(node)!; + + checkSpacingBefore(firstToken, PREV_TOKEN_M); + checkSpacingAfter(firstToken, NEXT_TOKEN_M); + + if (node.type === 'ExportDefaultDeclaration') { + checkSpacingAround(sourceCode.getTokenAfter(firstToken)!); + } + + if ((node as any).source) { + const fromToken = sourceCode.getTokenBefore((node as any).source)!; + + checkSpacingBefore(fromToken, PREV_TOKEN_M); + checkSpacingAfter(fromToken, NEXT_TOKEN_M); + } + } + + /** + * Reports `as` keyword of a given node if usage of spacing around this + * keyword is invalid. + * @param node A node to report. + */ + function checkSpacingForImportNamespaceSpecifier(node: TSESTree.Node) { + const asToken = sourceCode.getFirstToken(node, 1)!; + + checkSpacingBefore(asToken, PREV_TOKEN_M); + } + /** + * Reports `static`, `get`, and `set` keywords of a given node if usage of + * spacing around those keywords is invalid. + * @param node A node to report. + */ + function checkSpacingForProperty( + node: TSESTree.MethodDefinition | TSESTree.Property, + ) { + if ((node as any).static) { + checkSpacingAroundFirstToken(node); + } + if ( + node.kind === 'get' || + node.kind === 'set' || + (((node as any).method || node.type === 'MethodDefinition') && + (node as any).value.async) + ) { + const token = sourceCode.getTokenBefore(node.key, tok => { + switch (tok.value) { + case 'get': + case 'set': + case 'async': + return true; + default: + return false; + } + }); + + if (!token) { + throw new Error( + 'Failed to find token get, set, or async beside method name', + ); + } + + checkSpacingAround(token); + } + } + + /** + * Reports `await` keyword of a given node if usage of spacing before + * this keyword is invalid. + * @param node A node to report. + */ + function checkSpacingForAwaitExpression(node: TSESTree.AwaitExpression) { + checkSpacingBefore(sourceCode.getFirstToken(node)!); + } + + /** + * Reports `as` keyword of a given node if usage of spacing before + * this keyword is invalid. + * @param node A node to report. + */ + function checkSpacingForAsExpression(node: TSESTree.TSAsExpression) { + const token = sourceCode.getTokenAfter(node.expression)!; // get the `as` identifier. + checkSpacingAround(token); + } + + return { + // Statements + DebuggerStatement: checkSpacingAroundFirstToken, + WithStatement: checkSpacingAroundFirstToken, + + // Statements - Control flow + BreakStatement: checkSpacingAroundFirstToken, + ContinueStatement: checkSpacingAroundFirstToken, + ReturnStatement: checkSpacingAroundFirstToken, + ThrowStatement: checkSpacingAroundFirstToken, + TryStatement: checkSpacingForTryStatement, + + // Statements - Choice + IfStatement: checkSpacingForIfStatement, + SwitchStatement: checkSpacingAroundFirstToken, + SwitchCase: checkSpacingAroundFirstToken, + + // Statements - Loops + DoWhileStatement: checkSpacingForDoWhileStatement, + ForInStatement: checkSpacingForForInStatement, + ForOfStatement: checkSpacingForForOfStatement, + ForStatement: checkSpacingAroundFirstToken, + WhileStatement: checkSpacingAroundFirstToken, + + // Statements - Declarations + ClassDeclaration: checkSpacingForClass, + ExportNamedDeclaration: checkSpacingForModuleDeclaration, + ExportDefaultDeclaration: checkSpacingForModuleDeclaration, + ExportAllDeclaration: checkSpacingForModuleDeclaration, + FunctionDeclaration: checkSpacingForFunction, + ImportDeclaration: checkSpacingForModuleDeclaration, + VariableDeclaration: checkSpacingAroundFirstToken, + + // Expressions + ArrowFunctionExpression: checkSpacingForFunction, + AwaitExpression: checkSpacingForAwaitExpression, + ClassExpression: checkSpacingForClass, + FunctionExpression: checkSpacingForFunction, + NewExpression: checkSpacingBeforeFirstToken, + Super: checkSpacingBeforeFirstToken, + ThisExpression: checkSpacingBeforeFirstToken, + UnaryExpression: checkSpacingBeforeFirstToken, + YieldExpression: checkSpacingBeforeFirstToken, + + // Others + ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier, + MethodDefinition: checkSpacingForProperty, + Property: checkSpacingForProperty, + TSAsExpression: checkSpacingForAsExpression, + }; + }, +}); diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index bc2ad8b0d047..200bb39b2900 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -68,8 +68,8 @@ export default util.createRule({ /** * Determines whether a function has a name. - * @param {ASTNode} node The function node. - * @returns {boolean} Whether the function has a name. + * @param node The function node. + * @returns Whether the function has a name. */ function isNamedFunction( node: @@ -92,8 +92,7 @@ export default util.createRule({ /** * Gets the config for a given function - * @param {ASTNode} node The function node - * @returns {string} "always", "never", or "ignore" + * @param node The function node */ function getConfigForFunction( node: @@ -122,8 +121,7 @@ export default util.createRule({ /** * Checks the parens of a function node - * @param {ASTNode} node A function node - * @returns {void} + * @param node A function node */ function checkFunction( node: diff --git a/packages/eslint-plugin/src/types/eslint.d.ts b/packages/eslint-plugin/src/types/eslint.d.ts new file mode 100644 index 000000000000..2124fdd784b0 --- /dev/null +++ b/packages/eslint-plugin/src/types/eslint.d.ts @@ -0,0 +1,4 @@ +declare module 'eslint/lib/rules/utils/keywords' { + const keywords: string[]; + export default keywords; +} diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts new file mode 100644 index 000000000000..50764a5ca0de --- /dev/null +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -0,0 +1,3152 @@ +import { TSESLint } from '@typescript-eslint/experimental-utils'; +import rule, { MessageIds, Options, Option, RootOption } from '../../src/rules/keyword-spacing'; +import { RuleTester } from '../RuleTester'; + + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const BOTH = { before: true, after: true }; +const NEITHER = { before: false, after: false }; + + +/** + * Creates an option object to test an 'overrides' option. + * + * e.g. + * + * override('as', BOTH) + * + * returns + * + * { + * before: false, + * after: false, + * overrides: {as: {before: true, after: true}} + * } + * @param keyword A keyword to be overriden. + * @param value A value to override. + * @returns An option object to test an 'overrides' option. + */ +function override(keyword: string, value: Option): RootOption { + return { + before: value.before === false, + after: value.after === false, + overrides: { [keyword]: value }, + }; +} + +/** + * Gets an error message that expected space(s) before a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ +function expectedBefore(keyword: string): TSESLint.TestCaseError[] { + return [{ messageId: 'expectedBefore', data: { value: keyword } }]; +} + +/** +* Gets an error message that expected space(s) after a specified keyword. +* @param keyword A keyword. +* @returns An error message. +*/ +function expectedAfter(keyword: string): TSESLint.TestCaseError[] { + return [{ messageId: 'expectedAfter', data: { value: keyword } }]; +} + +/** +* Gets error messages that expected space(s) before and after a specified +* keyword. +* @param keyword A keyword. +* @returns Error messages. +*/ +function expectedBeforeAndAfter(keyword: string): TSESLint.TestCaseError[] { + return [ + { messageId: 'expectedBefore', data: { value: keyword } }, + { messageId: 'expectedAfter', data: { value: keyword } } + ]; +} + +/** +* Gets an error message that unexpected space(s) before a specified keyword. +* @param keyword A keyword. +* @returns An error message. +*/ +function unexpectedBefore(keyword: string): TSESLint.TestCaseError[] { + return [{ messageId: 'unexpectedBefore', data: { value: keyword } }]; +} + +/** +* Gets an error message that unexpected space(s) after a specified keyword. +* @param keyword A keyword. +* @returns An error message. +*/ +function unexpectedAfter(keyword: string): TSESLint.TestCaseError[] { + return [{ messageId: 'unexpectedAfter', data: { value: keyword } }]; +} + +/** +* Gets error messages that unexpected space(s) before and after a specified +* keyword. +* @param keyword A keyword. +* @returns Error messages. +*/ +function unexpectedBeforeAndAfter(keyword: string): TSESLint.TestCaseError[] { + return [ + { messageId: 'unexpectedBefore', data: { value: keyword } }, + { messageId: 'unexpectedAfter', data: { value: keyword } } + ]; +} + + +const ruleTester = new RuleTester({ + parser: '@typescript-eslint/parser', +}); + +ruleTester.run('keyword-spacing', rule, { + valid: [ + + //---------------------------------------------------------------------- + // as (import) + //---------------------------------------------------------------------- + + { code: 'import * as a from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import*as a from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import* as a from"foo"', options: [override('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import *as a from "foo"', options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + + //---------------------------------------------------------------------- + // as (typing) + //---------------------------------------------------------------------- + + { code: 'const foo = {} as {}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'const foo = {}as{}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'const foo = {} as {}', options: [override('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'const foo = {}as{}', options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + //---------------------------------------------------------------------- + // async + //---------------------------------------------------------------------- + + { code: '{} async function foo() {}', parserOptions: { ecmaVersion: 8 } }, + { code: '{}async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: '{} async function foo() {}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, + { code: '{}async function foo() {}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { code: '{} async () => {}', parserOptions: { ecmaVersion: 8 } }, + { code: '{}async () => {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: '{} async () => {}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, + { code: '{}async () => {}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { code: '({async [b]() {}})', parserOptions: { ecmaVersion: 8 } }, + { code: '({async[b]() {}})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: '({async [b]() {}})', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, + { code: '({async[b]() {}})', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { code: 'class A {a(){} async [b]() {}}', parserOptions: { ecmaVersion: 8 } }, + { code: 'class A {a(){}async[b]() {}}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: 'class A {a(){} async [b]() {}}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, + { code: 'class A {a(){}async[b]() {}}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `array-bracket-spacing` + { code: '[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, + { code: '[ async function foo() {}]', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `arrow-spacing` + { code: '() =>async function foo() {}', parserOptions: { ecmaVersion: 8 } }, + { code: '() => async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `block-spacing` + { code: '{async function foo() {} }', parserOptions: { ecmaVersion: 8 } }, + { code: '{ async function foo() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `comma-spacing` + { code: '(0,async function foo() {})', parserOptions: { ecmaVersion: 8 } }, + { code: '(0, async function foo() {})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `computed-property-spacing` + { code: 'a[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, + { code: '({[async function foo() {}]: 0})', parserOptions: { ecmaVersion: 8 } }, + { code: 'a[ async function foo() {}]', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: '({[ async function foo() {}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `generator-star-spacing` + { code: '({ async* foo() {} })', parserOptions: { ecmaVersion: 2018 } }, + { code: '({ async *foo() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 2018 } }, + + // not conflict with `key-spacing` + { code: '({a:async function foo() {} })', parserOptions: { ecmaVersion: 8 } }, + { code: '({a: async function foo() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `semi-spacing` + { code: ';async function foo() {};', parserOptions: { ecmaVersion: 8 } }, + { code: '; async function foo() {} ;', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-before-function-paren` + { code: 'async() => {}', parserOptions: { ecmaVersion: 8 } }, + { code: 'async () => {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-in-parens` + { code: '(async function foo() {})', parserOptions: { ecmaVersion: 8 } }, + { code: '( async function foo() {})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-infix-ops` + { code: 'a =async function foo() {}', parserOptions: { ecmaVersion: 8 } }, + { code: 'a = async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-unary-ops` + { code: '!async function foo() {}', parserOptions: { ecmaVersion: 8 } }, + { code: '! async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `template-curly-spacing` + { code: '`${async function foo() {}}`', parserOptions: { ecmaVersion: 8 } }, + { code: '`${ async function foo() {}}`', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // await + //---------------------------------------------------------------------- + + { code: 'async function wrap() { {} await +1 }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { {}await +1 }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { {} await +1 }', options: [override('await', BOTH)], parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { {}await +1 }', options: [override('await', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `array-bracket-spacing` + { code: 'async function wrap() { [await a] }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { [ await a] }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `arrow-spacing` + { code: 'async () =>await a', parserOptions: { ecmaVersion: 8 } }, + { code: 'async () => await a', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `block-spacing` + { code: 'async function wrap() { {await a } }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { { await a } }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `comma-spacing` + { code: 'async function wrap() { (0,await a) }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { (0, await a) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `computed-property-spacing` + { code: 'async function wrap() { a[await a] }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ({[await a]: 0}) }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { a[ await a] }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ({[ await a]: 0}) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `key-spacing` + { code: 'async function wrap() { ({a:await a }) }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ({a: await a }) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `semi-spacing` + { code: 'async function wrap() { ;await a; }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ; await a ; }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-in-parens` + { code: 'async function wrap() { (await a) }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ( await a) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-infix-ops` + { code: 'async function wrap() { a =await a }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { a = await a }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `space-unary-ops` + { code: 'async function wrap() { !await\'a\' }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { ! await \'a\' }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `template-curly-spacing` + { code: 'async function wrap() { `${await a}` }', parserOptions: { ecmaVersion: 8 } }, + { code: 'async function wrap() { `${ await a}` }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + + // not conflict with `jsx-curly-spacing` + { code: 'async function wrap() { }', parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { code: 'async function wrap() { }', options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // break + //---------------------------------------------------------------------- + + 'A: for (;;) { {} break A; }', + { code: 'A: for(;;) { {}break A; }', options: [NEITHER] }, + { code: 'A: for(;;) { {} break A; }', options: [override('break', BOTH)] }, + { code: 'A: for (;;) { {}break A; }', options: [override('break', NEITHER)] }, + + // not conflict with `block-spacing` + 'for (;;) {break}', + { code: 'for(;;) { break }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'for (;;) { ;break; }', + { code: 'for(;;) { ; break ; }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // case + //---------------------------------------------------------------------- + + 'switch (a) { case 0: {} case +1: }', + 'switch (a) { case 0: {} case (1): }', + { code: 'switch(a) { case 0: {}case+1: }', options: [NEITHER] }, + { code: 'switch(a) { case 0: {}case(1): }', options: [NEITHER] }, + { code: 'switch(a) { case 0: {} case +1: }', options: [override('case', BOTH)] }, + { code: 'switch (a) { case 0: {}case+1: }', options: [override('case', NEITHER)] }, + + // not conflict with `block-spacing` + 'switch (a) {case 0: }', + { code: 'switch(a) { case 0: }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'switch (a) { case 0: ;case 1: }', + { code: 'switch(a) { case 0: ; case 1: }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // catch + //---------------------------------------------------------------------- + + 'try {} catch (e) {}', + { code: 'try{}catch(e) {}', options: [NEITHER] }, + { code: 'try{} catch (e) {}', options: [override('catch', BOTH)] }, + { code: 'try {}catch(e) {}', options: [override('catch', NEITHER)] }, + 'try {}\ncatch (e) {}', + { code: 'try{}\ncatch(e) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // class + //---------------------------------------------------------------------- + + { code: '{} class Bar {}', parserOptions: { ecmaVersion: 6 } }, + { code: '(class {})', parserOptions: { ecmaVersion: 6 } }, + { code: '{}class Bar {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '(class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{} class Bar {}', options: [override('class', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}class Bar {}', options: [override('class', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `array-bracket-spacing` + { code: '[class {}]', parserOptions: { ecmaVersion: 6 } }, + { code: '[ class{}]', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `arrow-spacing` + { code: '() =>class {}', parserOptions: { ecmaVersion: 6 } }, + { code: '() => class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + { code: '{class Bar {} }', parserOptions: { ecmaVersion: 6 } }, + { code: '{ class Bar {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `comma-spacing` + { code: '(0,class {})', parserOptions: { ecmaVersion: 6 } }, + { code: '(0, class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `computed-property-spacing` + { code: 'a[class {}]', parserOptions: { ecmaVersion: 6 } }, + { code: '({[class {}]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ class{}]', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '({[ class{}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + { code: '({a:class {} })', parserOptions: { ecmaVersion: 6 } }, + { code: '({a: class{} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: ';class Bar {};', parserOptions: { ecmaVersion: 6 } }, + { code: '; class Bar {} ;', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-in-parens` + { code: '( class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-infix-ops` + { code: 'a =class {}', parserOptions: { ecmaVersion: 6 } }, + { code: 'a = class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-unary-ops` + { code: '!class {}', parserOptions: { ecmaVersion: 6 } }, + { code: '! class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `template-curly-spacing` + { code: '`${class {}}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ class{}}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // const + //---------------------------------------------------------------------- + + { code: '{} const [a] = b', parserOptions: { ecmaVersion: 6 } }, + { code: '{} const {a} = b', parserOptions: { ecmaVersion: 6 } }, + { code: '{}const[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{}const{a} = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{} const [a] = b', options: [override('const', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{} const {a} = b', options: [override('const', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}const[a] = b', options: [override('const', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}const{a} = b', options: [override('const', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + { code: '{const a = b}', parserOptions: { ecmaVersion: 6 } }, + { code: '{ const a = b}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: ';const a = b;', parserOptions: { ecmaVersion: 6 } }, + { code: '; const a = b ;', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // continue + //---------------------------------------------------------------------- + + 'A: for (;;) { {} continue A; }', + { code: 'A: for(;;) { {}continue A; }', options: [NEITHER] }, + { code: 'A: for(;;) { {} continue A; }', options: [override('continue', BOTH)] }, + { code: 'A: for (;;) { {}continue A; }', options: [override('continue', NEITHER)] }, + + // not conflict with `block-spacing` + 'for (;;) {continue}', + { code: 'for(;;) { continue }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'for (;;) { ;continue; }', + { code: 'for(;;) { ; continue ; }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // debugger + //---------------------------------------------------------------------- + + '{} debugger', + { code: '{}debugger', options: [NEITHER] }, + { code: '{} debugger', options: [override('debugger', BOTH)] }, + { code: '{}debugger', options: [override('debugger', NEITHER)] }, + + // not conflict with `block-spacing` + '{debugger}', + { code: '{ debugger }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';debugger;', + { code: '; debugger ;', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // default + //---------------------------------------------------------------------- + + 'switch (a) { case 0: {} default: }', + { code: 'switch(a) { case 0: {}default: }', options: [NEITHER] }, + { code: 'switch(a) { case 0: {} default: }', options: [override('default', BOTH)] }, + { code: 'switch (a) { case 0: {}default: }', options: [override('default', NEITHER)] }, + + // not conflict with `block-spacing` + 'switch (a) {default:}', + { code: 'switch(a) { default: }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'switch (a) { case 0: ;default: }', + { code: 'switch(a) { case 0: ; default: }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // delete + //---------------------------------------------------------------------- + + '{} delete foo.a', + { code: '{}delete foo.a', options: [NEITHER] }, + { code: '{} delete foo.a', options: [override('delete', BOTH)] }, + { code: '{}delete foo.a', options: [override('delete', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[delete foo.a]', + { code: '[ delete foo.a]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>delete foo.a)', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => delete foo.a)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{delete foo.a }', + { code: '{ delete foo.a }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,delete foo.a)', + { code: '(0, delete foo.a)', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[delete foo.a]', + { code: '({[delete foo.a]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ delete foo.a]', options: [NEITHER] }, + { code: '({[ delete foo.a]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:delete foo.a })', + { code: '({a: delete foo.a })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';delete foo.a', + { code: '; delete foo.a', options: [NEITHER] }, + + // not conflict with `space-in-parens` + '(delete foo.a)', + { code: '( delete foo.a)', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =delete foo.a', + { code: 'a = delete foo.a', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!delete(foo.a)', + { code: '! delete (foo.a)', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${delete foo.a}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ delete foo.a}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // do + //---------------------------------------------------------------------- + + '{} do {} while (true)', + { code: '{}do{}while(true)', options: [NEITHER] }, + { code: '{} do {}while(true)', options: [override('do', BOTH)] }, + { code: '{}do{} while (true)', options: [override('do', NEITHER)] }, + '{}\ndo\n{} while (true)', + { code: '{}\ndo\n{}while(true)', options: [NEITHER] }, + + // not conflict with `block-spacing` + '{do {} while (true)}', + { code: '{ do{}while(true) }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';do; while (true)', + { code: '; do ;while(true)', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // else + //---------------------------------------------------------------------- + + 'if (a) {} else {}', + 'if (a) {} else if (b) {}', + 'if (a) {} else (0)', + 'if (a) {} else []', + 'if (a) {} else +1', + 'if (a) {} else "a"', + { code: 'if(a){}else{}', options: [NEITHER] }, + { code: 'if(a){}else if(b) {}', options: [NEITHER] }, + { code: 'if(a) {}else(0)', options: [NEITHER] }, + { code: 'if(a) {}else[]', options: [NEITHER] }, + { code: 'if(a) {}else+1', options: [NEITHER] }, + { code: 'if(a) {}else"a"', options: [NEITHER] }, + { code: 'if(a) {} else {}', options: [override('else', BOTH)] }, + { code: 'if (a) {}else{}', options: [override('else', NEITHER)] }, + 'if (a) {}\nelse\n{}', + { code: 'if(a) {}\nelse\n{}', options: [NEITHER] }, + { code: 'if(a){ }else{ }', options: [{ before: false, after: true, overrides: { else: { after: false }, if: { after: false } } }] }, + { code: 'if(a){ }else{ }', options: [{ before: true, after: false, overrides: { else: { before: false }, if: { before: false } } }] }, + + // not conflict with `semi-spacing` + 'if (a);else;', + { code: 'if(a); else ;', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // export + //---------------------------------------------------------------------- + + { code: 'var a = 0; {} export {a}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} export default a', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} export * from "a"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'var a = 0; {}export{a}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'var a = 0; {} export {a}', options: [override('export', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'var a = 0; {}export{a}', options: [override('export', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + // not conflict with `semi-spacing` + { code: 'var a = 0;\n;export {a}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'var a = 0;\n; export{a}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + //---------------------------------------------------------------------- + // extends + //---------------------------------------------------------------------- + + { code: 'class Bar extends [] {}', parserOptions: { ecmaVersion: 6 } }, + { code: 'class Bar extends[] {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class Bar extends [] {}', options: [override('extends', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class Bar extends[] {}', options: [override('extends', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // finally + //---------------------------------------------------------------------- + + 'try {} finally {}', + { code: 'try{}finally{}', options: [NEITHER] }, + { code: 'try{} finally {}', options: [override('finally', BOTH)] }, + { code: 'try {}finally{}', options: [override('finally', NEITHER)] }, + 'try {}\nfinally\n{}', + { code: 'try{}\nfinally\n{}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // for + //---------------------------------------------------------------------- + + '{} for (;;) {}', + '{} for (var foo in obj) {}', + { code: '{} for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, + { code: '{}for(;;) {}', options: [NEITHER] }, + { code: '{}for(var foo in obj) {}', options: [NEITHER] }, + { code: '{}for(var foo of list) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{} for (;;) {}', options: [override('for', BOTH)] }, + { code: '{} for (var foo in obj) {}', options: [override('for', BOTH)] }, + { code: '{} for (var foo of list) {}', options: [override('for', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}for(;;) {}', options: [override('for', NEITHER)] }, + { code: '{}for(var foo in obj) {}', options: [override('for', NEITHER)] }, + { code: '{}for(var foo of list) {}', options: [override('for', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{for (;;) {} }', + '{for (var foo in obj) {} }', + { code: '{for (var foo of list) {} }', parserOptions: { ecmaVersion: 6 } }, + { code: '{ for(;;) {} }', options: [NEITHER] }, + { code: '{ for(var foo in obj) {} }', options: [NEITHER] }, + { code: '{ for(var foo of list) {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + ';for (;;) {}', + ';for (var foo in obj) {}', + { code: ';for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, + { code: '; for(;;) {}', options: [NEITHER] }, + { code: '; for(var foo in obj) {}', options: [NEITHER] }, + { code: '; for(var foo of list) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // from + //---------------------------------------------------------------------- + + { code: 'import {foo} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export {foo} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export * from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import{foo}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export{foo}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export*from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import{foo} from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export{foo} from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export* from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'import {foo}from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export {foo}from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: 'export *from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + //---------------------------------------------------------------------- + // function + //---------------------------------------------------------------------- + + '{} function foo() {}', + { code: '{}function foo() {}', options: [NEITHER] }, + { code: '{} function foo() {}', options: [override('function', BOTH)] }, + { code: '{}function foo() {}', options: [override('function', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[function() {}]', + { code: '[ function() {}]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>function() {})', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => function() {})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{function foo() {} }', + { code: '{ function foo() {} }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,function() {})', + { code: '(0, function() {})', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[function() {}]', + { code: '({[function() {}]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ function() {}]', options: [NEITHER] }, + { code: '({[ function(){}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `generator-star-spacing` + { code: 'function* foo() {}', parserOptions: { ecmaVersion: 6 } }, + { code: 'function *foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:function() {} })', + { code: '({a: function() {} })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';function foo() {};', + { code: '; function foo() {} ;', options: [NEITHER] }, + + /* + * not conflict with `space-before-function-paren` + * not conflict with `space-in-parens` + */ + '(function() {})', + { code: '( function () {})', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =function() {}', + { code: 'a = function() {}', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!function() {}', + { code: '! function() {}', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${function() {}}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ function() {}}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // get + //---------------------------------------------------------------------- + + { code: '({ get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} get [b]() {} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} static get [b]() {} }', parserOptions: { ecmaVersion: 6 } }, + { code: '({ get[b]() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}get[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}static get[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '({ get [b]() {} })', options: [override('get', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} get [b]() {} }', options: [override('get', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '({ get[b]() {} })', options: [override('get', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}get[b]() {} }', options: [override('get', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `comma-spacing` + { code: '({ a,get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, + { code: '({ a, get[b]() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // if + //---------------------------------------------------------------------- + + '{} if (a) {}', + 'if (a) {} else if (a) {}', + { code: '{}if(a) {}', options: [NEITHER] }, + { code: 'if(a) {}else if(a) {}', options: [NEITHER] }, + { code: '{} if (a) {}', options: [override('if', BOTH)] }, + { code: 'if (a) {}else if (a) {}', options: [override('if', BOTH)] }, + { code: '{}if(a) {}', options: [override('if', NEITHER)] }, + { code: 'if(a) {} else if(a) {}', options: [override('if', NEITHER)] }, + + // not conflict with `block-spacing` + '{if (a) {} }', + { code: '{ if(a) {} }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';if (a) {}', + { code: '; if(a) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // import + //---------------------------------------------------------------------- + + { code: '{} import {a} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} import a from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} import * as a from "a"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{}import{a}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{}import*as a from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} import {a}from"foo"', options: [override('import', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{} import *as a from"foo"', options: [override('import', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{}import{a} from "foo"', options: [override('import', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '{}import* as a from "foo"', options: [override('import', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + // not conflict with `semi-spacing` + { code: ';import {a} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { code: '; import{a}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + + //---------------------------------------------------------------------- + // in + //---------------------------------------------------------------------- + + { code: 'for ([foo] in {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, + { code: 'for([foo]in{foo: 0}) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'for([foo] in {foo: 0}) {}', options: [override('in', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'for ([foo]in{foo: 0}) {}', options: [override('in', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: 'for ([foo] in ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-infix-ops` + 'if ("foo"in{foo: 0}) {}', + { code: 'if("foo" in {foo: 0}) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // instanceof + //---------------------------------------------------------------------- + + // not conflict with `space-infix-ops` + 'if ("foo"instanceof{foo: 0}) {}', + { code: 'if("foo" instanceof {foo: 0}) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // let + //---------------------------------------------------------------------- + + { code: '{} let [a] = b', parserOptions: { ecmaVersion: 6 } }, + { code: '{}let[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{} let [a] = b', options: [override('let', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}let[a] = b', options: [override('let', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + { code: '{let [a] = b }', parserOptions: { ecmaVersion: 6 } }, + { code: '{ let[a] = b }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: ';let [a] = b', parserOptions: { ecmaVersion: 6 } }, + { code: '; let[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // new + //---------------------------------------------------------------------- + + '{} new foo()', + { code: '{}new foo()', options: [NEITHER] }, + { code: '{} new foo()', options: [override('new', BOTH)] }, + { code: '{}new foo()', options: [override('new', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[new foo()]', + { code: '[ new foo()]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>new foo())', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => new foo())', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{new foo() }', + { code: '{ new foo() }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,new foo())', + { code: '(0, new foo())', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[new foo()]', + { code: '({[new foo()]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ new foo()]', options: [NEITHER] }, + { code: '({[ new foo()]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:new foo() })', + { code: '({a: new foo() })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';new foo()', + { code: '; new foo()', options: [NEITHER] }, + + // not conflict with `space-in-parens` + '(new foo())', + { code: '( new foo())', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =new foo()', + { code: 'a = new foo()', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!new(foo)()', + { code: '! new (foo)()', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${new foo()}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ new foo()}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // of + //---------------------------------------------------------------------- + + { code: 'for ([foo] of {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, + { code: 'for([foo]of{foo: 0}) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'for([foo] of {foo: 0}) {}', options: [override('of', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'for ([foo]of{foo: 0}) {}', options: [override('of', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: 'for ([foo] of ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // return + //---------------------------------------------------------------------- + + 'function foo() { {} return +a }', + { code: 'function foo() { {}return+a }', options: [NEITHER] }, + { code: 'function foo() { {} return +a }', options: [override('return', BOTH)] }, + { code: 'function foo() { {}return+a }', options: [override('return', NEITHER)] }, + 'function foo() {\nreturn\n}', + { code: 'function foo() {\nreturn\n}', options: [NEITHER] }, + + // not conflict with `block-spacing` + 'function foo() {return}', + { code: 'function foo() { return }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'function foo() { ;return; }', + { code: 'function foo() { ; return ; }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // set + //---------------------------------------------------------------------- + + { code: '({ set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} set [b](value) {} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} static set [b](value) {} }', parserOptions: { ecmaVersion: 6 } }, + { code: '({ set[b](value) {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}set[b](value) {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '({ set [b](value) {} })', options: [override('set', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} set [b](value) {} }', options: [override('set', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '({ set[b](value) {} })', options: [override('set', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}set[b](value) {} }', options: [override('set', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `comma-spacing` + { code: '({ a,set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, + { code: '({ a, set[b](value) {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // static + //---------------------------------------------------------------------- + + { code: 'class A { a() {} static [b]() {} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}static[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {} static [b]() {} }', options: [override('static', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { a() {}static[b]() {} }', options: [override('static', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `generator-star-spacing` + { code: 'class A { static* [a]() {} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { static *[a]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: 'class A { ;static a() {} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A { ; static a() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + //---------------------------------------------------------------------- + // super + //---------------------------------------------------------------------- + + { code: 'class A extends B { a() { {} super[b](); } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { a() { {}super[b](); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { a() { {} super[b](); } }', options: [override('super', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { a() { {}super[b](); } }', options: [override('super', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `array-bracket-spacing` + { code: 'class A extends B { constructor() { [super()]; } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { [ super() ]; } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `arrow-spacing` + { code: 'class A extends B { constructor() { () =>super(); } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { () => super(); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + { code: 'class A extends B { constructor() {super()} }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `comma-spacing` + { code: 'class A extends B { constructor() { (0,super()) } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { (0, super()) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `computed-property-spacing` + { code: 'class A extends B { constructor() { ({[super()]: 0}) } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { ({[ super() ]: 0}) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + { code: 'class A extends B { constructor() { ({a:super() }) } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { ({a: super() }) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `func-call-spacing` + { code: 'class A extends B { constructor() { super(); } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { super (); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: 'class A extends B { constructor() { ;super(); } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { ; super() ; } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-in-parens` + { code: 'class A extends B { constructor() { (super()) } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { ( super() ) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-infix-ops` + { code: 'class A extends B { constructor() { b =super() } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { b = super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-unary-ops` + { code: 'class A extends B { constructor() { !super() } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { ! super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `template-curly-spacing` + { code: 'class A extends B { constructor() { `${super()}` } }', parserOptions: { ecmaVersion: 6 } }, + { code: 'class A extends B { constructor() { `${ super() }` } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: 'class A extends B { constructor() { } }', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: 'class A extends B { constructor() { } }', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // switch + //---------------------------------------------------------------------- + + '{} switch (a) {}', + { code: '{}switch(a) {}', options: [NEITHER] }, + { code: '{} switch (a) {}', options: [override('switch', BOTH)] }, + { code: '{}switch(a) {}', options: [override('switch', NEITHER)] }, + + // not conflict with `block-spacing` + '{switch (a) {} }', + { code: '{ switch(a) {} }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';switch (a) {}', + { code: '; switch(a) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // this + //---------------------------------------------------------------------- + + '{} this[a]', + { code: '{}this[a]', options: [NEITHER] }, + { code: '{} this[a]', options: [override('this', BOTH)] }, + { code: '{}this[a]', options: [override('this', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[this]', + { code: '[ this ]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>this)', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => this)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{this}', + { code: '{ this }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,this)', + { code: '(0, this)', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[this]', + { code: '({[this]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ this ]', options: [NEITHER] }, + { code: '({[ this ]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:this })', + { code: '({a: this })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';this', + { code: '; this', options: [NEITHER] }, + + // not conflict with `space-in-parens` + '(this)', + { code: '( this )', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =this', + { code: 'a = this', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!this', + { code: '! this', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${this}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ this }`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // throw + //---------------------------------------------------------------------- + + 'function foo() { {} throw +a }', + { code: 'function foo() { {}throw+a }', options: [NEITHER] }, + { code: 'function foo() { {} throw +a }', options: [override('throw', BOTH)] }, + { code: 'function foo() { {}throw+a }', options: [override('throw', NEITHER)] }, + 'function foo() {\nthrow a\n}', + { code: 'function foo() {\nthrow a\n}', options: [NEITHER] }, + + // not conflict with `block-spacing` + 'function foo() {throw a }', + { code: 'function foo() { throw a }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + 'function foo() { ;throw a }', + { code: 'function foo() { ; throw a }', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // try + //---------------------------------------------------------------------- + + '{} try {} finally {}', + { code: '{}try{}finally{}', options: [NEITHER] }, + { code: '{} try {}finally{}', options: [override('try', BOTH)] }, + { code: '{}try{} finally {}', options: [override('try', NEITHER)] }, + + // not conflict with `block-spacing` + '{try {} finally {}}', + { code: '{ try{}finally{}}', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';try {} finally {}', + { code: '; try{}finally{}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // typeof + //---------------------------------------------------------------------- + + '{} typeof foo', + { code: '{}typeof foo', options: [NEITHER] }, + { code: '{} typeof foo', options: [override('typeof', BOTH)] }, + { code: '{}typeof foo', options: [override('typeof', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[typeof foo]', + { code: '[ typeof foo]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>typeof foo)', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => typeof foo)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{typeof foo }', + { code: '{ typeof foo }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,typeof foo)', + { code: '(0, typeof foo)', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[typeof foo]', + { code: '({[typeof foo]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ typeof foo]', options: [NEITHER] }, + { code: '({[ typeof foo]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:typeof foo })', + { code: '({a: typeof foo })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';typeof foo', + { code: '; typeof foo', options: [NEITHER] }, + + // not conflict with `space-in-parens` + '(typeof foo)', + { code: '( typeof foo)', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =typeof foo', + { code: 'a = typeof foo', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!typeof+foo', + { code: '! typeof +foo', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${typeof foo}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ typeof foo}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // var + //---------------------------------------------------------------------- + + { code: '{} var [a] = b', parserOptions: { ecmaVersion: 6 } }, + { code: '{}var[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: '{} var [a] = b', options: [override('var', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: '{}var[a] = b', options: [override('var', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + 'for (var foo in [1, 2, 3]) {}', + + // not conflict with `block-spacing` + '{var a = b }', + { code: '{ var a = b }', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';var a = b', + { code: '; var a = b', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // void + //---------------------------------------------------------------------- + + '{} void foo', + { code: '{}void foo', options: [NEITHER] }, + { code: '{} void foo', options: [override('void', BOTH)] }, + { code: '{}void foo', options: [override('void', NEITHER)] }, + + // not conflict with `array-bracket-spacing` + '[void foo]', + { code: '[ void foo]', options: [NEITHER] }, + + // not conflict with `arrow-spacing` + { code: '(() =>void foo)', parserOptions: { ecmaVersion: 6 } }, + { code: '(() => void foo)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `block-spacing` + '{void foo }', + { code: '{ void foo }', options: [NEITHER] }, + + // not conflict with `comma-spacing` + '(0,void foo)', + { code: '(0, void foo)', options: [NEITHER] }, + + // not conflict with `computed-property-spacing` + 'a[void foo]', + { code: '({[void foo]: 0})', parserOptions: { ecmaVersion: 6 } }, + { code: 'a[ void foo]', options: [NEITHER] }, + { code: '({[ void foo]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + '({a:void foo })', + { code: '({a: void foo })', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';void foo', + { code: '; void foo', options: [NEITHER] }, + + // not conflict with `space-in-parens` + '(void foo)', + { code: '( void foo)', options: [NEITHER] }, + + // not conflict with `space-infix-ops` + 'a =void foo', + { code: 'a = void foo', options: [NEITHER] }, + + // not conflict with `space-unary-ops` + '!void+foo', + { code: '! void +foo', options: [NEITHER] }, + + // not conflict with `template-curly-spacing` + { code: '`${void foo}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ void foo}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // while + //---------------------------------------------------------------------- + + '{} while (a) {}', + 'do {} while (a)', + { code: '{}while(a) {}', options: [NEITHER] }, + { code: 'do{}while(a)', options: [NEITHER] }, + { code: '{} while (a) {}', options: [override('while', BOTH)] }, + { code: 'do{} while (a)', options: [override('while', BOTH)] }, + { code: '{}while(a) {}', options: [override('while', NEITHER)] }, + { code: 'do {}while(a)', options: [override('while', NEITHER)] }, + 'do {}\nwhile (a)', + { code: 'do{}\nwhile(a)', options: [NEITHER] }, + + // not conflict with `block-spacing` + '{while (a) {}}', + { code: '{ while(a) {}}', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';while (a);', + 'do;while (a);', + { code: '; while(a) ;', options: [NEITHER] }, + { code: 'do ; while(a) ;', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // with + //---------------------------------------------------------------------- + + '{} with (obj) {}', + { code: '{}with(obj) {}', options: [NEITHER] }, + { code: '{} with (obj) {}', options: [override('with', BOTH)] }, + { code: '{}with(obj) {}', options: [override('with', NEITHER)] }, + + // not conflict with `block-spacing` + '{with (obj) {}}', + { code: '{ with(obj) {}}', options: [NEITHER] }, + + // not conflict with `semi-spacing` + ';with (obj) {}', + { code: '; with(obj) {}', options: [NEITHER] }, + + //---------------------------------------------------------------------- + // yield + //---------------------------------------------------------------------- + + { code: 'function* foo() { {} yield foo }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { {}yield foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { {} yield foo }', options: [override('yield', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { {}yield foo }', options: [override('yield', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `array-bracket-spacing` + { code: 'function* foo() { [yield] }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { [ yield ] }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + /* + * This is invalid syntax: https://github.com/eslint/eslint/issues/5405 + * not conflict with `arrow-spacing` + * {code: 'function* foo() { (() =>yield foo) }', parserOptions: {ecmaVersion: 6}}, + * {code: 'function* foo() { (() => yield foo) }', options: [NEITHER], parserOptions: {ecmaVersion: 6}}, + * not conflict with `block-spacing` + */ + { code: 'function* foo() {yield}', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { yield }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `comma-spacing` + { code: 'function* foo() { (0,yield foo) }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { (0, yield foo) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `computed-property-spacing` + { code: 'function* foo() { a[yield] }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { ({[yield]: 0}) }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { a[ yield ] }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { ({[ yield ]: 0}) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `key-spacing` + { code: 'function* foo() { ({a:yield foo }) }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { ({a: yield foo }) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `semi-spacing` + { code: 'function* foo() { ;yield; }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { ; yield ; }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-in-parens` + { code: 'function* foo() { (yield) }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { ( yield ) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-infix-ops` + { code: 'function* foo() { a =yield foo }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { a = yield foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `space-unary-ops` + { code: 'function* foo() { yield+foo }', parserOptions: { ecmaVersion: 6 } }, + { code: 'function* foo() { yield +foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `template-curly-spacing` + { code: '`${yield}`', parserOptions: { ecmaVersion: 6 } }, + { code: '`${ yield}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + + // not conflict with `jsx-curly-spacing` + { code: 'function* foo() { }', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: 'function* foo() { }', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + + //---------------------------------------------------------------------- + // typescript parser + //---------------------------------------------------------------------- + + // // class declaration don't error with decorator + '@dec class Foo {}', + + // get, set, async methods don't error with decorator + 'class Foo { @dec get bar() {} @dec set baz() {} @dec async baw() {} }', + 'class Foo { @dec static qux() {} @dec static get bar() {} @dec static set baz() {} @dec static async baw() {} }', + + // type keywords can be used as parameters in arrow functions + 'symbol => 4;', + + ] as TSESLint.ValidTestCase[], + + invalid: [ + + //---------------------------------------------------------------------- + // as (import) + //---------------------------------------------------------------------- + + { + code: 'import *as a from "foo"', + output: 'import * as a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as') + }, + { + code: 'import* as a from"foo"', + output: 'import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as') + }, + { + code: 'import*as a from"foo"', + output: 'import* as a from"foo"', + options: [override('as', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as') + }, + { + code: 'import * as a from "foo"', + output: 'import *as a from "foo"', + options: [override('as', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as') + }, + + //---------------------------------------------------------------------- + // as (typing) + //---------------------------------------------------------------------- + + { + code: 'const foo = {}as {}', + output: 'const foo = {} as {}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as') + }, + { + code: 'const foo = {} as{}', + output: 'const foo = {}as{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as') + }, + + //---------------------------------------------------------------------- + // async + //---------------------------------------------------------------------- + + { + code: '{}async function foo() {}', + output: '{} async function foo() {}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async') + }, + { + code: '{} async function foo() {}', + output: '{}async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async') + }, + { + code: '{}async function foo() {}', + output: '{} async function foo() {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async') + }, + { + code: '{} async function foo() {}', + output: '{}async function foo() {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async') + }, + { + code: '{}async () => {}', + output: '{} async () => {}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async') + }, + { + code: '{} async () => {}', + output: '{}async () => {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async') + }, + { + code: '{}async () => {}', + output: '{} async () => {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async') + }, + { + code: '{} async () => {}', + output: '{}async () => {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async') + }, + { + code: '({async[b]() {}})', + output: '({async [b]() {}})', + parserOptions: { ecmaVersion: 8 }, + errors: expectedAfter('async') + }, + { + code: '({async [b]() {}})', + output: '({async[b]() {}})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter('async') + }, + { + code: '({async[b]() {}})', + output: '({async [b]() {}})', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedAfter('async') + }, + { + code: '({async [b]() {}})', + output: '({async[b]() {}})', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter('async') + }, + { + code: 'class A {a(){}async[b]() {}}', + output: 'class A {a(){} async [b]() {}}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter('async') + }, + { + code: 'class A {a(){} async [b]() {}}', + output: 'class A {a(){}async[b]() {}}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter('async') + }, + { + code: 'class A {a(){}async[b]() {}}', + output: 'class A {a(){} async [b]() {}}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter('async') + }, + { + code: 'class A {a(){} async [b]() {}}', + output: 'class A {a(){}async[b]() {}}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter('async') + }, + + //---------------------------------------------------------------------- + // await + //---------------------------------------------------------------------- + + { + code: 'async function wrap() { {}await a }', + output: 'async function wrap() { {} await a }', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('await') + }, + { + code: 'async function wrap() { {} await a }', + output: 'async function wrap() { {}await a }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('await') + }, + { + code: 'async function wrap() { {}await a }', + output: 'async function wrap() { {} await a }', + options: [override('await', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('await') + }, + { + code: 'async function wrap() { {} await a }', + output: 'async function wrap() { {}await a }', + options: [override('await', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('await') + }, + + { + code: 'async function wrap() { for await(x of xs); }', + output: 'async function wrap() { for await (x of xs); }', + parserOptions: { ecmaVersion: 2018 }, + errors: expectedAfter('await') + }, + { + code: 'async function wrap() { for await (x of xs); }', + output: 'async function wrap() { for await(x of xs); }', + options: [NEITHER], + parserOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter('await') + }, + { + code: 'async function wrap() { for await(x of xs); }', + output: 'async function wrap() { for await (x of xs); }', + options: [override('await', BOTH)], + parserOptions: { ecmaVersion: 2018 }, + errors: expectedAfter('await') + }, + { + code: 'async function wrap() { for await (x of xs); }', + output: 'async function wrap() { for await(x of xs); }', + options: [override('await', NEITHER)], + parserOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter('await') + }, + + //---------------------------------------------------------------------- + // break + //---------------------------------------------------------------------- + + { + code: 'A: for (;;) { {}break A; }', + output: 'A: for (;;) { {} break A; }', + errors: expectedBefore('break') + }, + { + code: 'A: for(;;) { {} break A; }', + output: 'A: for(;;) { {}break A; }', + options: [NEITHER], + errors: unexpectedBefore('break') + }, + { + code: 'A: for(;;) { {}break A; }', + output: 'A: for(;;) { {} break A; }', + options: [override('break', BOTH)], + errors: expectedBefore('break') + }, + { + code: 'A: for (;;) { {} break A; }', + output: 'A: for (;;) { {}break A; }', + options: [override('break', NEITHER)], + errors: unexpectedBefore('break') + }, + + //---------------------------------------------------------------------- + // case + //---------------------------------------------------------------------- + + { + code: 'switch (a) { case 0: {}case+1: }', + output: 'switch (a) { case 0: {} case +1: }', + errors: expectedBeforeAndAfter('case') + }, + { + code: 'switch (a) { case 0: {}case(1): }', + output: 'switch (a) { case 0: {} case (1): }', + errors: expectedBeforeAndAfter('case') + }, + { + code: 'switch(a) { case 0: {} case +1: }', + output: 'switch(a) { case 0: {}case+1: }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('case') + }, + { + code: 'switch(a) { case 0: {} case (1): }', + output: 'switch(a) { case 0: {}case(1): }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('case') + }, + { + code: 'switch(a) { case 0: {}case+1: }', + output: 'switch(a) { case 0: {} case +1: }', + options: [override('case', BOTH)], + errors: expectedBeforeAndAfter('case') + }, + { + code: 'switch (a) { case 0: {} case +1: }', + output: 'switch (a) { case 0: {}case+1: }', + options: [override('case', NEITHER)], + errors: unexpectedBeforeAndAfter('case') + }, + + //---------------------------------------------------------------------- + // catch + //---------------------------------------------------------------------- + + { + code: 'try {}catch(e) {}', + output: 'try {} catch (e) {}', + errors: expectedBeforeAndAfter('catch') + }, + { + code: 'try{} catch (e) {}', + output: 'try{}catch(e) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('catch') + }, + { + code: 'try{}catch(e) {}', + output: 'try{} catch (e) {}', + options: [override('catch', BOTH)], + errors: expectedBeforeAndAfter('catch') + }, + { + code: 'try {} catch (e) {}', + output: 'try {}catch(e) {}', + options: [override('catch', NEITHER)], + errors: unexpectedBeforeAndAfter('catch') + }, + + //---------------------------------------------------------------------- + // class + //---------------------------------------------------------------------- + + { + code: '{}class Bar {}', + output: '{} class Bar {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('class') + }, + { + code: '(class{})', + output: '(class {})', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('class') + }, + { + code: '{} class Bar {}', + output: '{}class Bar {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('class') + }, + { + code: '(class {})', + output: '(class{})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('class') + }, + { + code: '{}class Bar {}', + output: '{} class Bar {}', + options: [override('class', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('class') + }, + { + code: '{} class Bar {}', + output: '{}class Bar {}', + options: [override('class', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('class') + }, + + //---------------------------------------------------------------------- + // const + //---------------------------------------------------------------------- + + { + code: '{}const[a] = b', + output: '{} const [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const') + }, + { + code: '{}const{a} = b', + output: '{} const {a} = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const') + }, + { + code: '{} const [a] = b', + output: '{}const[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const') + }, + { + code: '{} const {a} = b', + output: '{}const{a} = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const') + }, + { + code: '{}const[a] = b', + output: '{} const [a] = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const') + }, + { + code: '{}const{a} = b', + output: '{} const {a} = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const') + }, + { + code: '{} const [a] = b', + output: '{}const[a] = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const') + }, + { + code: '{} const {a} = b', + output: '{}const{a} = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const') + }, + + //---------------------------------------------------------------------- + // continue + //---------------------------------------------------------------------- + + { + code: 'A: for (;;) { {}continue A; }', + output: 'A: for (;;) { {} continue A; }', + errors: expectedBefore('continue') + }, + { + code: 'A: for(;;) { {} continue A; }', + output: 'A: for(;;) { {}continue A; }', + options: [NEITHER], + errors: unexpectedBefore('continue') + }, + { + code: 'A: for(;;) { {}continue A; }', + output: 'A: for(;;) { {} continue A; }', + options: [override('continue', BOTH)], + errors: expectedBefore('continue') + }, + { + code: 'A: for (;;) { {} continue A; }', + output: 'A: for (;;) { {}continue A; }', + options: [override('continue', NEITHER)], + errors: unexpectedBefore('continue') + }, + + //---------------------------------------------------------------------- + // debugger + //---------------------------------------------------------------------- + + { + code: '{}debugger', + output: '{} debugger', + errors: expectedBefore('debugger') + }, + { + code: '{} debugger', + output: '{}debugger', + options: [NEITHER], + errors: unexpectedBefore('debugger') + }, + { + code: '{}debugger', + output: '{} debugger', + options: [override('debugger', BOTH)], + errors: expectedBefore('debugger') + }, + { + code: '{} debugger', + output: '{}debugger', + options: [override('debugger', NEITHER)], + errors: unexpectedBefore('debugger') + }, + + //---------------------------------------------------------------------- + // default + //---------------------------------------------------------------------- + + { + code: 'switch (a) { case 0: {}default: }', + output: 'switch (a) { case 0: {} default: }', + errors: expectedBefore('default') + }, + { + code: 'switch(a) { case 0: {} default: }', + output: 'switch(a) { case 0: {}default: }', + options: [NEITHER], + errors: unexpectedBefore('default') + }, + { + code: 'switch(a) { case 0: {}default: }', + output: 'switch(a) { case 0: {} default: }', + options: [override('default', BOTH)], + errors: expectedBefore('default') + }, + { + code: 'switch (a) { case 0: {} default: }', + output: 'switch (a) { case 0: {}default: }', + options: [override('default', NEITHER)], + errors: unexpectedBefore('default') + }, + + //---------------------------------------------------------------------- + // delete + //---------------------------------------------------------------------- + + { + code: '{}delete foo.a', + output: '{} delete foo.a', + errors: expectedBefore('delete') + }, + { + code: '{} delete foo.a', + output: '{}delete foo.a', + options: [NEITHER], + errors: unexpectedBefore('delete') + }, + { + code: '{}delete foo.a', + output: '{} delete foo.a', + options: [override('delete', BOTH)], + errors: expectedBefore('delete') + }, + { + code: '{} delete foo.a', + output: '{}delete foo.a', + options: [override('delete', NEITHER)], + errors: unexpectedBefore('delete') + }, + + //---------------------------------------------------------------------- + // do + //---------------------------------------------------------------------- + + { + code: '{}do{} while (true)', + output: '{} do {} while (true)', + errors: expectedBeforeAndAfter('do') + }, + { + code: '{} do {}while(true)', + output: '{}do{}while(true)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('do') + }, + { + code: '{}do{}while(true)', + output: '{} do {}while(true)', + options: [override('do', BOTH)], + errors: expectedBeforeAndAfter('do') + }, + { + code: '{} do {} while (true)', + output: '{}do{} while (true)', + options: [override('do', NEITHER)], + errors: unexpectedBeforeAndAfter('do') + }, + + //---------------------------------------------------------------------- + // else + //---------------------------------------------------------------------- + + { + code: 'if (a) {}else{}', + output: 'if (a) {} else {}', + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if (a) {}else if (b) {}', + output: 'if (a) {} else if (b) {}', + errors: expectedBefore('else') + }, + { + code: 'if (a) {}else(0)', + output: 'if (a) {} else (0)', + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if (a) {}else[]', + output: 'if (a) {} else []', + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if (a) {}else+1', + output: 'if (a) {} else +1', + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if (a) {}else"a"', + output: 'if (a) {} else "a"', + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if(a){} else {}', + output: 'if(a){}else{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else') + }, + { + code: 'if(a){} else if(b) {}', + output: 'if(a){}else if(b) {}', + options: [NEITHER], + errors: unexpectedBefore('else') + }, + { + code: 'if(a) {} else (0)', + output: 'if(a) {}else(0)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else') + }, + { + code: 'if(a) {} else []', + output: 'if(a) {}else[]', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else') + }, + { + code: 'if(a) {} else +1', + output: 'if(a) {}else+1', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else') + }, + { + code: 'if(a) {} else "a"', + output: 'if(a) {}else"a"', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else') + }, + { + code: 'if(a) {}else{}', + output: 'if(a) {} else {}', + options: [override('else', BOTH)], + errors: expectedBeforeAndAfter('else') + }, + { + code: 'if (a) {} else {}', + output: 'if (a) {}else{}', + options: [override('else', NEITHER)], + errors: unexpectedBeforeAndAfter('else') + }, + + { + code: 'if (a) {}else {}', + output: 'if (a) {} else {}', + errors: expectedBefore('else') + }, + { + code: 'if (a) {} else{}', + output: 'if (a) {} else {}', + errors: expectedAfter('else') + }, + { + code: 'if(a) {} else{}', + output: 'if(a) {}else{}', + options: [NEITHER], + errors: unexpectedBefore('else') + }, + { + code: 'if(a) {}else {}', + output: 'if(a) {}else{}', + options: [NEITHER], + errors: unexpectedAfter('else') + }, + + //---------------------------------------------------------------------- + // export + //---------------------------------------------------------------------- + + { + code: 'var a = 0; {}export{a}', + output: 'var a = 0; {} export {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export') + }, + { + code: 'var a = 0; {}export default a', + output: 'var a = 0; {} export default a', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('export') + }, + { + code: 'var a = 0; export default{a}', + output: 'var a = 0; export default {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedAfter('default') + }, + { + code: '{}export* from "a"', + output: '{} export * from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export') + }, + { + code: 'var a = 0; {} export {a}', + output: 'var a = 0; {}export{a}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('export') + }, + { + code: 'var a = 0; {}export{a}', + output: 'var a = 0; {} export {a}', + options: [override('export', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export') + }, + { + code: 'var a = 0; {} export {a}', + output: 'var a = 0; {}export{a}', + options: [override('export', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('export') + }, + + //---------------------------------------------------------------------- + // extends + //---------------------------------------------------------------------- + + { + code: 'class Bar extends[] {}', + output: 'class Bar extends [] {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends') + }, + { + code: '(class extends[] {})', + output: '(class extends [] {})', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends') + }, + { + code: 'class Bar extends [] {}', + output: 'class Bar extends[] {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends') + }, + { + code: '(class extends [] {})', + output: '(class extends[] {})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends') + }, + { + code: 'class Bar extends[] {}', + output: 'class Bar extends [] {}', + options: [override('extends', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends') + }, + { + code: 'class Bar extends [] {}', + output: 'class Bar extends[] {}', + options: [override('extends', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends') + }, + { + code: 'class Bar extends`}` {}', + output: 'class Bar extends `}` {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends') + }, + + //---------------------------------------------------------------------- + // finally + //---------------------------------------------------------------------- + + { + code: 'try {}finally{}', + output: 'try {} finally {}', + errors: expectedBeforeAndAfter('finally') + }, + { + code: 'try{} finally {}', + output: 'try{}finally{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('finally') + }, + { + code: 'try{}finally{}', + output: 'try{} finally {}', + options: [override('finally', BOTH)], + errors: expectedBeforeAndAfter('finally') + }, + { + code: 'try {} finally {}', + output: 'try {}finally{}', + options: [override('finally', NEITHER)], + errors: unexpectedBeforeAndAfter('finally') + }, + + //---------------------------------------------------------------------- + // for + //---------------------------------------------------------------------- + + { + code: '{}for(;;) {}', + output: '{} for (;;) {}', + errors: expectedBeforeAndAfter('for') + }, + { + code: '{}for(var foo in obj) {}', + output: '{} for (var foo in obj) {}', + errors: expectedBeforeAndAfter('for') + }, + { + code: '{}for(var foo of list) {}', + output: '{} for (var foo of list) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('for') + }, + { + code: '{} for (;;) {}', + output: '{}for(;;) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('for') + }, + { + code: '{} for (var foo in obj) {}', + output: '{}for(var foo in obj) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('for') + }, + { + code: '{} for (var foo of list) {}', + output: '{}for(var foo of list) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('for') + }, + { + code: '{}for(;;) {}', + output: '{} for (;;) {}', + options: [override('for', BOTH)], + errors: expectedBeforeAndAfter('for') + }, + { + code: '{}for(var foo in obj) {}', + output: '{} for (var foo in obj) {}', + options: [override('for', BOTH)], + errors: expectedBeforeAndAfter('for') + }, + { + code: '{}for(var foo of list) {}', + output: '{} for (var foo of list) {}', + options: [override('for', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('for') + }, + { + code: '{} for (;;) {}', + output: '{}for(;;) {}', + options: [override('for', NEITHER)], + errors: unexpectedBeforeAndAfter('for') + }, + { + code: '{} for (var foo in obj) {}', + output: '{}for(var foo in obj) {}', + options: [override('for', NEITHER)], + errors: unexpectedBeforeAndAfter('for') + }, + { + code: '{} for (var foo of list) {}', + output: '{}for(var foo of list) {}', + options: [override('for', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('for') + }, + + //---------------------------------------------------------------------- + // from + //---------------------------------------------------------------------- + + { + code: 'import {foo}from"foo"', + output: 'import {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'export {foo}from"foo"', + output: 'export {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'export *from"foo"', + output: 'export * from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'import{foo} from "foo"', + output: 'import{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + { + code: 'export{foo} from "foo"', + output: 'export{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + { + code: 'export* from "foo"', + output: 'export*from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + { + code: 'import{foo}from"foo"', + output: 'import{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'export{foo}from"foo"', + output: 'export{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'export*from"foo"', + output: 'export* from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from') + }, + { + code: 'import {foo} from "foo"', + output: 'import {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + { + code: 'export {foo} from "foo"', + output: 'export {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + { + code: 'export * from "foo"', + output: 'export *from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from') + }, + + //---------------------------------------------------------------------- + // function + //---------------------------------------------------------------------- + + { + code: '{}function foo() {}', + output: '{} function foo() {}', + errors: expectedBefore('function') + }, + { + code: '{} function foo() {}', + output: '{}function foo() {}', + options: [NEITHER], + errors: unexpectedBefore('function') + }, + { + code: '{}function foo() {}', + output: '{} function foo() {}', + options: [override('function', BOTH)], + errors: expectedBefore('function') + }, + { + code: '{} function foo() {}', + output: '{}function foo() {}', + options: [override('function', NEITHER)], + errors: unexpectedBefore('function') + }, + + //---------------------------------------------------------------------- + // get + //---------------------------------------------------------------------- + + { + code: '({ get[b]() {} })', + output: '({ get [b]() {} })', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get') + }, + { + code: 'class A { a() {}get[b]() {} }', + output: 'class A { a() {} get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('get') + }, + { + code: 'class A { a() {} static get[b]() {} }', + output: 'class A { a() {} static get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get') + }, + { + code: '({ get [b]() {} })', + output: '({ get[b]() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get') + }, + { + code: 'class A { a() {} get [b]() {} }', + output: 'class A { a() {}get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('get') + }, + { + code: 'class A { a() {}static get [b]() {} }', + output: 'class A { a() {}static get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get') + }, + { + code: '({ get[b]() {} })', + output: '({ get [b]() {} })', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get') + }, + { + code: 'class A { a() {}get[b]() {} }', + output: 'class A { a() {} get [b]() {} }', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('get') + }, + { + code: '({ get [b]() {} })', + output: '({ get[b]() {} })', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get') + }, + { + code: 'class A { a() {} get [b]() {} }', + output: 'class A { a() {}get[b]() {} }', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('get') + }, + + //---------------------------------------------------------------------- + // if + //---------------------------------------------------------------------- + + { + code: '{}if(a) {}', + output: '{} if (a) {}', + errors: expectedBeforeAndAfter('if') + }, + { + code: 'if (a) {} else if(b) {}', + output: 'if (a) {} else if (b) {}', + errors: expectedAfter('if') + }, + { + code: '{} if (a) {}', + output: '{}if(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('if') + }, + { + code: 'if(a) {}else if (b) {}', + output: 'if(a) {}else if(b) {}', + options: [NEITHER], + errors: unexpectedAfter('if') + }, + { + code: '{}if(a) {}', + output: '{} if (a) {}', + options: [override('if', BOTH)], + errors: expectedBeforeAndAfter('if') + }, + { + code: 'if (a) {}else if(b) {}', + output: 'if (a) {}else if (b) {}', + options: [override('if', BOTH)], + errors: expectedAfter('if') + }, + { + code: '{} if (a) {}', + output: '{}if(a) {}', + options: [override('if', NEITHER)], + errors: unexpectedBeforeAndAfter('if') + }, + { + code: 'if(a) {} else if (b) {}', + output: 'if(a) {} else if(b) {}', + options: [override('if', NEITHER)], + errors: unexpectedAfter('if') + }, + + //---------------------------------------------------------------------- + // import + //---------------------------------------------------------------------- + + { + code: '{}import{a} from "foo"', + output: '{} import {a} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import') + }, + { + code: '{}import a from "foo"', + output: '{} import a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('import') + }, + { + code: '{}import* as a from "a"', + output: '{} import * as a from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import') + }, + { + code: '{} import {a}from"foo"', + output: '{}import{a}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import') + }, + { + code: '{} import *as a from"foo"', + output: '{}import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import') + }, + { + code: '{}import{a}from"foo"', + output: '{} import {a}from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import') + }, + { + code: '{}import*as a from"foo"', + output: '{} import *as a from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import') + }, + { + code: '{} import {a} from "foo"', + output: '{}import{a} from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import') + }, + { + code: '{} import * as a from "foo"', + output: '{}import* as a from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import') + }, + + //---------------------------------------------------------------------- + // in + //---------------------------------------------------------------------- + + { + code: 'for ([foo]in{foo: 0}) {}', + output: 'for ([foo] in {foo: 0}) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('in') + }, + { + code: 'for([foo] in {foo: 0}) {}', + output: 'for([foo]in{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('in') + }, + { + code: 'for([foo]in{foo: 0}) {}', + output: 'for([foo] in {foo: 0}) {}', + options: [override('in', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('in') + }, + { + code: 'for ([foo] in {foo: 0}) {}', + output: 'for ([foo]in{foo: 0}) {}', + options: [override('in', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('in') + }, + + //---------------------------------------------------------------------- + // instanceof + //---------------------------------------------------------------------- + + // ignores + + //---------------------------------------------------------------------- + // let + //---------------------------------------------------------------------- + + { + code: '{}let[a] = b', + output: '{} let [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('let') + }, + { + code: '{} let [a] = b', + output: '{}let[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('let') + }, + { + code: '{}let[a] = b', + output: '{} let [a] = b', + options: [override('let', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('let') + }, + { + code: '{} let [a] = b', + output: '{}let[a] = b', + options: [override('let', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('let') + }, + + //---------------------------------------------------------------------- + // new + //---------------------------------------------------------------------- + + { + code: '{}new foo()', + output: '{} new foo()', + errors: expectedBefore('new') + }, + { + code: '{} new foo()', + output: '{}new foo()', + options: [NEITHER], + errors: unexpectedBefore('new') + }, + { + code: '{}new foo()', + output: '{} new foo()', + options: [override('new', BOTH)], + errors: expectedBefore('new') + }, + { + code: '{} new foo()', + output: '{}new foo()', + options: [override('new', NEITHER)], + errors: unexpectedBefore('new') + }, + + //---------------------------------------------------------------------- + // of + //---------------------------------------------------------------------- + + { + code: 'for ([foo]of{foo: 0}) {}', + output: 'for ([foo] of {foo: 0}) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('of') + }, + { + code: 'for([foo] of {foo: 0}) {}', + output: 'for([foo]of{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('of') + }, + { + code: 'for([foo]of{foo: 0}) {}', + output: 'for([foo] of {foo: 0}) {}', + options: [override('of', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('of') + }, + { + code: 'for ([foo] of {foo: 0}) {}', + output: 'for ([foo]of{foo: 0}) {}', + options: [override('of', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('of') + }, + + //---------------------------------------------------------------------- + // return + //---------------------------------------------------------------------- + + { + code: 'function foo() { {}return+a }', + output: 'function foo() { {} return +a }', + errors: expectedBeforeAndAfter('return') + }, + { + code: 'function foo() { {} return +a }', + output: 'function foo() { {}return+a }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('return') + }, + { + code: 'function foo() { {}return+a }', + output: 'function foo() { {} return +a }', + options: [override('return', BOTH)], + errors: expectedBeforeAndAfter('return') + }, + { + code: 'function foo() { {} return +a }', + output: 'function foo() { {}return+a }', + options: [override('return', NEITHER)], + errors: unexpectedBeforeAndAfter('return') + }, + + //---------------------------------------------------------------------- + // set + //---------------------------------------------------------------------- + + { + code: '({ set[b](value) {} })', + output: '({ set [b](value) {} })', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set') + }, + { + code: 'class A { a() {}set[b](value) {} }', + output: 'class A { a() {} set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('set') + }, + { + code: 'class A { a() {} static set[b](value) {} }', + output: 'class A { a() {} static set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set') + }, + { + code: '({ set [b](value) {} })', + output: '({ set[b](value) {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('set') + }, + { + code: 'class A { a() {} set [b](value) {} }', + output: 'class A { a() {}set[b](value) {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('set') + }, + { + code: '({ set[b](value) {} })', + output: '({ set [b](value) {} })', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set') + }, + { + code: 'class A { a() {}set[b](value) {} }', + output: 'class A { a() {} set [b](value) {} }', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('set') + }, + { + code: '({ set [b](value) {} })', + output: '({ set[b](value) {} })', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('set') + }, + { + code: 'class A { a() {} set [b](value) {} }', + output: 'class A { a() {}set[b](value) {} }', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('set') + }, + + //---------------------------------------------------------------------- + // static + //---------------------------------------------------------------------- + + { + code: 'class A { a() {}static[b]() {} }', + output: 'class A { a() {} static [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('static') + }, + { + code: 'class A { a() {}static get [b]() {} }', + output: 'class A { a() {} static get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('static') + }, + { + code: 'class A { a() {} static [b]() {} }', + output: 'class A { a() {}static[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('static') + }, + { + code: 'class A { a() {} static get[b]() {} }', + output: 'class A { a() {}static get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('static') + }, + { + code: 'class A { a() {}static[b]() {} }', + output: 'class A { a() {} static [b]() {} }', + options: [override('static', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('static') + }, + { + code: 'class A { a() {} static [b]() {} }', + output: 'class A { a() {}static[b]() {} }', + options: [override('static', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('static') + }, + + //---------------------------------------------------------------------- + // super + //---------------------------------------------------------------------- + + { + code: 'class A { a() { {}super[b]; } }', + output: 'class A { a() { {} super[b]; } }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('super') + }, + { + code: 'class A { a() { {} super[b]; } }', + output: 'class A { a() { {}super[b]; } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('super') + }, + { + code: 'class A { a() { {}super[b]; } }', + output: 'class A { a() { {} super[b]; } }', + options: [override('super', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('super') + }, + { + code: 'class A { a() { {} super[b]; } }', + output: 'class A { a() { {}super[b]; } }', + options: [override('super', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('super') + }, + + //---------------------------------------------------------------------- + // switch + //---------------------------------------------------------------------- + + { + code: '{}switch(a) {}', + output: '{} switch (a) {}', + errors: expectedBeforeAndAfter('switch') + }, + { + code: '{} switch (a) {}', + output: '{}switch(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('switch') + }, + { + code: '{}switch(a) {}', + output: '{} switch (a) {}', + options: [override('switch', BOTH)], + errors: expectedBeforeAndAfter('switch') + }, + { + code: '{} switch (a) {}', + output: '{}switch(a) {}', + options: [override('switch', NEITHER)], + errors: unexpectedBeforeAndAfter('switch') + }, + + //---------------------------------------------------------------------- + // this + //---------------------------------------------------------------------- + + { + code: '{}this[a]', + output: '{} this[a]', + errors: expectedBefore('this') + }, + { + code: '{} this[a]', + output: '{}this[a]', + options: [NEITHER], + errors: unexpectedBefore('this') + }, + { + code: '{}this[a]', + output: '{} this[a]', + options: [override('this', BOTH)], + errors: expectedBefore('this') + }, + { + code: '{} this[a]', + output: '{}this[a]', + options: [override('this', NEITHER)], + errors: unexpectedBefore('this') + }, + + //---------------------------------------------------------------------- + // throw + //---------------------------------------------------------------------- + + { + code: 'function foo() { {}throw+a }', + output: 'function foo() { {} throw +a }', + errors: expectedBeforeAndAfter('throw') + }, + { + code: 'function foo() { {} throw +a }', + output: 'function foo() { {}throw+a }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('throw') + }, + { + code: 'function foo() { {}throw+a }', + output: 'function foo() { {} throw +a }', + options: [override('throw', BOTH)], + errors: expectedBeforeAndAfter('throw') + }, + { + code: 'function foo() { {} throw +a }', + output: 'function foo() { {}throw+a }', + options: [override('throw', NEITHER)], + errors: unexpectedBeforeAndAfter('throw') + }, + + //---------------------------------------------------------------------- + // try + //---------------------------------------------------------------------- + + { + code: '{}try{} finally {}', + output: '{} try {} finally {}', + errors: expectedBeforeAndAfter('try') + }, + { + code: '{} try {}finally{}', + output: '{}try{}finally{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('try') + }, + { + code: '{}try{}finally{}', + output: '{} try {}finally{}', + options: [override('try', BOTH)], + errors: expectedBeforeAndAfter('try') + }, + { + code: '{} try {} finally {}', + output: '{}try{} finally {}', + options: [override('try', NEITHER)], + errors: unexpectedBeforeAndAfter('try') + }, + + //---------------------------------------------------------------------- + // typeof + //---------------------------------------------------------------------- + + { + code: '{}typeof foo', + output: '{} typeof foo', + errors: expectedBefore('typeof') + }, + { + code: '{} typeof foo', + output: '{}typeof foo', + options: [NEITHER], + errors: unexpectedBefore('typeof') + }, + { + code: '{}typeof foo', + output: '{} typeof foo', + options: [override('typeof', BOTH)], + errors: expectedBefore('typeof') + }, + { + code: '{} typeof foo', + output: '{}typeof foo', + options: [override('typeof', NEITHER)], + errors: unexpectedBefore('typeof') + }, + + //---------------------------------------------------------------------- + // var + //---------------------------------------------------------------------- + + { + code: '{}var[a] = b', + output: '{} var [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('var') + }, + { + code: '{} var [a] = b', + output: '{}var[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('var') + }, + { + code: '{}var[a] = b', + output: '{} var [a] = b', + options: [override('var', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('var') + }, + { + code: '{} var [a] = b', + output: '{}var[a] = b', + options: [override('var', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('var') + }, + + //---------------------------------------------------------------------- + // void + //---------------------------------------------------------------------- + + { + code: '{}void foo', + output: '{} void foo', + errors: expectedBefore('void') + }, + { + code: '{} void foo', + output: '{}void foo', + options: [NEITHER], + errors: unexpectedBefore('void') + }, + { + code: '{}void foo', + output: '{} void foo', + options: [override('void', BOTH)], + errors: expectedBefore('void') + }, + { + code: '{} void foo', + output: '{}void foo', + options: [override('void', NEITHER)], + errors: unexpectedBefore('void') + }, + + //---------------------------------------------------------------------- + // while + //---------------------------------------------------------------------- + + { + code: '{}while(a) {}', + output: '{} while (a) {}', + errors: expectedBeforeAndAfter('while') + }, + { + code: 'do {}while(a)', + output: 'do {} while (a)', + errors: expectedBeforeAndAfter('while') + }, + { + code: '{} while (a) {}', + output: '{}while(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('while') + }, + { + code: 'do{} while (a)', + output: 'do{}while(a)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('while') + }, + { + code: '{}while(a) {}', + output: '{} while (a) {}', + options: [override('while', BOTH)], + errors: expectedBeforeAndAfter('while') + }, + { + code: 'do{}while(a)', + output: 'do{} while (a)', + options: [override('while', BOTH)], + errors: expectedBeforeAndAfter('while') + }, + { + code: '{} while (a) {}', + output: '{}while(a) {}', + options: [override('while', NEITHER)], + errors: unexpectedBeforeAndAfter('while') + }, + { + code: 'do {} while (a)', + output: 'do {}while(a)', + options: [override('while', NEITHER)], + errors: unexpectedBeforeAndAfter('while') + }, + + //---------------------------------------------------------------------- + // with + //---------------------------------------------------------------------- + + { + code: '{}with(obj) {}', + output: '{} with (obj) {}', + errors: expectedBeforeAndAfter('with') + }, + { + code: '{} with (obj) {}', + output: '{}with(obj) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('with') + }, + { + code: '{}with(obj) {}', + output: '{} with (obj) {}', + options: [override('with', BOTH)], + errors: expectedBeforeAndAfter('with') + }, + { + code: '{} with (obj) {}', + output: '{}with(obj) {}', + options: [override('with', NEITHER)], + errors: unexpectedBeforeAndAfter('with') + }, + + //---------------------------------------------------------------------- + // yield + //---------------------------------------------------------------------- + + { + code: 'function* foo() { {}yield foo }', + output: 'function* foo() { {} yield foo }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('yield') + }, + { + code: 'function* foo() { {} yield foo }', + output: 'function* foo() { {}yield foo }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('yield') + }, + { + code: 'function* foo() { {}yield foo }', + output: 'function* foo() { {} yield foo }', + options: [override('yield', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('yield') + }, + { + code: 'function* foo() { {} yield foo }', + output: 'function* foo() { {}yield foo }', + options: [override('yield', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('yield') + }, + + //---------------------------------------------------------------------- + // typescript parser + //---------------------------------------------------------------------- + + // get, set, async decorator keywords shouldn't be detected + { + code: 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }', + output: 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }', + errors: expectedAfter('async') + } + + ] as TSESLint.InvalidTestCase[], +}); diff --git a/yarn.lock b/yarn.lock index 04ba7af56f04..52d7ab971d75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,9 +1564,9 @@ acorn-walk@^6.0.1: integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA== acorn@^6.0.1: - version "6.4.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474" - integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== + version "6.4.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.0.tgz#b659d2ffbafa24baf5db1cdbb2c94a983ecd2784" + integrity sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw== acorn@^7.1.0: version "7.1.0" From fca75e70ef86a819b8f2ac450313b15d8d0e4453 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:15:07 +0100 Subject: [PATCH 02/31] Cleaned --- packages/eslint-plugin/src/rules/index.ts | 2 +- packages/eslint-plugin/src/rules/keyword-spacing.ts | 2 +- .../src/rules/space-before-function-paren.ts | 10 ++++++---- yarn.lock | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index 4f1433275855..63c402297e39 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -32,10 +32,10 @@ import noDynamicDelete from './no-dynamic-delete'; import noEmptyFunction from './no-empty-function'; import noEmptyInterface from './no-empty-interface'; import noExplicitAny from './no-explicit-any'; +import noExtraneousClass from './no-extraneous-class'; import noExtraNonNullAssertion from './no-extra-non-null-assertion'; import noExtraParens from './no-extra-parens'; import noExtraSemi from './no-extra-semi'; -import noExtraneousClass from './no-extraneous-class'; import noFloatingPromises from './no-floating-promises'; import noForInArray from './no-for-in-array'; import noImpliedEval from './no-implied-eval'; diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 4069f62f9c28..9da38a80fc17 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -5,8 +5,8 @@ import { JSONSchema4 } from 'json-schema'; import { isTokenOnSameLine, isKeywordToken, - isNotOpeningParenToken, } from '../util/astUtils'; +import { isNotOpeningParenToken } from 'eslint-utils'; export type Option = Partial<{ before: boolean; diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index 200bb39b2900..bc2ad8b0d047 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -68,8 +68,8 @@ export default util.createRule({ /** * Determines whether a function has a name. - * @param node The function node. - * @returns Whether the function has a name. + * @param {ASTNode} node The function node. + * @returns {boolean} Whether the function has a name. */ function isNamedFunction( node: @@ -92,7 +92,8 @@ export default util.createRule({ /** * Gets the config for a given function - * @param node The function node + * @param {ASTNode} node The function node + * @returns {string} "always", "never", or "ignore" */ function getConfigForFunction( node: @@ -121,7 +122,8 @@ export default util.createRule({ /** * Checks the parens of a function node - * @param node A function node + * @param {ASTNode} node A function node + * @returns {void} */ function checkFunction( node: diff --git a/yarn.lock b/yarn.lock index 52d7ab971d75..04ba7af56f04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,9 +1564,9 @@ acorn-walk@^6.0.1: integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA== acorn@^6.0.1: - version "6.4.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.0.tgz#b659d2ffbafa24baf5db1cdbb2c94a983ecd2784" - integrity sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw== + version "6.4.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474" + integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== acorn@^7.1.0: version "7.1.0" From 82f1109893858196aebce61d6c3bb49527665607 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:30:32 +0100 Subject: [PATCH 03/31] Doc --- packages/eslint-plugin/README.md | 1 + .../docs/rules/keyword-spacing.md | 40 +++++++++++++++++++ .../src/rules/keyword-spacing.ts | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-plugin/docs/rules/keyword-spacing.md diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 7ed22981926c..3af29b3b6740 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -183,6 +183,7 @@ In these cases, we create what we call an extension rule; a rule within our plug | [`@typescript-eslint/default-param-last`](./docs/rules/default-param-last.md) | Enforce default parameters to be last | | | | | [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | | | [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation | | :wrench: | | +| [`@typescript-eslint/keyword-spacing`](./docs/rules/keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | | | [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-dupe-class-members`](./docs/rules/no-dupe-class-members.md) | Disallow duplicate class members | | | | | [`@typescript-eslint/no-empty-function`](./docs/rules/no-empty-function.md) | Disallow empty functions | :heavy_check_mark: | | | diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md new file mode 100644 index 000000000000..77267361d887 --- /dev/null +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -0,0 +1,40 @@ +# Enforce consistent spacing before and after keywords (`keyword-spacing`) + +Keywords are syntax elements of JavaScript, such as `try` and `if`. +These keywords have special meaning to the language and so often appear in a different color in code editors. +As an important part of the language, style guides often refer to the spacing that should be used around keywords. +For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean `if-else` statements must look like this: + +```js +if (foo) { + // ... +} else { + // ... +} +``` + +Of course, you could also have a style guide that disallows spaces around keywords. + +However, if you want to enforce the style of spacing between the `function` keyword and the following opening parenthesis, please refer to [space-before-function-paren](space-before-function-paren.md). + +## Rule Details + +This rule extends the base [`eslint/keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing) rule. +It supports all options and features of the base rule. +This version adds support for generic type parameters on function calls. + +## How to use + +```cjson +{ + // note you must disable the base rule as it can report incorrect errors + "keyword-spacing": "off", + "@typescript-eslint/keyword-spacing": ["error"] +} +``` + +## Options + +See [`eslint/keyword-spacing` options](https://eslint.org/docs/rules/keyword-spacing#options). + +Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/keyword-spacing.md) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 9da38a80fc17..1d1dae38ecd2 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -84,7 +84,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: 'enforce consistent spacing before and after keywords', + description: 'Enforce consistent spacing before and after keywords', category: 'Stylistic Issues', recommended: false, extendsBaseRule: true, From 47b6f2d34c93885777f149006fe00bdc0646967c Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:32:08 +0100 Subject: [PATCH 04/31] all.json --- packages/eslint-plugin/src/configs/all.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-plugin/src/configs/all.json b/packages/eslint-plugin/src/configs/all.json index c736840a3fff..ec65f143c590 100644 --- a/packages/eslint-plugin/src/configs/all.json +++ b/packages/eslint-plugin/src/configs/all.json @@ -22,6 +22,8 @@ "@typescript-eslint/func-call-spacing": "error", "indent": "off", "@typescript-eslint/indent": "error", + "keyword-spacing": "off", + "@typescript-eslint/keyword-spacing": "error", "@typescript-eslint/member-delimiter-style": "error", "@typescript-eslint/member-ordering": "error", "@typescript-eslint/method-signature-style": "error", From 668e9e98bcb754d0fecaea94d74634b15b6b1680 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:32:46 +0100 Subject: [PATCH 05/31] Docs --- packages/eslint-plugin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 3af29b3b6740..0428cff43fc5 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -183,7 +183,7 @@ In these cases, we create what we call an extension rule; a rule within our plug | [`@typescript-eslint/default-param-last`](./docs/rules/default-param-last.md) | Enforce default parameters to be last | | | | | [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | | | [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation | | :wrench: | | -| [`@typescript-eslint/keyword-spacing`](./docs/rules/keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | | +| [`@typescript-eslint/keyword-spacing`](./docs/rules/keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | | | [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-dupe-class-members`](./docs/rules/no-dupe-class-members.md) | Disallow duplicate class members | | | | | [`@typescript-eslint/no-empty-function`](./docs/rules/no-empty-function.md) | Disallow empty functions | :heavy_check_mark: | | | From 936913bca28d878715571b160ed788efb0d3cd97 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:33:39 +0100 Subject: [PATCH 06/31] Prettified --- .../docs/rules/keyword-spacing.md | 4 +- .../src/rules/keyword-spacing.ts | 5 +- .../tests/rules/keyword-spacing.test.ts | 3776 +++++++++++------ 3 files changed, 2399 insertions(+), 1386 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index 77267361d887..ff96657f67ae 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -7,9 +7,9 @@ For example, you might have a style guide that says keywords should be always su ```js if (foo) { - // ... + // ... } else { - // ... + // ... } ``` diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 1d1dae38ecd2..80a56c44cfcc 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -2,10 +2,7 @@ import keywords from 'eslint/lib/rules/utils/keywords'; import * as util from '../util'; import { TSESTree } from '@typescript-eslint/experimental-utils'; import { JSONSchema4 } from 'json-schema'; -import { - isTokenOnSameLine, - isKeywordToken, -} from '../util/astUtils'; +import { isTokenOnSameLine, isKeywordToken } from '../util/astUtils'; import { isNotOpeningParenToken } from 'eslint-utils'; export type Option = Partial<{ diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 50764a5ca0de..ff1257ae27b0 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,8 +1,12 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import rule, { MessageIds, Options, Option, RootOption } from '../../src/rules/keyword-spacing'; +import rule, { + MessageIds, + Options, + Option, + RootOption, +} from '../../src/rules/keyword-spacing'; import { RuleTester } from '../RuleTester'; - //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -10,7 +14,6 @@ import { RuleTester } from '../RuleTester'; const BOTH = { before: true, after: true }; const NEITHER = { before: false, after: false }; - /** * Creates an option object to test an 'overrides' option. * @@ -31,9 +34,9 @@ const NEITHER = { before: false, after: false }; */ function override(keyword: string, value: Option): RootOption { return { - before: value.before === false, - after: value.after === false, - overrides: { [keyword]: value }, + before: value.before === false, + after: value.after === false, + overrides: { [keyword]: value }, }; } @@ -47,222 +50,480 @@ function expectedBefore(keyword: string): TSESLint.TestCaseError[] { } /** -* Gets an error message that expected space(s) after a specified keyword. -* @param keyword A keyword. -* @returns An error message. -*/ + * Gets an error message that expected space(s) after a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ function expectedAfter(keyword: string): TSESLint.TestCaseError[] { return [{ messageId: 'expectedAfter', data: { value: keyword } }]; } /** -* Gets error messages that expected space(s) before and after a specified -* keyword. -* @param keyword A keyword. -* @returns Error messages. -*/ -function expectedBeforeAndAfter(keyword: string): TSESLint.TestCaseError[] { + * Gets error messages that expected space(s) before and after a specified + * keyword. + * @param keyword A keyword. + * @returns Error messages. + */ +function expectedBeforeAndAfter( + keyword: string, +): TSESLint.TestCaseError[] { return [ - { messageId: 'expectedBefore', data: { value: keyword } }, - { messageId: 'expectedAfter', data: { value: keyword } } + { messageId: 'expectedBefore', data: { value: keyword } }, + { messageId: 'expectedAfter', data: { value: keyword } }, ]; } /** -* Gets an error message that unexpected space(s) before a specified keyword. -* @param keyword A keyword. -* @returns An error message. -*/ -function unexpectedBefore(keyword: string): TSESLint.TestCaseError[] { + * Gets an error message that unexpected space(s) before a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ +function unexpectedBefore( + keyword: string, +): TSESLint.TestCaseError[] { return [{ messageId: 'unexpectedBefore', data: { value: keyword } }]; } /** -* Gets an error message that unexpected space(s) after a specified keyword. -* @param keyword A keyword. -* @returns An error message. -*/ -function unexpectedAfter(keyword: string): TSESLint.TestCaseError[] { + * Gets an error message that unexpected space(s) after a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ +function unexpectedAfter( + keyword: string, +): TSESLint.TestCaseError[] { return [{ messageId: 'unexpectedAfter', data: { value: keyword } }]; } /** -* Gets error messages that unexpected space(s) before and after a specified -* keyword. -* @param keyword A keyword. -* @returns Error messages. -*/ -function unexpectedBeforeAndAfter(keyword: string): TSESLint.TestCaseError[] { + * Gets error messages that unexpected space(s) before and after a specified + * keyword. + * @param keyword A keyword. + * @returns Error messages. + */ +function unexpectedBeforeAndAfter( + keyword: string, +): TSESLint.TestCaseError[] { return [ - { messageId: 'unexpectedBefore', data: { value: keyword } }, - { messageId: 'unexpectedAfter', data: { value: keyword } } + { messageId: 'unexpectedBefore', data: { value: keyword } }, + { messageId: 'unexpectedAfter', data: { value: keyword } }, ]; } - const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); ruleTester.run('keyword-spacing', rule, { valid: [ - //---------------------------------------------------------------------- // as (import) //---------------------------------------------------------------------- - { code: 'import * as a from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import*as a from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import* as a from"foo"', options: [override('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import *as a from "foo"', options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - + { + code: 'import * as a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import* as a from"foo"', + options: [override('as', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import *as a from "foo"', + options: [override('as', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, //---------------------------------------------------------------------- // as (typing) //---------------------------------------------------------------------- - { code: 'const foo = {} as {}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'const foo = {}as{}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'const foo = {} as {}', options: [override('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'const foo = {}as{}', options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: 'const foo = {} as {}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'const foo = {}as{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'const foo = {} as {}', + options: [override('as', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'const foo = {}as{}', + options: [override('as', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, //---------------------------------------------------------------------- // async //---------------------------------------------------------------------- { code: '{} async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { code: '{}async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: '{} async function foo() {}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: '{}async function foo() {}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { + code: '{}async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '{} async function foo() {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '{}async function foo() {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + }, { code: '{} async () => {}', parserOptions: { ecmaVersion: 8 } }, - { code: '{}async () => {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: '{} async () => {}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: '{}async () => {}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { + code: '{}async () => {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '{} async () => {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '{}async () => {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + }, { code: '({async [b]() {}})', parserOptions: { ecmaVersion: 8 } }, - { code: '({async[b]() {}})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: '({async [b]() {}})', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: '({async[b]() {}})', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, - { code: 'class A {a(){} async [b]() {}}', parserOptions: { ecmaVersion: 8 } }, - { code: 'class A {a(){}async[b]() {}}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: 'class A {a(){} async [b]() {}}', options: [override('async', BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: 'class A {a(){}async[b]() {}}', options: [override('async', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { + code: '({async[b]() {}})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '({async [b]() {}})', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '({async[b]() {}})', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'class A {a(){} async [b]() {}}', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'class A {a(){}async[b]() {}}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'class A {a(){} async [b]() {}}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'class A {a(){}async[b]() {}}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `array-bracket-spacing` { code: '[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, - { code: '[ async function foo() {}]', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '[ async function foo() {}]', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `arrow-spacing` { code: '() =>async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { code: '() => async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '() => async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `block-spacing` { code: '{async function foo() {} }', parserOptions: { ecmaVersion: 8 } }, - { code: '{ async function foo() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '{ async function foo() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `comma-spacing` { code: '(0,async function foo() {})', parserOptions: { ecmaVersion: 8 } }, - { code: '(0, async function foo() {})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '(0, async function foo() {})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `computed-property-spacing` { code: 'a[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, - { code: '({[async function foo() {}]: 0})', parserOptions: { ecmaVersion: 8 } }, - { code: 'a[ async function foo() {}]', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: '({[ async function foo() {}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '({[async function foo() {}]: 0})', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'a[ async function foo() {}]', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '({[ async function foo() {}]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `generator-star-spacing` { code: '({ async* foo() {} })', parserOptions: { ecmaVersion: 2018 } }, - { code: '({ async *foo() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 2018 } }, + { + code: '({ async *foo() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 2018 }, + }, // not conflict with `key-spacing` - { code: '({a:async function foo() {} })', parserOptions: { ecmaVersion: 8 } }, - { code: '({a: async function foo() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '({a:async function foo() {} })', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: '({a: async function foo() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `semi-spacing` { code: ';async function foo() {};', parserOptions: { ecmaVersion: 8 } }, - { code: '; async function foo() {} ;', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '; async function foo() {} ;', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-before-function-paren` { code: 'async() => {}', parserOptions: { ecmaVersion: 8 } }, - { code: 'async () => {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async () => {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-in-parens` { code: '(async function foo() {})', parserOptions: { ecmaVersion: 8 } }, - { code: '( async function foo() {})', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '( async function foo() {})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-infix-ops` { code: 'a =async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { code: 'a = async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'a = async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-unary-ops` { code: '!async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { code: '! async function foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '! async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `template-curly-spacing` { code: '`${async function foo() {}}`', parserOptions: { ecmaVersion: 8 } }, - { code: '`${ async function foo() {}}`', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: '`${ async function foo() {}}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // await //---------------------------------------------------------------------- - { code: 'async function wrap() { {} await +1 }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { {}await +1 }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { {} await +1 }', options: [override('await', BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { {}await +1 }', options: [override('await', NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { {} await +1 }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { {}await +1 }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { {} await +1 }', + options: [override('await', BOTH)], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { {}await +1 }', + options: [override('await', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `array-bracket-spacing` - { code: 'async function wrap() { [await a] }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { [ await a] }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { [await a] }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { [ await a] }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `arrow-spacing` { code: 'async () =>await a', parserOptions: { ecmaVersion: 8 } }, - { code: 'async () => await a', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async () => await a', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `block-spacing` - { code: 'async function wrap() { {await a } }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { { await a } }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { {await a } }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { { await a } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `comma-spacing` - { code: 'async function wrap() { (0,await a) }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { (0, await a) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { (0,await a) }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { (0, await a) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `computed-property-spacing` - { code: 'async function wrap() { a[await a] }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ({[await a]: 0}) }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { a[ await a] }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ({[ await a]: 0}) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { a[await a] }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { ({[await a]: 0}) }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { a[ await a] }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { ({[ await a]: 0}) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `key-spacing` - { code: 'async function wrap() { ({a:await a }) }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ({a: await a }) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { ({a:await a }) }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { ({a: await a }) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `semi-spacing` - { code: 'async function wrap() { ;await a; }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ; await a ; }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { ;await a; }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { ; await a ; }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-in-parens` - { code: 'async function wrap() { (await a) }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ( await a) }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { (await a) }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { ( await a) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-infix-ops` - { code: 'async function wrap() { a =await a }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { a = await a }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { a =await a }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { a = await a }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `space-unary-ops` - { code: 'async function wrap() { !await\'a\' }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { ! await \'a\' }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: "async function wrap() { !await'a' }", + parserOptions: { ecmaVersion: 8 }, + }, + { + code: "async function wrap() { ! await 'a' }", + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `template-curly-spacing` - { code: 'async function wrap() { `${await a}` }', parserOptions: { ecmaVersion: 8 } }, - { code: 'async function wrap() { `${ await a}` }', options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { + code: 'async function wrap() { `${await a}` }', + parserOptions: { ecmaVersion: 8 }, + }, + { + code: 'async function wrap() { `${ await a}` }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + }, // not conflict with `jsx-curly-spacing` - { code: 'async function wrap() { }', parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, - { code: 'async function wrap() { }', options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { + code: 'async function wrap() { }', + parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, + }, + { + code: 'async function wrap() { }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // break @@ -271,7 +532,10 @@ ruleTester.run('keyword-spacing', rule, { 'A: for (;;) { {} break A; }', { code: 'A: for(;;) { {}break A; }', options: [NEITHER] }, { code: 'A: for(;;) { {} break A; }', options: [override('break', BOTH)] }, - { code: 'A: for (;;) { {}break A; }', options: [override('break', NEITHER)] }, + { + code: 'A: for (;;) { {}break A; }', + options: [override('break', NEITHER)], + }, // not conflict with `block-spacing` 'for (;;) {break}', @@ -289,8 +553,14 @@ ruleTester.run('keyword-spacing', rule, { 'switch (a) { case 0: {} case (1): }', { code: 'switch(a) { case 0: {}case+1: }', options: [NEITHER] }, { code: 'switch(a) { case 0: {}case(1): }', options: [NEITHER] }, - { code: 'switch(a) { case 0: {} case +1: }', options: [override('case', BOTH)] }, - { code: 'switch (a) { case 0: {}case+1: }', options: [override('case', NEITHER)] }, + { + code: 'switch(a) { case 0: {} case +1: }', + options: [override('case', BOTH)], + }, + { + code: 'switch (a) { case 0: {}case+1: }', + options: [override('case', NEITHER)], + }, // not conflict with `block-spacing` 'switch (a) {case 0: }', @@ -317,59 +587,130 @@ ruleTester.run('keyword-spacing', rule, { { code: '{} class Bar {}', parserOptions: { ecmaVersion: 6 } }, { code: '(class {})', parserOptions: { ecmaVersion: 6 } }, - { code: '{}class Bar {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '(class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '{} class Bar {}', options: [override('class', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '{}class Bar {}', options: [override('class', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}class Bar {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '(class{})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{} class Bar {}', + options: [override('class', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}class Bar {}', + options: [override('class', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `array-bracket-spacing` { code: '[class {}]', parserOptions: { ecmaVersion: 6 } }, - { code: '[ class{}]', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '[ class{}]', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `arrow-spacing` { code: '() =>class {}', parserOptions: { ecmaVersion: 6 } }, - { code: '() => class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '() => class{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` { code: '{class Bar {} }', parserOptions: { ecmaVersion: 6 } }, - { code: '{ class Bar {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '{ class Bar {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `comma-spacing` { code: '(0,class {})', parserOptions: { ecmaVersion: 6 } }, - { code: '(0, class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(0, class{})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `computed-property-spacing` { code: 'a[class {}]', parserOptions: { ecmaVersion: 6 } }, { code: '({[class {}]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ class{}]', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '({[ class{}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'a[ class{}]', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({[ class{}]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` { code: '({a:class {} })', parserOptions: { ecmaVersion: 6 } }, - { code: '({a: class{} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({a: class{} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` { code: ';class Bar {};', parserOptions: { ecmaVersion: 6 } }, - { code: '; class Bar {} ;', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '; class Bar {} ;', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-in-parens` - { code: '( class{})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '( class{})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-infix-ops` { code: 'a =class {}', parserOptions: { ecmaVersion: 6 } }, - { code: 'a = class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'a = class{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-unary-ops` { code: '!class {}', parserOptions: { ecmaVersion: 6 } }, - { code: '! class{}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '! class{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `template-curly-spacing` { code: '`${class {}}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ class{}}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ class{}}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // const @@ -377,20 +718,52 @@ ruleTester.run('keyword-spacing', rule, { { code: '{} const [a] = b', parserOptions: { ecmaVersion: 6 } }, { code: '{} const {a} = b', parserOptions: { ecmaVersion: 6 } }, - { code: '{}const[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '{}const{a} = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '{} const [a] = b', options: [override('const', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '{} const {a} = b', options: [override('const', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '{}const[a] = b', options: [override('const', NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: '{}const{a} = b', options: [override('const', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}const[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}const{a} = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{} const [a] = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{} const {a} = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}const[a] = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}const{a} = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` { code: '{const a = b}', parserOptions: { ecmaVersion: 6 } }, - { code: '{ const a = b}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '{ const a = b}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` { code: ';const a = b;', parserOptions: { ecmaVersion: 6 } }, - { code: '; const a = b ;', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '; const a = b ;', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // continue @@ -398,8 +771,14 @@ ruleTester.run('keyword-spacing', rule, { 'A: for (;;) { {} continue A; }', { code: 'A: for(;;) { {}continue A; }', options: [NEITHER] }, - { code: 'A: for(;;) { {} continue A; }', options: [override('continue', BOTH)] }, - { code: 'A: for (;;) { {}continue A; }', options: [override('continue', NEITHER)] }, + { + code: 'A: for(;;) { {} continue A; }', + options: [override('continue', BOTH)], + }, + { + code: 'A: for (;;) { {}continue A; }', + options: [override('continue', NEITHER)], + }, // not conflict with `block-spacing` 'for (;;) {continue}', @@ -432,8 +811,14 @@ ruleTester.run('keyword-spacing', rule, { 'switch (a) { case 0: {} default: }', { code: 'switch(a) { case 0: {}default: }', options: [NEITHER] }, - { code: 'switch(a) { case 0: {} default: }', options: [override('default', BOTH)] }, - { code: 'switch (a) { case 0: {}default: }', options: [override('default', NEITHER)] }, + { + code: 'switch(a) { case 0: {} default: }', + options: [override('default', BOTH)], + }, + { + code: 'switch (a) { case 0: {}default: }', + options: [override('default', NEITHER)], + }, // not conflict with `block-spacing` 'switch (a) {default:}', @@ -458,7 +843,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>delete foo.a)', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => delete foo.a)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => delete foo.a)', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{delete foo.a }', @@ -472,7 +861,11 @@ ruleTester.run('keyword-spacing', rule, { 'a[delete foo.a]', { code: '({[delete foo.a]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ delete foo.a]', options: [NEITHER] }, - { code: '({[ delete foo.a]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ delete foo.a]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:delete foo.a })', @@ -496,11 +889,22 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${delete foo.a}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ delete foo.a}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ delete foo.a}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // do @@ -541,8 +945,26 @@ ruleTester.run('keyword-spacing', rule, { { code: 'if (a) {}else{}', options: [override('else', NEITHER)] }, 'if (a) {}\nelse\n{}', { code: 'if(a) {}\nelse\n{}', options: [NEITHER] }, - { code: 'if(a){ }else{ }', options: [{ before: false, after: true, overrides: { else: { after: false }, if: { after: false } } }] }, - { code: 'if(a){ }else{ }', options: [{ before: true, after: false, overrides: { else: { before: false }, if: { before: false } } }] }, + { + code: 'if(a){ }else{ }', + options: [ + { + before: false, + after: true, + overrides: { else: { after: false }, if: { after: false } }, + }, + ], + }, + { + code: 'if(a){ }else{ }', + options: [ + { + before: true, + after: false, + overrides: { else: { before: false }, if: { before: false } }, + }, + ], + }, // not conflict with `semi-spacing` 'if (a);else;', @@ -552,25 +974,65 @@ ruleTester.run('keyword-spacing', rule, { // export //---------------------------------------------------------------------- - { code: 'var a = 0; {} export {a}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} export default a', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} export * from "a"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'var a = 0; {}export{a}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'var a = 0; {} export {a}', options: [override('export', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'var a = 0; {}export{a}', options: [override('export', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: 'var a = 0; {} export {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} export default a', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} export * from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'var a = 0; {}export{a}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'var a = 0; {} export {a}', + options: [override('export', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'var a = 0; {}export{a}', + options: [override('export', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, // not conflict with `semi-spacing` - { code: 'var a = 0;\n;export {a}', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'var a = 0;\n; export{a}', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: 'var a = 0;\n;export {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'var a = 0;\n; export{a}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, //---------------------------------------------------------------------- // extends //---------------------------------------------------------------------- { code: 'class Bar extends [] {}', parserOptions: { ecmaVersion: 6 } }, - { code: 'class Bar extends[] {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class Bar extends [] {}', options: [override('extends', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class Bar extends[] {}', options: [override('extends', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class Bar extends[] {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class Bar extends [] {}', + options: [override('extends', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class Bar extends[] {}', + options: [override('extends', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // finally @@ -592,13 +1054,25 @@ ruleTester.run('keyword-spacing', rule, { { code: '{} for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, { code: '{}for(;;) {}', options: [NEITHER] }, { code: '{}for(var foo in obj) {}', options: [NEITHER] }, - { code: '{}for(var foo of list) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}for(var foo of list) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, { code: '{} for (;;) {}', options: [override('for', BOTH)] }, { code: '{} for (var foo in obj) {}', options: [override('for', BOTH)] }, - { code: '{} for (var foo of list) {}', options: [override('for', BOTH)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{} for (var foo of list) {}', + options: [override('for', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, { code: '{}for(;;) {}', options: [override('for', NEITHER)] }, { code: '{}for(var foo in obj) {}', options: [override('for', NEITHER)] }, - { code: '{}for(var foo of list) {}', options: [override('for', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}for(var foo of list) {}', + options: [override('for', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{for (;;) {} }', @@ -606,7 +1080,11 @@ ruleTester.run('keyword-spacing', rule, { { code: '{for (var foo of list) {} }', parserOptions: { ecmaVersion: 6 } }, { code: '{ for(;;) {} }', options: [NEITHER] }, { code: '{ for(var foo in obj) {} }', options: [NEITHER] }, - { code: '{ for(var foo of list) {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '{ for(var foo of list) {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` ';for (;;) {}', @@ -614,24 +1092,73 @@ ruleTester.run('keyword-spacing', rule, { { code: ';for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, { code: '; for(;;) {}', options: [NEITHER] }, { code: '; for(var foo in obj) {}', options: [NEITHER] }, - { code: '; for(var foo of list) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '; for(var foo of list) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // from //---------------------------------------------------------------------- - { code: 'import {foo} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export {foo} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export * from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import{foo}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export{foo}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export*from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import{foo} from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export{foo} from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export* from "foo"', options: [override('from', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'import {foo}from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export {foo}from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: 'export *from"foo"', options: [override('from', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: 'import {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export * from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export*from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export* from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'import {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'export *from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, //---------------------------------------------------------------------- // function @@ -648,7 +1175,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>function() {})', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => function() {})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => function() {})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{function foo() {} }', @@ -662,11 +1193,19 @@ ruleTester.run('keyword-spacing', rule, { 'a[function() {}]', { code: '({[function() {}]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ function() {}]', options: [NEITHER] }, - { code: '({[ function(){}]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ function(){}]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `generator-star-spacing` { code: 'function* foo() {}', parserOptions: { ecmaVersion: 6 } }, - { code: 'function *foo() {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function *foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:function() {} })', @@ -693,30 +1232,79 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${function() {}}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ function() {}}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ function() {}}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // get //---------------------------------------------------------------------- { code: '({ get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} get [b]() {} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} static get [b]() {} }', parserOptions: { ecmaVersion: 6 } }, - { code: '({ get[b]() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}get[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}static get[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '({ get [b]() {} })', options: [override('get', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} get [b]() {} }', options: [override('get', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '({ get[b]() {} })', options: [override('get', NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}get[b]() {} }', options: [override('get', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A { a() {} get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {} static get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ get[b]() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}static get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ get [b]() {} })', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {} get [b]() {} }', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ get[b]() {} })', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}get[b]() {} }', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `comma-spacing` { code: '({ a,get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, - { code: '({ a, get[b]() {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({ a, get[b]() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // if @@ -743,28 +1331,80 @@ ruleTester.run('keyword-spacing', rule, { // import //---------------------------------------------------------------------- - { code: '{} import {a} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} import a from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} import * as a from "a"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{}import{a}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{}import*as a from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} import {a}from"foo"', options: [override('import', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{} import *as a from"foo"', options: [override('import', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{}import{a} from "foo"', options: [override('import', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '{}import* as a from "foo"', options: [override('import', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: '{} import {a} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} import a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} import * as a from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{}import{a}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{}import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} import {a}from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{} import *as a from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{}import{a} from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '{}import* as a from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, // not conflict with `semi-spacing` - { code: ';import {a} from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, - { code: '; import{a}from"foo"', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' } }, + { + code: ';import {a} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: '; import{a}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, //---------------------------------------------------------------------- // in //---------------------------------------------------------------------- { code: 'for ([foo] in {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, - { code: 'for([foo]in{foo: 0}) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'for([foo] in {foo: 0}) {}', options: [override('in', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'for ([foo]in{foo: 0}) {}', options: [override('in', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'for([foo]in{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'for([foo] in {foo: 0}) {}', + options: [override('in', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'for ([foo]in{foo: 0}) {}', + options: [override('in', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, { code: 'for ([foo] in ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, // not conflict with `space-infix-ops` @@ -784,17 +1424,37 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { code: '{} let [a] = b', parserOptions: { ecmaVersion: 6 } }, - { code: '{}let[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '{} let [a] = b', options: [override('let', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '{}let[a] = b', options: [override('let', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}let[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{} let [a] = b', + options: [override('let', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}let[a] = b', + options: [override('let', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` { code: '{let [a] = b }', parserOptions: { ecmaVersion: 6 } }, - { code: '{ let[a] = b }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '{ let[a] = b }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` { code: ';let [a] = b', parserOptions: { ecmaVersion: 6 } }, - { code: '; let[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '; let[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // new @@ -811,7 +1471,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>new foo())', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => new foo())', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => new foo())', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{new foo() }', @@ -825,7 +1489,11 @@ ruleTester.run('keyword-spacing', rule, { 'a[new foo()]', { code: '({[new foo()]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ new foo()]', options: [NEITHER] }, - { code: '({[ new foo()]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ new foo()]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:new foo() })', @@ -849,20 +1517,43 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${new foo()}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ new foo()}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ new foo()}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // of //---------------------------------------------------------------------- { code: 'for ([foo] of {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, - { code: 'for([foo]of{foo: 0}) {}', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'for([foo] of {foo: 0}) {}', options: [override('of', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'for ([foo]of{foo: 0}) {}', options: [override('of', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'for([foo]of{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'for([foo] of {foo: 0}) {}', + options: [override('of', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'for ([foo]of{foo: 0}) {}', + options: [override('of', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, { code: 'for ([foo] of ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -871,8 +1562,14 @@ ruleTester.run('keyword-spacing', rule, { 'function foo() { {} return +a }', { code: 'function foo() { {}return+a }', options: [NEITHER] }, - { code: 'function foo() { {} return +a }', options: [override('return', BOTH)] }, - { code: 'function foo() { {}return+a }', options: [override('return', NEITHER)] }, + { + code: 'function foo() { {} return +a }', + options: [override('return', BOTH)], + }, + { + code: 'function foo() { {}return+a }', + options: [override('return', NEITHER)], + }, 'function foo() {\nreturn\n}', { code: 'function foo() {\nreturn\n}', options: [NEITHER] }, @@ -889,96 +1586,260 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { code: '({ set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} set [b](value) {} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} static set [b](value) {} }', parserOptions: { ecmaVersion: 6 } }, - { code: '({ set[b](value) {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}set[b](value) {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '({ set [b](value) {} })', options: [override('set', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} set [b](value) {} }', options: [override('set', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '({ set[b](value) {} })', options: [override('set', NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}set[b](value) {} }', options: [override('set', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A { a() {} set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {} static set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ set[b](value) {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}set[b](value) {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ set [b](value) {} })', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {} set [b](value) {} }', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '({ set[b](value) {} })', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}set[b](value) {} }', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `comma-spacing` { code: '({ a,set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, - { code: '({ a, set[b](value) {} })', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({ a, set[b](value) {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // static //---------------------------------------------------------------------- - { code: 'class A { a() {} static [b]() {} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}static[b]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {} static [b]() {} }', options: [override('static', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { a() {}static[b]() {} }', options: [override('static', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A { a() {} static [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}static[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {} static [b]() {} }', + options: [override('static', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A { a() {}static[b]() {} }', + options: [override('static', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `generator-star-spacing` { code: 'class A { static* [a]() {} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { static *[a]() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A { static *[a]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` { code: 'class A { ;static a() {} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A { ; static a() {} }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A { ; static a() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, //---------------------------------------------------------------------- // super //---------------------------------------------------------------------- - { code: 'class A extends B { a() { {} super[b](); } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { a() { {}super[b](); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { a() { {} super[b](); } }', options: [override('super', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { a() { {}super[b](); } }', options: [override('super', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { a() { {} super[b](); } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { a() { {}super[b](); } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { a() { {} super[b](); } }', + options: [override('super', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { a() { {}super[b](); } }', + options: [override('super', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `array-bracket-spacing` - { code: 'class A extends B { constructor() { [super()]; } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { [ super() ]; } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { [super()]; } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { [ super() ]; } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `arrow-spacing` - { code: 'class A extends B { constructor() { () =>super(); } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { () => super(); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { () =>super(); } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { () => super(); } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` - { code: 'class A extends B { constructor() {super()} }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() {super()} }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { super() } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `comma-spacing` - { code: 'class A extends B { constructor() { (0,super()) } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { (0, super()) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { (0,super()) } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { (0, super()) } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `computed-property-spacing` - { code: 'class A extends B { constructor() { ({[super()]: 0}) } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { ({[ super() ]: 0}) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { ({[super()]: 0}) } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { ({[ super() ]: 0}) } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` - { code: 'class A extends B { constructor() { ({a:super() }) } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { ({a: super() }) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { ({a:super() }) } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { ({a: super() }) } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `func-call-spacing` - { code: 'class A extends B { constructor() { super(); } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { super (); } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { super(); } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { super (); } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` - { code: 'class A extends B { constructor() { ;super(); } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { ; super() ; } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { ;super(); } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { ; super() ; } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-in-parens` - { code: 'class A extends B { constructor() { (super()) } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { ( super() ) } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { (super()) } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { ( super() ) } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-infix-ops` - { code: 'class A extends B { constructor() { b =super() } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { b = super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { b =super() } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { b = super() } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-unary-ops` - { code: 'class A extends B { constructor() { !super() } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { ! super() } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { !super() } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { ! super() } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `template-curly-spacing` - { code: 'class A extends B { constructor() { `${super()}` } }', parserOptions: { ecmaVersion: 6 } }, - { code: 'class A extends B { constructor() { `${ super() }` } }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'class A extends B { constructor() { `${super()}` } }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'class A extends B { constructor() { `${ super() }` } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: 'class A extends B { constructor() { } }', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: 'class A extends B { constructor() { } }', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { + code: 'class A extends B { constructor() { } }', + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, + { + code: + 'class A extends B { constructor() { } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // switch @@ -1012,7 +1873,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>this)', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => this)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => this)', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{this}', @@ -1026,7 +1891,11 @@ ruleTester.run('keyword-spacing', rule, { 'a[this]', { code: '({[this]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ this ]', options: [NEITHER] }, - { code: '({[ this ]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ this ]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:this })', @@ -1050,11 +1919,22 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${this}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ this }`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ this }`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // throw @@ -1062,8 +1942,14 @@ ruleTester.run('keyword-spacing', rule, { 'function foo() { {} throw +a }', { code: 'function foo() { {}throw+a }', options: [NEITHER] }, - { code: 'function foo() { {} throw +a }', options: [override('throw', BOTH)] }, - { code: 'function foo() { {}throw+a }', options: [override('throw', NEITHER)] }, + { + code: 'function foo() { {} throw +a }', + options: [override('throw', BOTH)], + }, + { + code: 'function foo() { {}throw+a }', + options: [override('throw', NEITHER)], + }, 'function foo() {\nthrow a\n}', { code: 'function foo() {\nthrow a\n}', options: [NEITHER] }, @@ -1107,7 +1993,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>typeof foo)', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => typeof foo)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => typeof foo)', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{typeof foo }', @@ -1121,7 +2011,11 @@ ruleTester.run('keyword-spacing', rule, { 'a[typeof foo]', { code: '({[typeof foo]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ typeof foo]', options: [NEITHER] }, - { code: '({[ typeof foo]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ typeof foo]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:typeof foo })', @@ -1145,20 +2039,43 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${typeof foo}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ typeof foo}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ typeof foo}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // var //---------------------------------------------------------------------- { code: '{} var [a] = b', parserOptions: { ecmaVersion: 6 } }, - { code: '{}var[a] = b', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: '{} var [a] = b', options: [override('var', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: '{}var[a] = b', options: [override('var', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: '{}var[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{} var [a] = b', + options: [override('var', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: '{}var[a] = b', + options: [override('var', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, 'for (var foo in [1, 2, 3]) {}', // not conflict with `block-spacing` @@ -1184,7 +2101,11 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `arrow-spacing` { code: '(() =>void foo)', parserOptions: { ecmaVersion: 6 } }, - { code: '(() => void foo)', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '(() => void foo)', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `block-spacing` '{void foo }', @@ -1198,7 +2119,11 @@ ruleTester.run('keyword-spacing', rule, { 'a[void foo]', { code: '({[void foo]: 0})', parserOptions: { ecmaVersion: 6 } }, { code: 'a[ void foo]', options: [NEITHER] }, - { code: '({[ void foo]: 0})', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '({[ void foo]: 0})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` '({a:void foo })', @@ -1222,11 +2147,22 @@ ruleTester.run('keyword-spacing', rule, { // not conflict with `template-curly-spacing` { code: '`${void foo}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ void foo}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ void foo}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: '', parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: '', options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { + code: '', + parserOptions: { ecmaFeatures: { jsx: true } }, + }, + { + code: '', + options: [NEITHER], + parserOptions: { ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // while @@ -1274,14 +2210,33 @@ ruleTester.run('keyword-spacing', rule, { // yield //---------------------------------------------------------------------- - { code: 'function* foo() { {} yield foo }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { {}yield foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { {} yield foo }', options: [override('yield', BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { {}yield foo }', options: [override('yield', NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { {} yield foo }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { {}yield foo }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { {} yield foo }', + options: [override('yield', BOTH)], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { {}yield foo }', + options: [override('yield', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `array-bracket-spacing` { code: 'function* foo() { [yield] }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { [ yield ] }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { [ yield ] }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, /* * This is invalid syntax: https://github.com/eslint/eslint/issues/5405 @@ -1291,45 +2246,107 @@ ruleTester.run('keyword-spacing', rule, { * not conflict with `block-spacing` */ { code: 'function* foo() {yield}', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { yield }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { yield }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `comma-spacing` - { code: 'function* foo() { (0,yield foo) }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { (0, yield foo) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { (0,yield foo) }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { (0, yield foo) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `computed-property-spacing` { code: 'function* foo() { a[yield] }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { ({[yield]: 0}) }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { a[ yield ] }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { ({[ yield ]: 0}) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { ({[yield]: 0}) }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { a[ yield ] }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { ({[ yield ]: 0}) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `key-spacing` - { code: 'function* foo() { ({a:yield foo }) }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { ({a: yield foo }) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { ({a:yield foo }) }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { ({a: yield foo }) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `semi-spacing` { code: 'function* foo() { ;yield; }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { ; yield ; }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { ; yield ; }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-in-parens` { code: 'function* foo() { (yield) }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { ( yield ) }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { ( yield ) }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-infix-ops` - { code: 'function* foo() { a =yield foo }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { a = yield foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { a =yield foo }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { a = yield foo }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `space-unary-ops` - { code: 'function* foo() { yield+foo }', parserOptions: { ecmaVersion: 6 } }, - { code: 'function* foo() { yield +foo }', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: 'function* foo() { yield+foo }', + parserOptions: { ecmaVersion: 6 }, + }, + { + code: 'function* foo() { yield +foo }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `template-curly-spacing` { code: '`${yield}`', parserOptions: { ecmaVersion: 6 } }, - { code: '`${ yield}`', options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { + code: '`${ yield}`', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + }, // not conflict with `jsx-curly-spacing` - { code: 'function* foo() { }', parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: 'function* foo() { }', options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { + code: 'function* foo() { }', + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, + { + code: 'function* foo() { }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + }, //---------------------------------------------------------------------- // typescript parser @@ -1344,41 +2361,39 @@ ruleTester.run('keyword-spacing', rule, { // type keywords can be used as parameters in arrow functions 'symbol => 4;', - ] as TSESLint.ValidTestCase[], invalid: [ - //---------------------------------------------------------------------- // as (import) //---------------------------------------------------------------------- { - code: 'import *as a from "foo"', - output: 'import * as a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as') + code: 'import *as a from "foo"', + output: 'import * as a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as'), }, { - code: 'import* as a from"foo"', - output: 'import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as') + code: 'import* as a from"foo"', + output: 'import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as'), }, { - code: 'import*as a from"foo"', - output: 'import* as a from"foo"', - options: [override('as', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as') + code: 'import*as a from"foo"', + output: 'import* as a from"foo"', + options: [override('as', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as'), }, { - code: 'import * as a from "foo"', - output: 'import *as a from "foo"', - options: [override('as', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as') + code: 'import * as a from "foo"', + output: 'import *as a from "foo"', + options: [override('as', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as'), }, //---------------------------------------------------------------------- @@ -1386,17 +2401,17 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'const foo = {}as {}', - output: 'const foo = {} as {}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as') + code: 'const foo = {}as {}', + output: 'const foo = {} as {}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as'), }, { - code: 'const foo = {} as{}', - output: 'const foo = {}as{}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as') + code: 'const foo = {} as{}', + output: 'const foo = {}as{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBefore('as'), }, //---------------------------------------------------------------------- @@ -1404,112 +2419,112 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}async function foo() {}', - output: '{} async function foo() {}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async') + code: '{}async function foo() {}', + output: '{} async function foo() {}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async'), }, { - code: '{} async function foo() {}', - output: '{}async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async') + code: '{} async function foo() {}', + output: '{}async function foo() {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async'), }, { - code: '{}async function foo() {}', - output: '{} async function foo() {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async') + code: '{}async function foo() {}', + output: '{} async function foo() {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async'), }, { - code: '{} async function foo() {}', - output: '{}async function foo() {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async') + code: '{} async function foo() {}', + output: '{}async function foo() {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async'), }, { - code: '{}async () => {}', - output: '{} async () => {}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async') + code: '{}async () => {}', + output: '{} async () => {}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async'), }, { - code: '{} async () => {}', - output: '{}async () => {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async') + code: '{} async () => {}', + output: '{}async () => {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async'), }, { - code: '{}async () => {}', - output: '{} async () => {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async') + code: '{}async () => {}', + output: '{} async () => {}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('async'), }, { - code: '{} async () => {}', - output: '{}async () => {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async') + code: '{} async () => {}', + output: '{}async () => {}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('async'), }, { - code: '({async[b]() {}})', - output: '({async [b]() {}})', - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter('async') + code: '({async[b]() {}})', + output: '({async [b]() {}})', + parserOptions: { ecmaVersion: 8 }, + errors: expectedAfter('async'), }, { - code: '({async [b]() {}})', - output: '({async[b]() {}})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter('async') + code: '({async [b]() {}})', + output: '({async[b]() {}})', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter('async'), }, { - code: '({async[b]() {}})', - output: '({async [b]() {}})', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter('async') + code: '({async[b]() {}})', + output: '({async [b]() {}})', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedAfter('async'), }, { - code: '({async [b]() {}})', - output: '({async[b]() {}})', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter('async') + code: '({async [b]() {}})', + output: '({async[b]() {}})', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter('async'), }, { - code: 'class A {a(){}async[b]() {}}', - output: 'class A {a(){} async [b]() {}}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter('async') + code: 'class A {a(){}async[b]() {}}', + output: 'class A {a(){} async [b]() {}}', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter('async'), }, { - code: 'class A {a(){} async [b]() {}}', - output: 'class A {a(){}async[b]() {}}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter('async') + code: 'class A {a(){} async [b]() {}}', + output: 'class A {a(){}async[b]() {}}', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter('async'), }, { - code: 'class A {a(){}async[b]() {}}', - output: 'class A {a(){} async [b]() {}}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter('async') + code: 'class A {a(){}async[b]() {}}', + output: 'class A {a(){} async [b]() {}}', + options: [override('async', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter('async'), }, { - code: 'class A {a(){} async [b]() {}}', - output: 'class A {a(){}async[b]() {}}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter('async') + code: 'class A {a(){} async [b]() {}}', + output: 'class A {a(){}async[b]() {}}', + options: [override('async', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter('async'), }, //---------------------------------------------------------------------- @@ -1517,59 +2532,59 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'async function wrap() { {}await a }', - output: 'async function wrap() { {} await a }', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('await') + code: 'async function wrap() { {}await a }', + output: 'async function wrap() { {} await a }', + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('await'), }, { - code: 'async function wrap() { {} await a }', - output: 'async function wrap() { {}await a }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('await') + code: 'async function wrap() { {} await a }', + output: 'async function wrap() { {}await a }', + options: [NEITHER], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('await'), }, { - code: 'async function wrap() { {}await a }', - output: 'async function wrap() { {} await a }', - options: [override('await', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('await') + code: 'async function wrap() { {}await a }', + output: 'async function wrap() { {} await a }', + options: [override('await', BOTH)], + parserOptions: { ecmaVersion: 8 }, + errors: expectedBefore('await'), }, { - code: 'async function wrap() { {} await a }', - output: 'async function wrap() { {}await a }', - options: [override('await', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('await') + code: 'async function wrap() { {} await a }', + output: 'async function wrap() { {}await a }', + options: [override('await', NEITHER)], + parserOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore('await'), }, { - code: 'async function wrap() { for await(x of xs); }', - output: 'async function wrap() { for await (x of xs); }', - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter('await') + code: 'async function wrap() { for await(x of xs); }', + output: 'async function wrap() { for await (x of xs); }', + parserOptions: { ecmaVersion: 2018 }, + errors: expectedAfter('await'), }, { - code: 'async function wrap() { for await (x of xs); }', - output: 'async function wrap() { for await(x of xs); }', - options: [NEITHER], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter('await') + code: 'async function wrap() { for await (x of xs); }', + output: 'async function wrap() { for await(x of xs); }', + options: [NEITHER], + parserOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter('await'), }, { - code: 'async function wrap() { for await(x of xs); }', - output: 'async function wrap() { for await (x of xs); }', - options: [override('await', BOTH)], - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter('await') + code: 'async function wrap() { for await(x of xs); }', + output: 'async function wrap() { for await (x of xs); }', + options: [override('await', BOTH)], + parserOptions: { ecmaVersion: 2018 }, + errors: expectedAfter('await'), }, { - code: 'async function wrap() { for await (x of xs); }', - output: 'async function wrap() { for await(x of xs); }', - options: [override('await', NEITHER)], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter('await') + code: 'async function wrap() { for await (x of xs); }', + output: 'async function wrap() { for await(x of xs); }', + options: [override('await', NEITHER)], + parserOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter('await'), }, //---------------------------------------------------------------------- @@ -1577,27 +2592,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'A: for (;;) { {}break A; }', - output: 'A: for (;;) { {} break A; }', - errors: expectedBefore('break') + code: 'A: for (;;) { {}break A; }', + output: 'A: for (;;) { {} break A; }', + errors: expectedBefore('break'), }, { - code: 'A: for(;;) { {} break A; }', - output: 'A: for(;;) { {}break A; }', - options: [NEITHER], - errors: unexpectedBefore('break') + code: 'A: for(;;) { {} break A; }', + output: 'A: for(;;) { {}break A; }', + options: [NEITHER], + errors: unexpectedBefore('break'), }, { - code: 'A: for(;;) { {}break A; }', - output: 'A: for(;;) { {} break A; }', - options: [override('break', BOTH)], - errors: expectedBefore('break') + code: 'A: for(;;) { {}break A; }', + output: 'A: for(;;) { {} break A; }', + options: [override('break', BOTH)], + errors: expectedBefore('break'), }, { - code: 'A: for (;;) { {} break A; }', - output: 'A: for (;;) { {}break A; }', - options: [override('break', NEITHER)], - errors: unexpectedBefore('break') + code: 'A: for (;;) { {} break A; }', + output: 'A: for (;;) { {}break A; }', + options: [override('break', NEITHER)], + errors: unexpectedBefore('break'), }, //---------------------------------------------------------------------- @@ -1605,38 +2620,38 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'switch (a) { case 0: {}case+1: }', - output: 'switch (a) { case 0: {} case +1: }', - errors: expectedBeforeAndAfter('case') + code: 'switch (a) { case 0: {}case+1: }', + output: 'switch (a) { case 0: {} case +1: }', + errors: expectedBeforeAndAfter('case'), }, { - code: 'switch (a) { case 0: {}case(1): }', - output: 'switch (a) { case 0: {} case (1): }', - errors: expectedBeforeAndAfter('case') + code: 'switch (a) { case 0: {}case(1): }', + output: 'switch (a) { case 0: {} case (1): }', + errors: expectedBeforeAndAfter('case'), }, { - code: 'switch(a) { case 0: {} case +1: }', - output: 'switch(a) { case 0: {}case+1: }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('case') + code: 'switch(a) { case 0: {} case +1: }', + output: 'switch(a) { case 0: {}case+1: }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('case'), }, { - code: 'switch(a) { case 0: {} case (1): }', - output: 'switch(a) { case 0: {}case(1): }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('case') + code: 'switch(a) { case 0: {} case (1): }', + output: 'switch(a) { case 0: {}case(1): }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('case'), }, { - code: 'switch(a) { case 0: {}case+1: }', - output: 'switch(a) { case 0: {} case +1: }', - options: [override('case', BOTH)], - errors: expectedBeforeAndAfter('case') + code: 'switch(a) { case 0: {}case+1: }', + output: 'switch(a) { case 0: {} case +1: }', + options: [override('case', BOTH)], + errors: expectedBeforeAndAfter('case'), }, { - code: 'switch (a) { case 0: {} case +1: }', - output: 'switch (a) { case 0: {}case+1: }', - options: [override('case', NEITHER)], - errors: unexpectedBeforeAndAfter('case') + code: 'switch (a) { case 0: {} case +1: }', + output: 'switch (a) { case 0: {}case+1: }', + options: [override('case', NEITHER)], + errors: unexpectedBeforeAndAfter('case'), }, //---------------------------------------------------------------------- @@ -1644,27 +2659,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'try {}catch(e) {}', - output: 'try {} catch (e) {}', - errors: expectedBeforeAndAfter('catch') + code: 'try {}catch(e) {}', + output: 'try {} catch (e) {}', + errors: expectedBeforeAndAfter('catch'), }, { - code: 'try{} catch (e) {}', - output: 'try{}catch(e) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('catch') + code: 'try{} catch (e) {}', + output: 'try{}catch(e) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('catch'), }, { - code: 'try{}catch(e) {}', - output: 'try{} catch (e) {}', - options: [override('catch', BOTH)], - errors: expectedBeforeAndAfter('catch') + code: 'try{}catch(e) {}', + output: 'try{} catch (e) {}', + options: [override('catch', BOTH)], + errors: expectedBeforeAndAfter('catch'), }, { - code: 'try {} catch (e) {}', - output: 'try {}catch(e) {}', - options: [override('catch', NEITHER)], - errors: unexpectedBeforeAndAfter('catch') + code: 'try {} catch (e) {}', + output: 'try {}catch(e) {}', + options: [override('catch', NEITHER)], + errors: unexpectedBeforeAndAfter('catch'), }, //---------------------------------------------------------------------- @@ -1672,44 +2687,44 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}class Bar {}', - output: '{} class Bar {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('class') + code: '{}class Bar {}', + output: '{} class Bar {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('class'), }, { - code: '(class{})', - output: '(class {})', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('class') + code: '(class{})', + output: '(class {})', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('class'), }, { - code: '{} class Bar {}', - output: '{}class Bar {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('class') + code: '{} class Bar {}', + output: '{}class Bar {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('class'), }, { - code: '(class {})', - output: '(class{})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('class') + code: '(class {})', + output: '(class{})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('class'), }, { - code: '{}class Bar {}', - output: '{} class Bar {}', - options: [override('class', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('class') + code: '{}class Bar {}', + output: '{} class Bar {}', + options: [override('class', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('class'), }, { - code: '{} class Bar {}', - output: '{}class Bar {}', - options: [override('class', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('class') + code: '{} class Bar {}', + output: '{}class Bar {}', + options: [override('class', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('class'), }, //---------------------------------------------------------------------- @@ -1717,58 +2732,58 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}const[a] = b', - output: '{} const [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const') + code: '{}const[a] = b', + output: '{} const [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const'), }, { - code: '{}const{a} = b', - output: '{} const {a} = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const') + code: '{}const{a} = b', + output: '{} const {a} = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const'), }, { - code: '{} const [a] = b', - output: '{}const[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const') + code: '{} const [a] = b', + output: '{}const[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const'), }, { - code: '{} const {a} = b', - output: '{}const{a} = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const') + code: '{} const {a} = b', + output: '{}const{a} = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const'), }, { - code: '{}const[a] = b', - output: '{} const [a] = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const') + code: '{}const[a] = b', + output: '{} const [a] = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const'), }, { - code: '{}const{a} = b', - output: '{} const {a} = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const') + code: '{}const{a} = b', + output: '{} const {a} = b', + options: [override('const', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('const'), }, { - code: '{} const [a] = b', - output: '{}const[a] = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const') + code: '{} const [a] = b', + output: '{}const[a] = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const'), }, { - code: '{} const {a} = b', - output: '{}const{a} = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const') + code: '{} const {a} = b', + output: '{}const{a} = b', + options: [override('const', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('const'), }, //---------------------------------------------------------------------- @@ -1776,27 +2791,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'A: for (;;) { {}continue A; }', - output: 'A: for (;;) { {} continue A; }', - errors: expectedBefore('continue') + code: 'A: for (;;) { {}continue A; }', + output: 'A: for (;;) { {} continue A; }', + errors: expectedBefore('continue'), }, { - code: 'A: for(;;) { {} continue A; }', - output: 'A: for(;;) { {}continue A; }', - options: [NEITHER], - errors: unexpectedBefore('continue') + code: 'A: for(;;) { {} continue A; }', + output: 'A: for(;;) { {}continue A; }', + options: [NEITHER], + errors: unexpectedBefore('continue'), }, { - code: 'A: for(;;) { {}continue A; }', - output: 'A: for(;;) { {} continue A; }', - options: [override('continue', BOTH)], - errors: expectedBefore('continue') + code: 'A: for(;;) { {}continue A; }', + output: 'A: for(;;) { {} continue A; }', + options: [override('continue', BOTH)], + errors: expectedBefore('continue'), }, { - code: 'A: for (;;) { {} continue A; }', - output: 'A: for (;;) { {}continue A; }', - options: [override('continue', NEITHER)], - errors: unexpectedBefore('continue') + code: 'A: for (;;) { {} continue A; }', + output: 'A: for (;;) { {}continue A; }', + options: [override('continue', NEITHER)], + errors: unexpectedBefore('continue'), }, //---------------------------------------------------------------------- @@ -1804,27 +2819,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}debugger', - output: '{} debugger', - errors: expectedBefore('debugger') + code: '{}debugger', + output: '{} debugger', + errors: expectedBefore('debugger'), }, { - code: '{} debugger', - output: '{}debugger', - options: [NEITHER], - errors: unexpectedBefore('debugger') + code: '{} debugger', + output: '{}debugger', + options: [NEITHER], + errors: unexpectedBefore('debugger'), }, { - code: '{}debugger', - output: '{} debugger', - options: [override('debugger', BOTH)], - errors: expectedBefore('debugger') + code: '{}debugger', + output: '{} debugger', + options: [override('debugger', BOTH)], + errors: expectedBefore('debugger'), }, { - code: '{} debugger', - output: '{}debugger', - options: [override('debugger', NEITHER)], - errors: unexpectedBefore('debugger') + code: '{} debugger', + output: '{}debugger', + options: [override('debugger', NEITHER)], + errors: unexpectedBefore('debugger'), }, //---------------------------------------------------------------------- @@ -1832,27 +2847,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'switch (a) { case 0: {}default: }', - output: 'switch (a) { case 0: {} default: }', - errors: expectedBefore('default') + code: 'switch (a) { case 0: {}default: }', + output: 'switch (a) { case 0: {} default: }', + errors: expectedBefore('default'), }, { - code: 'switch(a) { case 0: {} default: }', - output: 'switch(a) { case 0: {}default: }', - options: [NEITHER], - errors: unexpectedBefore('default') + code: 'switch(a) { case 0: {} default: }', + output: 'switch(a) { case 0: {}default: }', + options: [NEITHER], + errors: unexpectedBefore('default'), }, { - code: 'switch(a) { case 0: {}default: }', - output: 'switch(a) { case 0: {} default: }', - options: [override('default', BOTH)], - errors: expectedBefore('default') + code: 'switch(a) { case 0: {}default: }', + output: 'switch(a) { case 0: {} default: }', + options: [override('default', BOTH)], + errors: expectedBefore('default'), }, { - code: 'switch (a) { case 0: {} default: }', - output: 'switch (a) { case 0: {}default: }', - options: [override('default', NEITHER)], - errors: unexpectedBefore('default') + code: 'switch (a) { case 0: {} default: }', + output: 'switch (a) { case 0: {}default: }', + options: [override('default', NEITHER)], + errors: unexpectedBefore('default'), }, //---------------------------------------------------------------------- @@ -1860,27 +2875,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}delete foo.a', - output: '{} delete foo.a', - errors: expectedBefore('delete') + code: '{}delete foo.a', + output: '{} delete foo.a', + errors: expectedBefore('delete'), }, { - code: '{} delete foo.a', - output: '{}delete foo.a', - options: [NEITHER], - errors: unexpectedBefore('delete') + code: '{} delete foo.a', + output: '{}delete foo.a', + options: [NEITHER], + errors: unexpectedBefore('delete'), }, { - code: '{}delete foo.a', - output: '{} delete foo.a', - options: [override('delete', BOTH)], - errors: expectedBefore('delete') + code: '{}delete foo.a', + output: '{} delete foo.a', + options: [override('delete', BOTH)], + errors: expectedBefore('delete'), }, { - code: '{} delete foo.a', - output: '{}delete foo.a', - options: [override('delete', NEITHER)], - errors: unexpectedBefore('delete') + code: '{} delete foo.a', + output: '{}delete foo.a', + options: [override('delete', NEITHER)], + errors: unexpectedBefore('delete'), }, //---------------------------------------------------------------------- @@ -1888,27 +2903,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}do{} while (true)', - output: '{} do {} while (true)', - errors: expectedBeforeAndAfter('do') + code: '{}do{} while (true)', + output: '{} do {} while (true)', + errors: expectedBeforeAndAfter('do'), }, { - code: '{} do {}while(true)', - output: '{}do{}while(true)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('do') + code: '{} do {}while(true)', + output: '{}do{}while(true)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('do'), }, { - code: '{}do{}while(true)', - output: '{} do {}while(true)', - options: [override('do', BOTH)], - errors: expectedBeforeAndAfter('do') + code: '{}do{}while(true)', + output: '{} do {}while(true)', + options: [override('do', BOTH)], + errors: expectedBeforeAndAfter('do'), }, { - code: '{} do {} while (true)', - output: '{}do{} while (true)', - options: [override('do', NEITHER)], - errors: unexpectedBeforeAndAfter('do') + code: '{} do {} while (true)', + output: '{}do{} while (true)', + options: [override('do', NEITHER)], + errors: unexpectedBeforeAndAfter('do'), }, //---------------------------------------------------------------------- @@ -1916,105 +2931,105 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'if (a) {}else{}', - output: 'if (a) {} else {}', - errors: expectedBeforeAndAfter('else') + code: 'if (a) {}else{}', + output: 'if (a) {} else {}', + errors: expectedBeforeAndAfter('else'), }, { - code: 'if (a) {}else if (b) {}', - output: 'if (a) {} else if (b) {}', - errors: expectedBefore('else') + code: 'if (a) {}else if (b) {}', + output: 'if (a) {} else if (b) {}', + errors: expectedBefore('else'), }, { - code: 'if (a) {}else(0)', - output: 'if (a) {} else (0)', - errors: expectedBeforeAndAfter('else') + code: 'if (a) {}else(0)', + output: 'if (a) {} else (0)', + errors: expectedBeforeAndAfter('else'), }, { - code: 'if (a) {}else[]', - output: 'if (a) {} else []', - errors: expectedBeforeAndAfter('else') + code: 'if (a) {}else[]', + output: 'if (a) {} else []', + errors: expectedBeforeAndAfter('else'), }, { - code: 'if (a) {}else+1', - output: 'if (a) {} else +1', - errors: expectedBeforeAndAfter('else') + code: 'if (a) {}else+1', + output: 'if (a) {} else +1', + errors: expectedBeforeAndAfter('else'), }, { - code: 'if (a) {}else"a"', - output: 'if (a) {} else "a"', - errors: expectedBeforeAndAfter('else') + code: 'if (a) {}else"a"', + output: 'if (a) {} else "a"', + errors: expectedBeforeAndAfter('else'), }, { - code: 'if(a){} else {}', - output: 'if(a){}else{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else') + code: 'if(a){} else {}', + output: 'if(a){}else{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if(a){} else if(b) {}', - output: 'if(a){}else if(b) {}', - options: [NEITHER], - errors: unexpectedBefore('else') + code: 'if(a){} else if(b) {}', + output: 'if(a){}else if(b) {}', + options: [NEITHER], + errors: unexpectedBefore('else'), }, { - code: 'if(a) {} else (0)', - output: 'if(a) {}else(0)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else') + code: 'if(a) {} else (0)', + output: 'if(a) {}else(0)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if(a) {} else []', - output: 'if(a) {}else[]', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else') + code: 'if(a) {} else []', + output: 'if(a) {}else[]', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if(a) {} else +1', - output: 'if(a) {}else+1', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else') + code: 'if(a) {} else +1', + output: 'if(a) {}else+1', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if(a) {} else "a"', - output: 'if(a) {}else"a"', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else') + code: 'if(a) {} else "a"', + output: 'if(a) {}else"a"', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if(a) {}else{}', - output: 'if(a) {} else {}', - options: [override('else', BOTH)], - errors: expectedBeforeAndAfter('else') + code: 'if(a) {}else{}', + output: 'if(a) {} else {}', + options: [override('else', BOTH)], + errors: expectedBeforeAndAfter('else'), }, { - code: 'if (a) {} else {}', - output: 'if (a) {}else{}', - options: [override('else', NEITHER)], - errors: unexpectedBeforeAndAfter('else') + code: 'if (a) {} else {}', + output: 'if (a) {}else{}', + options: [override('else', NEITHER)], + errors: unexpectedBeforeAndAfter('else'), }, { - code: 'if (a) {}else {}', - output: 'if (a) {} else {}', - errors: expectedBefore('else') + code: 'if (a) {}else {}', + output: 'if (a) {} else {}', + errors: expectedBefore('else'), }, { - code: 'if (a) {} else{}', - output: 'if (a) {} else {}', - errors: expectedAfter('else') + code: 'if (a) {} else{}', + output: 'if (a) {} else {}', + errors: expectedAfter('else'), }, { - code: 'if(a) {} else{}', - output: 'if(a) {}else{}', - options: [NEITHER], - errors: unexpectedBefore('else') + code: 'if(a) {} else{}', + output: 'if(a) {}else{}', + options: [NEITHER], + errors: unexpectedBefore('else'), }, { - code: 'if(a) {}else {}', - output: 'if(a) {}else{}', - options: [NEITHER], - errors: unexpectedAfter('else') + code: 'if(a) {}else {}', + output: 'if(a) {}else{}', + options: [NEITHER], + errors: unexpectedAfter('else'), }, //---------------------------------------------------------------------- @@ -2022,49 +3037,49 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'var a = 0; {}export{a}', - output: 'var a = 0; {} export {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export') + code: 'var a = 0; {}export{a}', + output: 'var a = 0; {} export {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export'), }, { - code: 'var a = 0; {}export default a', - output: 'var a = 0; {} export default a', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('export') + code: 'var a = 0; {}export default a', + output: 'var a = 0; {} export default a', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('export'), }, { - code: 'var a = 0; export default{a}', - output: 'var a = 0; export default {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedAfter('default') + code: 'var a = 0; export default{a}', + output: 'var a = 0; export default {a}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedAfter('default'), }, { - code: '{}export* from "a"', - output: '{} export * from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export') + code: '{}export* from "a"', + output: '{} export * from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export'), }, { - code: 'var a = 0; {} export {a}', - output: 'var a = 0; {}export{a}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('export') + code: 'var a = 0; {} export {a}', + output: 'var a = 0; {}export{a}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('export'), }, { - code: 'var a = 0; {}export{a}', - output: 'var a = 0; {} export {a}', - options: [override('export', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export') + code: 'var a = 0; {}export{a}', + output: 'var a = 0; {} export {a}', + options: [override('export', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('export'), }, { - code: 'var a = 0; {} export {a}', - output: 'var a = 0; {}export{a}', - options: [override('export', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('export') + code: 'var a = 0; {} export {a}', + output: 'var a = 0; {}export{a}', + options: [override('export', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('export'), }, //---------------------------------------------------------------------- @@ -2072,50 +3087,50 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'class Bar extends[] {}', - output: 'class Bar extends [] {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends') + code: 'class Bar extends[] {}', + output: 'class Bar extends [] {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends'), }, { - code: '(class extends[] {})', - output: '(class extends [] {})', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends') + code: '(class extends[] {})', + output: '(class extends [] {})', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends'), }, { - code: 'class Bar extends [] {}', - output: 'class Bar extends[] {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends') + code: 'class Bar extends [] {}', + output: 'class Bar extends[] {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends'), }, { - code: '(class extends [] {})', - output: '(class extends[] {})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends') + code: '(class extends [] {})', + output: '(class extends[] {})', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends'), }, { - code: 'class Bar extends[] {}', - output: 'class Bar extends [] {}', - options: [override('extends', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends') + code: 'class Bar extends[] {}', + output: 'class Bar extends [] {}', + options: [override('extends', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends'), }, { - code: 'class Bar extends [] {}', - output: 'class Bar extends[] {}', - options: [override('extends', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends') + code: 'class Bar extends [] {}', + output: 'class Bar extends[] {}', + options: [override('extends', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('extends'), }, { - code: 'class Bar extends`}` {}', - output: 'class Bar extends `}` {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends') + code: 'class Bar extends`}` {}', + output: 'class Bar extends `}` {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('extends'), }, //---------------------------------------------------------------------- @@ -2123,27 +3138,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'try {}finally{}', - output: 'try {} finally {}', - errors: expectedBeforeAndAfter('finally') + code: 'try {}finally{}', + output: 'try {} finally {}', + errors: expectedBeforeAndAfter('finally'), }, { - code: 'try{} finally {}', - output: 'try{}finally{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('finally') + code: 'try{} finally {}', + output: 'try{}finally{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('finally'), }, { - code: 'try{}finally{}', - output: 'try{} finally {}', - options: [override('finally', BOTH)], - errors: expectedBeforeAndAfter('finally') + code: 'try{}finally{}', + output: 'try{} finally {}', + options: [override('finally', BOTH)], + errors: expectedBeforeAndAfter('finally'), }, { - code: 'try {} finally {}', - output: 'try {}finally{}', - options: [override('finally', NEITHER)], - errors: unexpectedBeforeAndAfter('finally') + code: 'try {} finally {}', + output: 'try {}finally{}', + options: [override('finally', NEITHER)], + errors: unexpectedBeforeAndAfter('finally'), }, //---------------------------------------------------------------------- @@ -2151,77 +3166,77 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}for(;;) {}', - output: '{} for (;;) {}', - errors: expectedBeforeAndAfter('for') + code: '{}for(;;) {}', + output: '{} for (;;) {}', + errors: expectedBeforeAndAfter('for'), }, { - code: '{}for(var foo in obj) {}', - output: '{} for (var foo in obj) {}', - errors: expectedBeforeAndAfter('for') + code: '{}for(var foo in obj) {}', + output: '{} for (var foo in obj) {}', + errors: expectedBeforeAndAfter('for'), }, { - code: '{}for(var foo of list) {}', - output: '{} for (var foo of list) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('for') + code: '{}for(var foo of list) {}', + output: '{} for (var foo of list) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('for'), }, { - code: '{} for (;;) {}', - output: '{}for(;;) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('for') + code: '{} for (;;) {}', + output: '{}for(;;) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('for'), }, { - code: '{} for (var foo in obj) {}', - output: '{}for(var foo in obj) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('for') + code: '{} for (var foo in obj) {}', + output: '{}for(var foo in obj) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('for'), }, { - code: '{} for (var foo of list) {}', - output: '{}for(var foo of list) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('for') + code: '{} for (var foo of list) {}', + output: '{}for(var foo of list) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('for'), }, { - code: '{}for(;;) {}', - output: '{} for (;;) {}', - options: [override('for', BOTH)], - errors: expectedBeforeAndAfter('for') + code: '{}for(;;) {}', + output: '{} for (;;) {}', + options: [override('for', BOTH)], + errors: expectedBeforeAndAfter('for'), }, { - code: '{}for(var foo in obj) {}', - output: '{} for (var foo in obj) {}', - options: [override('for', BOTH)], - errors: expectedBeforeAndAfter('for') + code: '{}for(var foo in obj) {}', + output: '{} for (var foo in obj) {}', + options: [override('for', BOTH)], + errors: expectedBeforeAndAfter('for'), }, { - code: '{}for(var foo of list) {}', - output: '{} for (var foo of list) {}', - options: [override('for', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('for') + code: '{}for(var foo of list) {}', + output: '{} for (var foo of list) {}', + options: [override('for', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('for'), }, { - code: '{} for (;;) {}', - output: '{}for(;;) {}', - options: [override('for', NEITHER)], - errors: unexpectedBeforeAndAfter('for') + code: '{} for (;;) {}', + output: '{}for(;;) {}', + options: [override('for', NEITHER)], + errors: unexpectedBeforeAndAfter('for'), }, { - code: '{} for (var foo in obj) {}', - output: '{}for(var foo in obj) {}', - options: [override('for', NEITHER)], - errors: unexpectedBeforeAndAfter('for') + code: '{} for (var foo in obj) {}', + output: '{}for(var foo in obj) {}', + options: [override('for', NEITHER)], + errors: unexpectedBeforeAndAfter('for'), }, { - code: '{} for (var foo of list) {}', - output: '{}for(var foo of list) {}', - options: [override('for', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('for') + code: '{} for (var foo of list) {}', + output: '{}for(var foo of list) {}', + options: [override('for', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('for'), }, //---------------------------------------------------------------------- @@ -2229,85 +3244,85 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'import {foo}from"foo"', - output: 'import {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'import {foo}from"foo"', + output: 'import {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'export {foo}from"foo"', - output: 'export {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'export {foo}from"foo"', + output: 'export {foo} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'export *from"foo"', - output: 'export * from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'export *from"foo"', + output: 'export * from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'import{foo} from "foo"', - output: 'import{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'import{foo} from "foo"', + output: 'import{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, { - code: 'export{foo} from "foo"', - output: 'export{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'export{foo} from "foo"', + output: 'export{foo}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, { - code: 'export* from "foo"', - output: 'export*from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'export* from "foo"', + output: 'export*from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, { - code: 'import{foo}from"foo"', - output: 'import{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'import{foo}from"foo"', + output: 'import{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'export{foo}from"foo"', - output: 'export{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'export{foo}from"foo"', + output: 'export{foo} from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'export*from"foo"', - output: 'export* from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from') + code: 'export*from"foo"', + output: 'export* from "foo"', + options: [override('from', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('from'), }, { - code: 'import {foo} from "foo"', - output: 'import {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'import {foo} from "foo"', + output: 'import {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, { - code: 'export {foo} from "foo"', - output: 'export {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'export {foo} from "foo"', + output: 'export {foo}from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, { - code: 'export * from "foo"', - output: 'export *from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from') + code: 'export * from "foo"', + output: 'export *from"foo"', + options: [override('from', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('from'), }, //---------------------------------------------------------------------- @@ -2315,27 +3330,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}function foo() {}', - output: '{} function foo() {}', - errors: expectedBefore('function') + code: '{}function foo() {}', + output: '{} function foo() {}', + errors: expectedBefore('function'), }, { - code: '{} function foo() {}', - output: '{}function foo() {}', - options: [NEITHER], - errors: unexpectedBefore('function') + code: '{} function foo() {}', + output: '{}function foo() {}', + options: [NEITHER], + errors: unexpectedBefore('function'), }, { - code: '{}function foo() {}', - output: '{} function foo() {}', - options: [override('function', BOTH)], - errors: expectedBefore('function') + code: '{}function foo() {}', + output: '{} function foo() {}', + options: [override('function', BOTH)], + errors: expectedBefore('function'), }, { - code: '{} function foo() {}', - output: '{}function foo() {}', - options: [override('function', NEITHER)], - errors: unexpectedBefore('function') + code: '{} function foo() {}', + output: '{}function foo() {}', + options: [override('function', NEITHER)], + errors: unexpectedBefore('function'), }, //---------------------------------------------------------------------- @@ -2343,71 +3358,71 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '({ get[b]() {} })', - output: '({ get [b]() {} })', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get') + code: '({ get[b]() {} })', + output: '({ get [b]() {} })', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get'), }, { - code: 'class A { a() {}get[b]() {} }', - output: 'class A { a() {} get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('get') + code: 'class A { a() {}get[b]() {} }', + output: 'class A { a() {} get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('get'), }, { - code: 'class A { a() {} static get[b]() {} }', - output: 'class A { a() {} static get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get') + code: 'class A { a() {} static get[b]() {} }', + output: 'class A { a() {} static get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get'), }, { - code: '({ get [b]() {} })', - output: '({ get[b]() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get') + code: '({ get [b]() {} })', + output: '({ get[b]() {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get'), }, { - code: 'class A { a() {} get [b]() {} }', - output: 'class A { a() {}get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('get') + code: 'class A { a() {} get [b]() {} }', + output: 'class A { a() {}get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('get'), }, { - code: 'class A { a() {}static get [b]() {} }', - output: 'class A { a() {}static get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get') + code: 'class A { a() {}static get [b]() {} }', + output: 'class A { a() {}static get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get'), }, { - code: '({ get[b]() {} })', - output: '({ get [b]() {} })', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get') + code: '({ get[b]() {} })', + output: '({ get [b]() {} })', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('get'), }, { - code: 'class A { a() {}get[b]() {} }', - output: 'class A { a() {} get [b]() {} }', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('get') + code: 'class A { a() {}get[b]() {} }', + output: 'class A { a() {} get [b]() {} }', + options: [override('get', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('get'), }, { - code: '({ get [b]() {} })', - output: '({ get[b]() {} })', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get') + code: '({ get [b]() {} })', + output: '({ get[b]() {} })', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('get'), }, { - code: 'class A { a() {} get [b]() {} }', - output: 'class A { a() {}get[b]() {} }', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('get') + code: 'class A { a() {} get [b]() {} }', + output: 'class A { a() {}get[b]() {} }', + options: [override('get', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('get'), }, //---------------------------------------------------------------------- @@ -2415,50 +3430,50 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}if(a) {}', - output: '{} if (a) {}', - errors: expectedBeforeAndAfter('if') + code: '{}if(a) {}', + output: '{} if (a) {}', + errors: expectedBeforeAndAfter('if'), }, { - code: 'if (a) {} else if(b) {}', - output: 'if (a) {} else if (b) {}', - errors: expectedAfter('if') + code: 'if (a) {} else if(b) {}', + output: 'if (a) {} else if (b) {}', + errors: expectedAfter('if'), }, { - code: '{} if (a) {}', - output: '{}if(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('if') + code: '{} if (a) {}', + output: '{}if(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('if'), }, { - code: 'if(a) {}else if (b) {}', - output: 'if(a) {}else if(b) {}', - options: [NEITHER], - errors: unexpectedAfter('if') + code: 'if(a) {}else if (b) {}', + output: 'if(a) {}else if(b) {}', + options: [NEITHER], + errors: unexpectedAfter('if'), }, { - code: '{}if(a) {}', - output: '{} if (a) {}', - options: [override('if', BOTH)], - errors: expectedBeforeAndAfter('if') + code: '{}if(a) {}', + output: '{} if (a) {}', + options: [override('if', BOTH)], + errors: expectedBeforeAndAfter('if'), }, { - code: 'if (a) {}else if(b) {}', - output: 'if (a) {}else if (b) {}', - options: [override('if', BOTH)], - errors: expectedAfter('if') + code: 'if (a) {}else if(b) {}', + output: 'if (a) {}else if (b) {}', + options: [override('if', BOTH)], + errors: expectedAfter('if'), }, { - code: '{} if (a) {}', - output: '{}if(a) {}', - options: [override('if', NEITHER)], - errors: unexpectedBeforeAndAfter('if') + code: '{} if (a) {}', + output: '{}if(a) {}', + options: [override('if', NEITHER)], + errors: unexpectedBeforeAndAfter('if'), }, { - code: 'if(a) {} else if (b) {}', - output: 'if(a) {} else if(b) {}', - options: [override('if', NEITHER)], - errors: unexpectedAfter('if') + code: 'if(a) {} else if (b) {}', + output: 'if(a) {} else if(b) {}', + options: [override('if', NEITHER)], + errors: unexpectedAfter('if'), }, //---------------------------------------------------------------------- @@ -2466,64 +3481,64 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}import{a} from "foo"', - output: '{} import {a} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import') + code: '{}import{a} from "foo"', + output: '{} import {a} from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import'), }, { - code: '{}import a from "foo"', - output: '{} import a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('import') + code: '{}import a from "foo"', + output: '{} import a from "foo"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('import'), }, { - code: '{}import* as a from "a"', - output: '{} import * as a from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import') + code: '{}import* as a from "a"', + output: '{} import * as a from "a"', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import'), }, { - code: '{} import {a}from"foo"', - output: '{}import{a}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import') + code: '{} import {a}from"foo"', + output: '{}import{a}from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import'), }, { - code: '{} import *as a from"foo"', - output: '{}import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import') + code: '{} import *as a from"foo"', + output: '{}import*as a from"foo"', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import'), }, { - code: '{}import{a}from"foo"', - output: '{} import {a}from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import') + code: '{}import{a}from"foo"', + output: '{} import {a}from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import'), }, { - code: '{}import*as a from"foo"', - output: '{} import *as a from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import') + code: '{}import*as a from"foo"', + output: '{} import *as a from"foo"', + options: [override('import', BOTH)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBeforeAndAfter('import'), }, { - code: '{} import {a} from "foo"', - output: '{}import{a} from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import') + code: '{} import {a} from "foo"', + output: '{}import{a} from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import'), }, { - code: '{} import * as a from "foo"', - output: '{}import* as a from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import') + code: '{} import * as a from "foo"', + output: '{}import* as a from "foo"', + options: [override('import', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedBeforeAndAfter('import'), }, //---------------------------------------------------------------------- @@ -2531,31 +3546,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'for ([foo]in{foo: 0}) {}', - output: 'for ([foo] in {foo: 0}) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('in') + code: 'for ([foo]in{foo: 0}) {}', + output: 'for ([foo] in {foo: 0}) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('in'), }, { - code: 'for([foo] in {foo: 0}) {}', - output: 'for([foo]in{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('in') + code: 'for([foo] in {foo: 0}) {}', + output: 'for([foo]in{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('in'), }, { - code: 'for([foo]in{foo: 0}) {}', - output: 'for([foo] in {foo: 0}) {}', - options: [override('in', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('in') + code: 'for([foo]in{foo: 0}) {}', + output: 'for([foo] in {foo: 0}) {}', + options: [override('in', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('in'), }, { - code: 'for ([foo] in {foo: 0}) {}', - output: 'for ([foo]in{foo: 0}) {}', - options: [override('in', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('in') + code: 'for ([foo] in {foo: 0}) {}', + output: 'for ([foo]in{foo: 0}) {}', + options: [override('in', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('in'), }, //---------------------------------------------------------------------- @@ -2569,31 +3584,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}let[a] = b', - output: '{} let [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('let') + code: '{}let[a] = b', + output: '{} let [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('let'), }, { - code: '{} let [a] = b', - output: '{}let[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('let') + code: '{} let [a] = b', + output: '{}let[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('let'), }, { - code: '{}let[a] = b', - output: '{} let [a] = b', - options: [override('let', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('let') + code: '{}let[a] = b', + output: '{} let [a] = b', + options: [override('let', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('let'), }, { - code: '{} let [a] = b', - output: '{}let[a] = b', - options: [override('let', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('let') + code: '{} let [a] = b', + output: '{}let[a] = b', + options: [override('let', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('let'), }, //---------------------------------------------------------------------- @@ -2601,27 +3616,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}new foo()', - output: '{} new foo()', - errors: expectedBefore('new') + code: '{}new foo()', + output: '{} new foo()', + errors: expectedBefore('new'), }, { - code: '{} new foo()', - output: '{}new foo()', - options: [NEITHER], - errors: unexpectedBefore('new') + code: '{} new foo()', + output: '{}new foo()', + options: [NEITHER], + errors: unexpectedBefore('new'), }, { - code: '{}new foo()', - output: '{} new foo()', - options: [override('new', BOTH)], - errors: expectedBefore('new') + code: '{}new foo()', + output: '{} new foo()', + options: [override('new', BOTH)], + errors: expectedBefore('new'), }, { - code: '{} new foo()', - output: '{}new foo()', - options: [override('new', NEITHER)], - errors: unexpectedBefore('new') + code: '{} new foo()', + output: '{}new foo()', + options: [override('new', NEITHER)], + errors: unexpectedBefore('new'), }, //---------------------------------------------------------------------- @@ -2629,31 +3644,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'for ([foo]of{foo: 0}) {}', - output: 'for ([foo] of {foo: 0}) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('of') + code: 'for ([foo]of{foo: 0}) {}', + output: 'for ([foo] of {foo: 0}) {}', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('of'), }, { - code: 'for([foo] of {foo: 0}) {}', - output: 'for([foo]of{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('of') + code: 'for([foo] of {foo: 0}) {}', + output: 'for([foo]of{foo: 0}) {}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('of'), }, { - code: 'for([foo]of{foo: 0}) {}', - output: 'for([foo] of {foo: 0}) {}', - options: [override('of', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('of') + code: 'for([foo]of{foo: 0}) {}', + output: 'for([foo] of {foo: 0}) {}', + options: [override('of', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('of'), }, { - code: 'for ([foo] of {foo: 0}) {}', - output: 'for ([foo]of{foo: 0}) {}', - options: [override('of', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('of') + code: 'for ([foo] of {foo: 0}) {}', + output: 'for ([foo]of{foo: 0}) {}', + options: [override('of', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('of'), }, //---------------------------------------------------------------------- @@ -2661,27 +3676,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'function foo() { {}return+a }', - output: 'function foo() { {} return +a }', - errors: expectedBeforeAndAfter('return') + code: 'function foo() { {}return+a }', + output: 'function foo() { {} return +a }', + errors: expectedBeforeAndAfter('return'), }, { - code: 'function foo() { {} return +a }', - output: 'function foo() { {}return+a }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('return') + code: 'function foo() { {} return +a }', + output: 'function foo() { {}return+a }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('return'), }, { - code: 'function foo() { {}return+a }', - output: 'function foo() { {} return +a }', - options: [override('return', BOTH)], - errors: expectedBeforeAndAfter('return') + code: 'function foo() { {}return+a }', + output: 'function foo() { {} return +a }', + options: [override('return', BOTH)], + errors: expectedBeforeAndAfter('return'), }, { - code: 'function foo() { {} return +a }', - output: 'function foo() { {}return+a }', - options: [override('return', NEITHER)], - errors: unexpectedBeforeAndAfter('return') + code: 'function foo() { {} return +a }', + output: 'function foo() { {}return+a }', + options: [override('return', NEITHER)], + errors: unexpectedBeforeAndAfter('return'), }, //---------------------------------------------------------------------- @@ -2689,64 +3704,64 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '({ set[b](value) {} })', - output: '({ set [b](value) {} })', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set') + code: '({ set[b](value) {} })', + output: '({ set [b](value) {} })', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set'), }, { - code: 'class A { a() {}set[b](value) {} }', - output: 'class A { a() {} set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('set') + code: 'class A { a() {}set[b](value) {} }', + output: 'class A { a() {} set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('set'), }, { - code: 'class A { a() {} static set[b](value) {} }', - output: 'class A { a() {} static set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set') + code: 'class A { a() {} static set[b](value) {} }', + output: 'class A { a() {} static set [b](value) {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set'), }, { - code: '({ set [b](value) {} })', - output: '({ set[b](value) {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('set') + code: '({ set [b](value) {} })', + output: '({ set[b](value) {} })', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('set'), }, { - code: 'class A { a() {} set [b](value) {} }', - output: 'class A { a() {}set[b](value) {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('set') + code: 'class A { a() {} set [b](value) {} }', + output: 'class A { a() {}set[b](value) {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('set'), }, { - code: '({ set[b](value) {} })', - output: '({ set [b](value) {} })', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set') + code: '({ set[b](value) {} })', + output: '({ set [b](value) {} })', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedAfter('set'), }, { - code: 'class A { a() {}set[b](value) {} }', - output: 'class A { a() {} set [b](value) {} }', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('set') + code: 'class A { a() {}set[b](value) {} }', + output: 'class A { a() {} set [b](value) {} }', + options: [override('set', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('set'), }, { - code: '({ set [b](value) {} })', - output: '({ set[b](value) {} })', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('set') + code: '({ set [b](value) {} })', + output: '({ set[b](value) {} })', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter('set'), }, { - code: 'class A { a() {} set [b](value) {} }', - output: 'class A { a() {}set[b](value) {} }', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('set') + code: 'class A { a() {} set [b](value) {} }', + output: 'class A { a() {}set[b](value) {} }', + options: [override('set', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('set'), }, //---------------------------------------------------------------------- @@ -2754,44 +3769,44 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'class A { a() {}static[b]() {} }', - output: 'class A { a() {} static [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('static') + code: 'class A { a() {}static[b]() {} }', + output: 'class A { a() {} static [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('static'), }, { - code: 'class A { a() {}static get [b]() {} }', - output: 'class A { a() {} static get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('static') + code: 'class A { a() {}static get [b]() {} }', + output: 'class A { a() {} static get [b]() {} }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('static'), }, { - code: 'class A { a() {} static [b]() {} }', - output: 'class A { a() {}static[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('static') + code: 'class A { a() {} static [b]() {} }', + output: 'class A { a() {}static[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('static'), }, { - code: 'class A { a() {} static get[b]() {} }', - output: 'class A { a() {}static get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('static') + code: 'class A { a() {} static get[b]() {} }', + output: 'class A { a() {}static get[b]() {} }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('static'), }, { - code: 'class A { a() {}static[b]() {} }', - output: 'class A { a() {} static [b]() {} }', - options: [override('static', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('static') + code: 'class A { a() {}static[b]() {} }', + output: 'class A { a() {} static [b]() {} }', + options: [override('static', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('static'), }, { - code: 'class A { a() {} static [b]() {} }', - output: 'class A { a() {}static[b]() {} }', - options: [override('static', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('static') + code: 'class A { a() {} static [b]() {} }', + output: 'class A { a() {}static[b]() {} }', + options: [override('static', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('static'), }, //---------------------------------------------------------------------- @@ -2799,31 +3814,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'class A { a() { {}super[b]; } }', - output: 'class A { a() { {} super[b]; } }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('super') + code: 'class A { a() { {}super[b]; } }', + output: 'class A { a() { {} super[b]; } }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('super'), }, { - code: 'class A { a() { {} super[b]; } }', - output: 'class A { a() { {}super[b]; } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('super') + code: 'class A { a() { {} super[b]; } }', + output: 'class A { a() { {}super[b]; } }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('super'), }, { - code: 'class A { a() { {}super[b]; } }', - output: 'class A { a() { {} super[b]; } }', - options: [override('super', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('super') + code: 'class A { a() { {}super[b]; } }', + output: 'class A { a() { {} super[b]; } }', + options: [override('super', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('super'), }, { - code: 'class A { a() { {} super[b]; } }', - output: 'class A { a() { {}super[b]; } }', - options: [override('super', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('super') + code: 'class A { a() { {} super[b]; } }', + output: 'class A { a() { {}super[b]; } }', + options: [override('super', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('super'), }, //---------------------------------------------------------------------- @@ -2831,27 +3846,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}switch(a) {}', - output: '{} switch (a) {}', - errors: expectedBeforeAndAfter('switch') + code: '{}switch(a) {}', + output: '{} switch (a) {}', + errors: expectedBeforeAndAfter('switch'), }, { - code: '{} switch (a) {}', - output: '{}switch(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('switch') + code: '{} switch (a) {}', + output: '{}switch(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('switch'), }, { - code: '{}switch(a) {}', - output: '{} switch (a) {}', - options: [override('switch', BOTH)], - errors: expectedBeforeAndAfter('switch') + code: '{}switch(a) {}', + output: '{} switch (a) {}', + options: [override('switch', BOTH)], + errors: expectedBeforeAndAfter('switch'), }, { - code: '{} switch (a) {}', - output: '{}switch(a) {}', - options: [override('switch', NEITHER)], - errors: unexpectedBeforeAndAfter('switch') + code: '{} switch (a) {}', + output: '{}switch(a) {}', + options: [override('switch', NEITHER)], + errors: unexpectedBeforeAndAfter('switch'), }, //---------------------------------------------------------------------- @@ -2859,27 +3874,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}this[a]', - output: '{} this[a]', - errors: expectedBefore('this') + code: '{}this[a]', + output: '{} this[a]', + errors: expectedBefore('this'), }, { - code: '{} this[a]', - output: '{}this[a]', - options: [NEITHER], - errors: unexpectedBefore('this') + code: '{} this[a]', + output: '{}this[a]', + options: [NEITHER], + errors: unexpectedBefore('this'), }, { - code: '{}this[a]', - output: '{} this[a]', - options: [override('this', BOTH)], - errors: expectedBefore('this') + code: '{}this[a]', + output: '{} this[a]', + options: [override('this', BOTH)], + errors: expectedBefore('this'), }, { - code: '{} this[a]', - output: '{}this[a]', - options: [override('this', NEITHER)], - errors: unexpectedBefore('this') + code: '{} this[a]', + output: '{}this[a]', + options: [override('this', NEITHER)], + errors: unexpectedBefore('this'), }, //---------------------------------------------------------------------- @@ -2887,27 +3902,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'function foo() { {}throw+a }', - output: 'function foo() { {} throw +a }', - errors: expectedBeforeAndAfter('throw') + code: 'function foo() { {}throw+a }', + output: 'function foo() { {} throw +a }', + errors: expectedBeforeAndAfter('throw'), }, { - code: 'function foo() { {} throw +a }', - output: 'function foo() { {}throw+a }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('throw') + code: 'function foo() { {} throw +a }', + output: 'function foo() { {}throw+a }', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('throw'), }, { - code: 'function foo() { {}throw+a }', - output: 'function foo() { {} throw +a }', - options: [override('throw', BOTH)], - errors: expectedBeforeAndAfter('throw') + code: 'function foo() { {}throw+a }', + output: 'function foo() { {} throw +a }', + options: [override('throw', BOTH)], + errors: expectedBeforeAndAfter('throw'), }, { - code: 'function foo() { {} throw +a }', - output: 'function foo() { {}throw+a }', - options: [override('throw', NEITHER)], - errors: unexpectedBeforeAndAfter('throw') + code: 'function foo() { {} throw +a }', + output: 'function foo() { {}throw+a }', + options: [override('throw', NEITHER)], + errors: unexpectedBeforeAndAfter('throw'), }, //---------------------------------------------------------------------- @@ -2915,27 +3930,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}try{} finally {}', - output: '{} try {} finally {}', - errors: expectedBeforeAndAfter('try') + code: '{}try{} finally {}', + output: '{} try {} finally {}', + errors: expectedBeforeAndAfter('try'), }, { - code: '{} try {}finally{}', - output: '{}try{}finally{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('try') + code: '{} try {}finally{}', + output: '{}try{}finally{}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('try'), }, { - code: '{}try{}finally{}', - output: '{} try {}finally{}', - options: [override('try', BOTH)], - errors: expectedBeforeAndAfter('try') + code: '{}try{}finally{}', + output: '{} try {}finally{}', + options: [override('try', BOTH)], + errors: expectedBeforeAndAfter('try'), }, { - code: '{} try {} finally {}', - output: '{}try{} finally {}', - options: [override('try', NEITHER)], - errors: unexpectedBeforeAndAfter('try') + code: '{} try {} finally {}', + output: '{}try{} finally {}', + options: [override('try', NEITHER)], + errors: unexpectedBeforeAndAfter('try'), }, //---------------------------------------------------------------------- @@ -2943,27 +3958,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}typeof foo', - output: '{} typeof foo', - errors: expectedBefore('typeof') + code: '{}typeof foo', + output: '{} typeof foo', + errors: expectedBefore('typeof'), }, { - code: '{} typeof foo', - output: '{}typeof foo', - options: [NEITHER], - errors: unexpectedBefore('typeof') + code: '{} typeof foo', + output: '{}typeof foo', + options: [NEITHER], + errors: unexpectedBefore('typeof'), }, { - code: '{}typeof foo', - output: '{} typeof foo', - options: [override('typeof', BOTH)], - errors: expectedBefore('typeof') + code: '{}typeof foo', + output: '{} typeof foo', + options: [override('typeof', BOTH)], + errors: expectedBefore('typeof'), }, { - code: '{} typeof foo', - output: '{}typeof foo', - options: [override('typeof', NEITHER)], - errors: unexpectedBefore('typeof') + code: '{} typeof foo', + output: '{}typeof foo', + options: [override('typeof', NEITHER)], + errors: unexpectedBefore('typeof'), }, //---------------------------------------------------------------------- @@ -2971,31 +3986,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}var[a] = b', - output: '{} var [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('var') + code: '{}var[a] = b', + output: '{} var [a] = b', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('var'), }, { - code: '{} var [a] = b', - output: '{}var[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('var') + code: '{} var [a] = b', + output: '{}var[a] = b', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('var'), }, { - code: '{}var[a] = b', - output: '{} var [a] = b', - options: [override('var', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('var') + code: '{}var[a] = b', + output: '{} var [a] = b', + options: [override('var', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter('var'), }, { - code: '{} var [a] = b', - output: '{}var[a] = b', - options: [override('var', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('var') + code: '{} var [a] = b', + output: '{}var[a] = b', + options: [override('var', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter('var'), }, //---------------------------------------------------------------------- @@ -3003,27 +4018,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}void foo', - output: '{} void foo', - errors: expectedBefore('void') + code: '{}void foo', + output: '{} void foo', + errors: expectedBefore('void'), }, { - code: '{} void foo', - output: '{}void foo', - options: [NEITHER], - errors: unexpectedBefore('void') + code: '{} void foo', + output: '{}void foo', + options: [NEITHER], + errors: unexpectedBefore('void'), }, { - code: '{}void foo', - output: '{} void foo', - options: [override('void', BOTH)], - errors: expectedBefore('void') + code: '{}void foo', + output: '{} void foo', + options: [override('void', BOTH)], + errors: expectedBefore('void'), }, { - code: '{} void foo', - output: '{}void foo', - options: [override('void', NEITHER)], - errors: unexpectedBefore('void') + code: '{} void foo', + output: '{}void foo', + options: [override('void', NEITHER)], + errors: unexpectedBefore('void'), }, //---------------------------------------------------------------------- @@ -3031,50 +4046,50 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}while(a) {}', - output: '{} while (a) {}', - errors: expectedBeforeAndAfter('while') + code: '{}while(a) {}', + output: '{} while (a) {}', + errors: expectedBeforeAndAfter('while'), }, { - code: 'do {}while(a)', - output: 'do {} while (a)', - errors: expectedBeforeAndAfter('while') + code: 'do {}while(a)', + output: 'do {} while (a)', + errors: expectedBeforeAndAfter('while'), }, { - code: '{} while (a) {}', - output: '{}while(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('while') + code: '{} while (a) {}', + output: '{}while(a) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('while'), }, { - code: 'do{} while (a)', - output: 'do{}while(a)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('while') + code: 'do{} while (a)', + output: 'do{}while(a)', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('while'), }, { - code: '{}while(a) {}', - output: '{} while (a) {}', - options: [override('while', BOTH)], - errors: expectedBeforeAndAfter('while') + code: '{}while(a) {}', + output: '{} while (a) {}', + options: [override('while', BOTH)], + errors: expectedBeforeAndAfter('while'), }, { - code: 'do{}while(a)', - output: 'do{} while (a)', - options: [override('while', BOTH)], - errors: expectedBeforeAndAfter('while') + code: 'do{}while(a)', + output: 'do{} while (a)', + options: [override('while', BOTH)], + errors: expectedBeforeAndAfter('while'), }, { - code: '{} while (a) {}', - output: '{}while(a) {}', - options: [override('while', NEITHER)], - errors: unexpectedBeforeAndAfter('while') + code: '{} while (a) {}', + output: '{}while(a) {}', + options: [override('while', NEITHER)], + errors: unexpectedBeforeAndAfter('while'), }, { - code: 'do {} while (a)', - output: 'do {}while(a)', - options: [override('while', NEITHER)], - errors: unexpectedBeforeAndAfter('while') + code: 'do {} while (a)', + output: 'do {}while(a)', + options: [override('while', NEITHER)], + errors: unexpectedBeforeAndAfter('while'), }, //---------------------------------------------------------------------- @@ -3082,27 +4097,27 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: '{}with(obj) {}', - output: '{} with (obj) {}', - errors: expectedBeforeAndAfter('with') + code: '{}with(obj) {}', + output: '{} with (obj) {}', + errors: expectedBeforeAndAfter('with'), }, { - code: '{} with (obj) {}', - output: '{}with(obj) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('with') + code: '{} with (obj) {}', + output: '{}with(obj) {}', + options: [NEITHER], + errors: unexpectedBeforeAndAfter('with'), }, { - code: '{}with(obj) {}', - output: '{} with (obj) {}', - options: [override('with', BOTH)], - errors: expectedBeforeAndAfter('with') + code: '{}with(obj) {}', + output: '{} with (obj) {}', + options: [override('with', BOTH)], + errors: expectedBeforeAndAfter('with'), }, { - code: '{} with (obj) {}', - output: '{}with(obj) {}', - options: [override('with', NEITHER)], - errors: unexpectedBeforeAndAfter('with') + code: '{} with (obj) {}', + output: '{}with(obj) {}', + options: [override('with', NEITHER)], + errors: unexpectedBeforeAndAfter('with'), }, //---------------------------------------------------------------------- @@ -3110,31 +4125,31 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- { - code: 'function* foo() { {}yield foo }', - output: 'function* foo() { {} yield foo }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('yield') + code: 'function* foo() { {}yield foo }', + output: 'function* foo() { {} yield foo }', + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('yield'), }, { - code: 'function* foo() { {} yield foo }', - output: 'function* foo() { {}yield foo }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('yield') + code: 'function* foo() { {} yield foo }', + output: 'function* foo() { {}yield foo }', + options: [NEITHER], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('yield'), }, { - code: 'function* foo() { {}yield foo }', - output: 'function* foo() { {} yield foo }', - options: [override('yield', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('yield') + code: 'function* foo() { {}yield foo }', + output: 'function* foo() { {} yield foo }', + options: [override('yield', BOTH)], + parserOptions: { ecmaVersion: 6 }, + errors: expectedBefore('yield'), }, { - code: 'function* foo() { {} yield foo }', - output: 'function* foo() { {}yield foo }', - options: [override('yield', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('yield') + code: 'function* foo() { {} yield foo }', + output: 'function* foo() { {}yield foo }', + options: [override('yield', NEITHER)], + parserOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore('yield'), }, //---------------------------------------------------------------------- @@ -3143,10 +4158,11 @@ ruleTester.run('keyword-spacing', rule, { // get, set, async decorator keywords shouldn't be detected { - code: 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }', - output: 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }', - errors: expectedAfter('async') - } - + code: + 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }', + output: + 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }', + errors: expectedAfter('async'), + }, ] as TSESLint.InvalidTestCase[], }); From e0dc65941356a765dc844912b2796f3a31e53c2f Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 01:53:06 +0100 Subject: [PATCH 07/31] removed as any --- packages/eslint-plugin/src/rules/keyword-spacing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 80a56c44cfcc..2f377a690d17 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -392,7 +392,7 @@ export default util.createRule({ */ function checkSpacingForIfStatement(node: TSESTree.IfStatement) { checkSpacingAroundFirstToken(node); - checkSpacingAroundTokenBefore((node as any).alternate); + checkSpacingAroundTokenBefore(node.alternate!); } /** From 644cb332014aff511c5333655c0668a3b440e3c7 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 12:49:12 +0100 Subject: [PATCH 08/31] Import what's available from base rule --- .../src/rules/keyword-spacing.ts | 349 +----------------- .../eslint-plugin/typings/eslint-rules.d.ts | 61 +++ 2 files changed, 74 insertions(+), 336 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 2f377a690d17..b6ad2a27356a 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,9 +1,10 @@ +import baseRule from 'eslint/lib/rules/keyword-spacing'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; +import { isTokenOnSameLine } from '../util/astUtils'; import keywords from 'eslint/lib/rules/utils/keywords'; + import * as util from '../util'; -import { TSESTree } from '@typescript-eslint/experimental-utils'; -import { JSONSchema4 } from 'json-schema'; -import { isTokenOnSameLine, isKeywordToken } from '../util/astUtils'; -import { isNotOpeningParenToken } from 'eslint-utils'; + export type Option = Partial<{ before: boolean; @@ -14,21 +15,11 @@ export type RootOption = Option & { overrides?: { [keywordName: string]: Option }; }; -export type Options = [RootOption]; -export type MessageIds = - | 'expectedBefore' - | 'expectedAfter' - | 'unexpectedBefore' - | 'unexpectedAfter'; +export type MessageIds = util.InferMessageIdsTypeFromRule; -//------------------------------------------------------------------------------ -// Constants -//------------------------------------------------------------------------------ const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; -const PREV_TOKEN_M = /^[)\]}>*]$/u; -const NEXT_TOKEN_M = /^[{*]$/u; const TEMPLATE_OPEN_PAREN = /\$\{$/u; const TEMPLATE_CLOSE_PAREN = /^\}/u; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; @@ -44,16 +35,6 @@ const KEYS = keywords.concat([ 'yield', ]); -// check duplications. -(function() { - KEYS.sort(); - for (let i = 1; i < KEYS.length; ++i) { - if (KEYS[i] === KEYS[i - 1]) { - throw new Error(`Duplication was found in the keyword list: ${KEYS[i]}`); - } - } -})(); - //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -87,42 +68,15 @@ export default util.createRule({ extendsBaseRule: true, }, fixable: 'whitespace', - schema: [ - { - type: 'object', - properties: { - before: { type: 'boolean', default: true }, - after: { type: 'boolean', default: true }, - overrides: { - type: 'object', - properties: KEYS.reduce((retv: JSONSchema4, key) => { - retv[key] = { - type: 'object', - properties: { - before: { type: 'boolean' }, - after: { type: 'boolean' }, - }, - additionalProperties: false, - }; - return retv; - }, {}), - additionalProperties: false, - }, - }, - additionalProperties: false, - }, - ], - messages: { - expectedBefore: 'Expected space(s) before "{{value}}".', - expectedAfter: 'Expected space(s) after "{{value}}".', - unexpectedBefore: 'Unexpected space(s) before "{{value}}".', - unexpectedAfter: 'Unexpected space(s) after "{{value}}".', - }, + schema: baseRule.meta.schema, + messages: baseRule.meta.messages, }, - defaultOptions: [{ before: true, after: true }], + defaultOptions: [], create(context) { const sourceCode = context.getSourceCode(); + const baseRules = baseRule.create(context); + /** * Reports a given token if there are not space(s) before the token. * @param token A token to report. @@ -235,6 +189,7 @@ export default util.createRule({ } } + /** * Parses the option object and determines check methods for each keyword. * @param options The option object to parse. @@ -302,238 +257,6 @@ export default util.createRule({ checkSpacingAfter(token); } - /** - * Reports the first token of a given node if the first token is a keyword - * and usage of spacing around the token is invalid. - * @param node A node to report. - */ - function checkSpacingAroundFirstToken(node: TSESTree.Node) { - const firstToken = node && sourceCode.getFirstToken(node); - - if (firstToken && firstToken.type === 'Keyword') { - checkSpacingAround(firstToken); - } - } - - /** - * Reports the first token of a given node if the first token is a keyword - * and usage of spacing followed by the token is invalid. - * - * This is used for unary operators (e.g. `typeof`), `function`, and `super`. - * Other rules are handling usage of spacing preceded by those keywords. - * @param node A node to report. - */ - function checkSpacingBeforeFirstToken( - node: - | TSESTree.NewExpression - | TSESTree.Super - | TSESTree.ThisExpression - | TSESTree.UnaryExpression - | TSESTree.YieldExpression, - ) { - const firstToken = node && sourceCode.getFirstToken(node); - - if (firstToken && firstToken.type === 'Keyword') { - checkSpacingBefore(firstToken); - } - } - - /** - * Reports the previous token of a given node if the token is a keyword and - * usage of spacing around the token is invalid. - * @param node A node to report. - */ - function checkSpacingAroundTokenBefore(node: TSESTree.Node) { - if (node) { - const token = sourceCode.getTokenBefore(node, isKeywordToken)!; - - checkSpacingAround(token); - } - } - - /** - * Reports `async` or `function` keywords of a given node if usage of - * spacing around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForFunction( - node: - | TSESTree.FunctionDeclaration - | TSESTree.ArrowFunctionExpression - | TSESTree.FunctionExpression, - ) { - const firstToken = node && sourceCode.getFirstToken(node); - - if ( - firstToken && - ((firstToken.type === 'Keyword' && firstToken.value === 'function') || - firstToken.value === 'async') - ) { - checkSpacingBefore(firstToken); - } - } - - /** - * Reports `class` and `extends` keywords of a given node if usage of - * spacing around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForClass( - node: TSESTree.ClassExpression | TSESTree.ClassDeclaration, - ) { - checkSpacingAroundFirstToken(node); - checkSpacingAroundTokenBefore(node.superClass!); - } - - /** - * Reports `if` and `else` keywords of a given node if usage of spacing - * around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForIfStatement(node: TSESTree.IfStatement) { - checkSpacingAroundFirstToken(node); - checkSpacingAroundTokenBefore(node.alternate!); - } - - /** - * Reports `try`, `catch`, and `finally` keywords of a given node if usage - * of spacing around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForTryStatement(node: TSESTree.TryStatement) { - checkSpacingAroundFirstToken(node); - checkSpacingAroundFirstToken(node.handler!); - checkSpacingAroundTokenBefore(node.finalizer); - } - - /** - * Reports `do` and `while` keywords of a given node if usage of spacing - * around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForDoWhileStatement(node: TSESTree.DoWhileStatement) { - checkSpacingAroundFirstToken(node); - checkSpacingAroundTokenBefore(node.test); - } - - /** - * Reports `for` and `in` keywords of a given node if usage of spacing - * around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForForInStatement(node: TSESTree.ForInStatement) { - checkSpacingAroundFirstToken(node); - checkSpacingAroundTokenBefore(node.right); - } - - /** - * Reports `for` and `of` keywords of a given node if usage of spacing - * around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForForOfStatement(node: TSESTree.ForOfStatement) { - if (node.await) { - checkSpacingBefore(sourceCode.getFirstToken(node, 0)!); - checkSpacingAfter(sourceCode.getFirstToken(node, 1)!); - } else { - checkSpacingAroundFirstToken(node); - } - checkSpacingAround( - sourceCode.getTokenBefore(node.right, isNotOpeningParenToken)!, - ); - } - - /** - * Reports `import`, `export`, `as`, and `from` keywords of a given node if - * usage of spacing around those keywords is invalid. - * - * This rule handles the `*` token in module declarations. - * - * import*as A from "./a"; /*error Expected space(s) after "import". - * error Expected space(s) before "as". - * @param node A node to report. - */ - function checkSpacingForModuleDeclaration( - node: - | TSESTree.ExportNamedDeclaration - | TSESTree.ExportDefaultDeclaration - | TSESTree.ExportAllDeclaration - | TSESTree.ImportDeclaration, - ) { - const firstToken = sourceCode.getFirstToken(node)!; - - checkSpacingBefore(firstToken, PREV_TOKEN_M); - checkSpacingAfter(firstToken, NEXT_TOKEN_M); - - if (node.type === 'ExportDefaultDeclaration') { - checkSpacingAround(sourceCode.getTokenAfter(firstToken)!); - } - - if ((node as any).source) { - const fromToken = sourceCode.getTokenBefore((node as any).source)!; - - checkSpacingBefore(fromToken, PREV_TOKEN_M); - checkSpacingAfter(fromToken, NEXT_TOKEN_M); - } - } - - /** - * Reports `as` keyword of a given node if usage of spacing around this - * keyword is invalid. - * @param node A node to report. - */ - function checkSpacingForImportNamespaceSpecifier(node: TSESTree.Node) { - const asToken = sourceCode.getFirstToken(node, 1)!; - - checkSpacingBefore(asToken, PREV_TOKEN_M); - } - /** - * Reports `static`, `get`, and `set` keywords of a given node if usage of - * spacing around those keywords is invalid. - * @param node A node to report. - */ - function checkSpacingForProperty( - node: TSESTree.MethodDefinition | TSESTree.Property, - ) { - if ((node as any).static) { - checkSpacingAroundFirstToken(node); - } - if ( - node.kind === 'get' || - node.kind === 'set' || - (((node as any).method || node.type === 'MethodDefinition') && - (node as any).value.async) - ) { - const token = sourceCode.getTokenBefore(node.key, tok => { - switch (tok.value) { - case 'get': - case 'set': - case 'async': - return true; - default: - return false; - } - }); - - if (!token) { - throw new Error( - 'Failed to find token get, set, or async beside method name', - ); - } - - checkSpacingAround(token); - } - } - - /** - * Reports `await` keyword of a given node if usage of spacing before - * this keyword is invalid. - * @param node A node to report. - */ - function checkSpacingForAwaitExpression(node: TSESTree.AwaitExpression) { - checkSpacingBefore(sourceCode.getFirstToken(node)!); - } - /** * Reports `as` keyword of a given node if usage of spacing before * this keyword is invalid. @@ -545,53 +268,7 @@ export default util.createRule({ } return { - // Statements - DebuggerStatement: checkSpacingAroundFirstToken, - WithStatement: checkSpacingAroundFirstToken, - - // Statements - Control flow - BreakStatement: checkSpacingAroundFirstToken, - ContinueStatement: checkSpacingAroundFirstToken, - ReturnStatement: checkSpacingAroundFirstToken, - ThrowStatement: checkSpacingAroundFirstToken, - TryStatement: checkSpacingForTryStatement, - - // Statements - Choice - IfStatement: checkSpacingForIfStatement, - SwitchStatement: checkSpacingAroundFirstToken, - SwitchCase: checkSpacingAroundFirstToken, - - // Statements - Loops - DoWhileStatement: checkSpacingForDoWhileStatement, - ForInStatement: checkSpacingForForInStatement, - ForOfStatement: checkSpacingForForOfStatement, - ForStatement: checkSpacingAroundFirstToken, - WhileStatement: checkSpacingAroundFirstToken, - - // Statements - Declarations - ClassDeclaration: checkSpacingForClass, - ExportNamedDeclaration: checkSpacingForModuleDeclaration, - ExportDefaultDeclaration: checkSpacingForModuleDeclaration, - ExportAllDeclaration: checkSpacingForModuleDeclaration, - FunctionDeclaration: checkSpacingForFunction, - ImportDeclaration: checkSpacingForModuleDeclaration, - VariableDeclaration: checkSpacingAroundFirstToken, - - // Expressions - ArrowFunctionExpression: checkSpacingForFunction, - AwaitExpression: checkSpacingForAwaitExpression, - ClassExpression: checkSpacingForClass, - FunctionExpression: checkSpacingForFunction, - NewExpression: checkSpacingBeforeFirstToken, - Super: checkSpacingBeforeFirstToken, - ThisExpression: checkSpacingBeforeFirstToken, - UnaryExpression: checkSpacingBeforeFirstToken, - YieldExpression: checkSpacingBeforeFirstToken, - - // Others - ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier, - MethodDefinition: checkSpacingForProperty, - Property: checkSpacingForProperty, + ...baseRules, TSAsExpression: checkSpacingForAsExpression, }; }, diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index ea60d9b31697..6506ca170268 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -142,6 +142,67 @@ declare module 'eslint/lib/rules/indent' { export = rule; } + +declare module 'eslint/lib/rules/keyword-spacing' { + import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; + + const rule: TSESLint.RuleModule< + 'expectedBefore' | 'expectedAfter' | 'unexpectedBefore' | 'unexpectedAfter', + [], + { + // Statements + DebuggerStatement: (node: TSESTree.DebuggerStatement) => void, + WithStatement: (node: TSESTree.WithStatement) => void, + + // Statements - Control flow + BreakStatement: (node: TSESTree.BreakStatement) => void, + ContinueStatement: (node: TSESTree.ContinueStatement) => void, + ReturnStatement: (node: TSESTree.ReturnStatement) => void, + ThrowStatement: (node: TSESTree.ThrowStatement) => void, + TryStatement: (node: TSESTree.TryStatement) => void, + + // Statements - Choice + IfStatement: (node: TSESTree.IfStatement) => void, + SwitchStatement: (node: TSESTree.Node) => void, + SwitchCase: (node: TSESTree.Node) => void, + + // Statements - Loops + DoWhileStatement: (node: TSESTree.DoWhileStatement) => void, + ForInStatement: (node: TSESTree.ForInStatement) => void, + ForOfStatement: (node: TSESTree.ForOfStatement) => void, + ForStatement: (node: TSESTree.ForStatement) => void, + WhileStatement: (node: TSESTree.WhileStatement) => void, + + // Statements - Declarations + ClassDeclaration: (node: TSESTree.ClassDeclaration) => void, + ExportNamedDeclaration: (node: TSESTree.ExportNamedDeclaration) => void, + ExportDefaultDeclaration: (node: TSESTree.ExportDefaultDeclaration) => void, + ExportAllDeclaration: (node: TSESTree.ExportAllDeclaration) => void, + FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void, + ImportDeclaration: (node: TSESTree.ImportDeclaration) => void, + VariableDeclaration: (node: TSESTree.VariableDeclaration) => void, + + // Expressions + ArrowFunctionExpression: (node: TSESTree.ArrowFunctionExpression) => void, + AwaitExpression: (node: TSESTree.AwaitExpression) => void, + ClassExpression: (node: TSESTree.ClassExpression) => void, + FunctionExpression: (node: TSESTree.FunctionExpression) => void, + NewExpression: (node: TSESTree.NewExpression) => void, + Super: (node: TSESTree.Super) => void, + ThisExpression: (node: TSESTree.ThisExpression) => void, + UnaryExpression: (node: TSESTree.UnaryExpression) => void, + YieldExpression: (node: TSESTree.YieldExpression) => void, + + // Others + ImportNamespaceSpecifier: (node: TSESTree.ImportNamespaceSpecifier) => void, + MethodDefinition: (node: TSESTree.MethodDefinition) => void, + Property: (node: TSESTree.Property) => void, + } + >; + export = rule; +} + + declare module 'eslint/lib/rules/no-dupe-class-members' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; From 23975f2655b6684b4e0fdaa0d5718bed19a3f506 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 12:52:11 +0100 Subject: [PATCH 09/31] Moved keyword typing file --- .../{src/types/eslint.d.ts => typings/eslint-keywords.d.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/eslint-plugin/{src/types/eslint.d.ts => typings/eslint-keywords.d.ts} (100%) diff --git a/packages/eslint-plugin/src/types/eslint.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts similarity index 100% rename from packages/eslint-plugin/src/types/eslint.d.ts rename to packages/eslint-plugin/typings/eslint-keywords.d.ts From f0e95bffc61584831ef66f9be070fa191b85148e Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 16 Mar 2020 12:57:11 +0100 Subject: [PATCH 10/31] Prettyfied --- .../src/rules/keyword-spacing.ts | 3 - .../eslint-plugin/typings/eslint-rules.d.ts | 74 ++++++++++--------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index b6ad2a27356a..d95ae003d2d6 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -5,7 +5,6 @@ import keywords from 'eslint/lib/rules/utils/keywords'; import * as util from '../util'; - export type Option = Partial<{ before: boolean; after: boolean; @@ -17,7 +16,6 @@ export type RootOption = Option & { export type MessageIds = util.InferMessageIdsTypeFromRule; - const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; const TEMPLATE_OPEN_PAREN = /\$\{$/u; @@ -189,7 +187,6 @@ export default util.createRule({ } } - /** * Parses the option object and determines check methods for each keyword. * @param options The option object to parse. diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 6506ca170268..9d9c88b73bb2 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -142,7 +142,6 @@ declare module 'eslint/lib/rules/indent' { export = rule; } - declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; @@ -151,58 +150,61 @@ declare module 'eslint/lib/rules/keyword-spacing' { [], { // Statements - DebuggerStatement: (node: TSESTree.DebuggerStatement) => void, - WithStatement: (node: TSESTree.WithStatement) => void, + DebuggerStatement: (node: TSESTree.DebuggerStatement) => void; + WithStatement: (node: TSESTree.WithStatement) => void; // Statements - Control flow - BreakStatement: (node: TSESTree.BreakStatement) => void, - ContinueStatement: (node: TSESTree.ContinueStatement) => void, - ReturnStatement: (node: TSESTree.ReturnStatement) => void, - ThrowStatement: (node: TSESTree.ThrowStatement) => void, - TryStatement: (node: TSESTree.TryStatement) => void, + BreakStatement: (node: TSESTree.BreakStatement) => void; + ContinueStatement: (node: TSESTree.ContinueStatement) => void; + ReturnStatement: (node: TSESTree.ReturnStatement) => void; + ThrowStatement: (node: TSESTree.ThrowStatement) => void; + TryStatement: (node: TSESTree.TryStatement) => void; // Statements - Choice - IfStatement: (node: TSESTree.IfStatement) => void, - SwitchStatement: (node: TSESTree.Node) => void, - SwitchCase: (node: TSESTree.Node) => void, + IfStatement: (node: TSESTree.IfStatement) => void; + SwitchStatement: (node: TSESTree.Node) => void; + SwitchCase: (node: TSESTree.Node) => void; // Statements - Loops - DoWhileStatement: (node: TSESTree.DoWhileStatement) => void, - ForInStatement: (node: TSESTree.ForInStatement) => void, - ForOfStatement: (node: TSESTree.ForOfStatement) => void, - ForStatement: (node: TSESTree.ForStatement) => void, - WhileStatement: (node: TSESTree.WhileStatement) => void, + DoWhileStatement: (node: TSESTree.DoWhileStatement) => void; + ForInStatement: (node: TSESTree.ForInStatement) => void; + ForOfStatement: (node: TSESTree.ForOfStatement) => void; + ForStatement: (node: TSESTree.ForStatement) => void; + WhileStatement: (node: TSESTree.WhileStatement) => void; // Statements - Declarations - ClassDeclaration: (node: TSESTree.ClassDeclaration) => void, - ExportNamedDeclaration: (node: TSESTree.ExportNamedDeclaration) => void, - ExportDefaultDeclaration: (node: TSESTree.ExportDefaultDeclaration) => void, - ExportAllDeclaration: (node: TSESTree.ExportAllDeclaration) => void, - FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void, - ImportDeclaration: (node: TSESTree.ImportDeclaration) => void, - VariableDeclaration: (node: TSESTree.VariableDeclaration) => void, + ClassDeclaration: (node: TSESTree.ClassDeclaration) => void; + ExportNamedDeclaration: (node: TSESTree.ExportNamedDeclaration) => void; + ExportDefaultDeclaration: ( + node: TSESTree.ExportDefaultDeclaration, + ) => void; + ExportAllDeclaration: (node: TSESTree.ExportAllDeclaration) => void; + FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void; + ImportDeclaration: (node: TSESTree.ImportDeclaration) => void; + VariableDeclaration: (node: TSESTree.VariableDeclaration) => void; // Expressions - ArrowFunctionExpression: (node: TSESTree.ArrowFunctionExpression) => void, - AwaitExpression: (node: TSESTree.AwaitExpression) => void, - ClassExpression: (node: TSESTree.ClassExpression) => void, - FunctionExpression: (node: TSESTree.FunctionExpression) => void, - NewExpression: (node: TSESTree.NewExpression) => void, - Super: (node: TSESTree.Super) => void, - ThisExpression: (node: TSESTree.ThisExpression) => void, - UnaryExpression: (node: TSESTree.UnaryExpression) => void, - YieldExpression: (node: TSESTree.YieldExpression) => void, + ArrowFunctionExpression: (node: TSESTree.ArrowFunctionExpression) => void; + AwaitExpression: (node: TSESTree.AwaitExpression) => void; + ClassExpression: (node: TSESTree.ClassExpression) => void; + FunctionExpression: (node: TSESTree.FunctionExpression) => void; + NewExpression: (node: TSESTree.NewExpression) => void; + Super: (node: TSESTree.Super) => void; + ThisExpression: (node: TSESTree.ThisExpression) => void; + UnaryExpression: (node: TSESTree.UnaryExpression) => void; + YieldExpression: (node: TSESTree.YieldExpression) => void; // Others - ImportNamespaceSpecifier: (node: TSESTree.ImportNamespaceSpecifier) => void, - MethodDefinition: (node: TSESTree.MethodDefinition) => void, - Property: (node: TSESTree.Property) => void, + ImportNamespaceSpecifier: ( + node: TSESTree.ImportNamespaceSpecifier, + ) => void; + MethodDefinition: (node: TSESTree.MethodDefinition) => void; + Property: (node: TSESTree.Property) => void; } >; export = rule; } - declare module 'eslint/lib/rules/no-dupe-class-members' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; From 6da07f6b8701ef6ce6a3282455333f4283adf4c6 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 14:41:07 +0100 Subject: [PATCH 11/31] Better typing --- .../src/rules/keyword-spacing.ts | 41 +- .../tests/rules/keyword-spacing.test.ts | 4082 +---------------- .../eslint-plugin/typings/eslint-rules.d.ts | 91 +- 3 files changed, 110 insertions(+), 4104 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index d95ae003d2d6..c9f4435ecc78 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,38 +1,19 @@ -import baseRule from 'eslint/lib/rules/keyword-spacing'; +import baseRule, { + Options, + RootOption, + OverrideOptions, + MessageIds, +} from 'eslint/lib/rules/keyword-spacing'; import { TSESTree } from '@typescript-eslint/experimental-utils'; -import { isTokenOnSameLine } from '../util/astUtils'; -import keywords from 'eslint/lib/rules/utils/keywords'; +import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; import * as util from '../util'; -export type Option = Partial<{ - before: boolean; - after: boolean; -}>; - -export type RootOption = Option & { - overrides?: { [keywordName: string]: Option }; -}; - -export type MessageIds = util.InferMessageIdsTypeFromRule; - const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; const TEMPLATE_OPEN_PAREN = /\$\{$/u; const TEMPLATE_CLOSE_PAREN = /^\}/u; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; -const KEYS = keywords.concat([ - 'as', - 'async', - 'await', - 'from', - 'get', - 'let', - 'of', - 'set', - 'yield', -]); - //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -69,7 +50,7 @@ export default util.createRule({ schema: baseRule.meta.schema, messages: baseRule.meta.messages, }, - defaultOptions: [], + defaultOptions: [{}], create(context) { const sourceCode = context.getSourceCode(); @@ -203,11 +184,11 @@ export default util.createRule({ before: before ? expectSpaceBefore : unexpectSpaceBefore, after: after ? expectSpaceAfter : unexpectSpaceAfter, }; - const overrides = (options && options.overrides) || {}; + const overrides: OverrideOptions = (options && options.overrides) || {}; const retv = Object.create(null); - for (let i = 0; i < KEYS.length; ++i) { - const key = KEYS[i]; + for (let i = 0; i < KEYWORDS.length; ++i) { + const key = KEYWORDS[i] as Keyword; const override = overrides[key]; if (override) { diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index ff1257ae27b0..7bd5c6e5baa3 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,11 +1,7 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import rule, { - MessageIds, - Options, - Option, - RootOption, -} from '../../src/rules/keyword-spacing'; +import rule from '../../src/rules/keyword-spacing'; import { RuleTester } from '../RuleTester'; +import { MessageIds, Options } from 'eslint/lib/rules/keyword-spacing'; //------------------------------------------------------------------------------ // Helpers @@ -49,30 +45,6 @@ function expectedBefore(keyword: string): TSESLint.TestCaseError[] { return [{ messageId: 'expectedBefore', data: { value: keyword } }]; } -/** - * Gets an error message that expected space(s) after a specified keyword. - * @param keyword A keyword. - * @returns An error message. - */ -function expectedAfter(keyword: string): TSESLint.TestCaseError[] { - return [{ messageId: 'expectedAfter', data: { value: keyword } }]; -} - -/** - * Gets error messages that expected space(s) before and after a specified - * keyword. - * @param keyword A keyword. - * @returns Error messages. - */ -function expectedBeforeAndAfter( - keyword: string, -): TSESLint.TestCaseError[] { - return [ - { messageId: 'expectedBefore', data: { value: keyword } }, - { messageId: 'expectedAfter', data: { value: keyword } }, - ]; -} - /** * Gets an error message that unexpected space(s) before a specified keyword. * @param keyword A keyword. @@ -84,31 +56,6 @@ function unexpectedBefore( return [{ messageId: 'unexpectedBefore', data: { value: keyword } }]; } -/** - * Gets an error message that unexpected space(s) after a specified keyword. - * @param keyword A keyword. - * @returns An error message. - */ -function unexpectedAfter( - keyword: string, -): TSESLint.TestCaseError[] { - return [{ messageId: 'unexpectedAfter', data: { value: keyword } }]; -} - -/** - * Gets error messages that unexpected space(s) before and after a specified - * keyword. - * @param keyword A keyword. - * @returns Error messages. - */ -function unexpectedBeforeAndAfter( - keyword: string, -): TSESLint.TestCaseError[] { - return [ - { messageId: 'unexpectedBefore', data: { value: keyword } }, - { messageId: 'unexpectedAfter', data: { value: keyword } }, - ]; -} const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', @@ -116,30 +63,6 @@ const ruleTester = new RuleTester({ ruleTester.run('keyword-spacing', rule, { valid: [ - //---------------------------------------------------------------------- - // as (import) - //---------------------------------------------------------------------- - - { - code: 'import * as a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import* as a from"foo"', - options: [override('as', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import *as a from "foo"', - options: [override('as', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - //---------------------------------------------------------------------- // as (typing) //---------------------------------------------------------------------- @@ -163,4006 +86,25 @@ ruleTester.run('keyword-spacing', rule, { options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, + ] as TSESLint.ValidTestCase[], + invalid: [ //---------------------------------------------------------------------- - // async - //---------------------------------------------------------------------- - - { code: '{} async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { - code: '{}async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '{} async function foo() {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '{}async function foo() {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - }, - { code: '{} async () => {}', parserOptions: { ecmaVersion: 8 } }, - { - code: '{}async () => {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '{} async () => {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '{}async () => {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - }, - { code: '({async [b]() {}})', parserOptions: { ecmaVersion: 8 } }, - { - code: '({async[b]() {}})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '({async [b]() {}})', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '({async[b]() {}})', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'class A {a(){} async [b]() {}}', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'class A {a(){}async[b]() {}}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'class A {a(){} async [b]() {}}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'class A {a(){}async[b]() {}}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `array-bracket-spacing` - { code: '[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, - { - code: '[ async function foo() {}]', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `arrow-spacing` - { code: '() =>async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { - code: '() => async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `block-spacing` - { code: '{async function foo() {} }', parserOptions: { ecmaVersion: 8 } }, - { - code: '{ async function foo() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `comma-spacing` - { code: '(0,async function foo() {})', parserOptions: { ecmaVersion: 8 } }, - { - code: '(0, async function foo() {})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `computed-property-spacing` - { code: 'a[async function foo() {}]', parserOptions: { ecmaVersion: 8 } }, - { - code: '({[async function foo() {}]: 0})', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'a[ async function foo() {}]', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '({[ async function foo() {}]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `generator-star-spacing` - { code: '({ async* foo() {} })', parserOptions: { ecmaVersion: 2018 } }, - { - code: '({ async *foo() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 2018 }, - }, - - // not conflict with `key-spacing` - { - code: '({a:async function foo() {} })', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: '({a: async function foo() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `semi-spacing` - { code: ';async function foo() {};', parserOptions: { ecmaVersion: 8 } }, - { - code: '; async function foo() {} ;', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-before-function-paren` - { code: 'async() => {}', parserOptions: { ecmaVersion: 8 } }, - { - code: 'async () => {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-in-parens` - { code: '(async function foo() {})', parserOptions: { ecmaVersion: 8 } }, - { - code: '( async function foo() {})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-infix-ops` - { code: 'a =async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { - code: 'a = async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-unary-ops` - { code: '!async function foo() {}', parserOptions: { ecmaVersion: 8 } }, - { - code: '! async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `template-curly-spacing` - { code: '`${async function foo() {}}`', parserOptions: { ecmaVersion: 8 } }, - { - code: '`${ async function foo() {}}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // await + // as (typing) //---------------------------------------------------------------------- { - code: 'async function wrap() { {} await +1 }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { {}await +1 }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { {} await +1 }', - options: [override('await', BOTH)], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { {}await +1 }', - options: [override('await', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `array-bracket-spacing` - { - code: 'async function wrap() { [await a] }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { [ await a] }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `arrow-spacing` - { code: 'async () =>await a', parserOptions: { ecmaVersion: 8 } }, - { - code: 'async () => await a', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `block-spacing` - { - code: 'async function wrap() { {await a } }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { { await a } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `comma-spacing` - { - code: 'async function wrap() { (0,await a) }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { (0, await a) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `computed-property-spacing` - { - code: 'async function wrap() { a[await a] }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { ({[await a]: 0}) }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { a[ await a] }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { ({[ await a]: 0}) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `key-spacing` - { - code: 'async function wrap() { ({a:await a }) }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { ({a: await a }) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `semi-spacing` - { - code: 'async function wrap() { ;await a; }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { ; await a ; }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-in-parens` - { - code: 'async function wrap() { (await a) }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { ( await a) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-infix-ops` - { - code: 'async function wrap() { a =await a }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { a = await a }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `space-unary-ops` - { - code: "async function wrap() { !await'a' }", - parserOptions: { ecmaVersion: 8 }, - }, - { - code: "async function wrap() { ! await 'a' }", - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `template-curly-spacing` - { - code: 'async function wrap() { `${await a}` }', - parserOptions: { ecmaVersion: 8 }, - }, - { - code: 'async function wrap() { `${ await a}` }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: 'async function wrap() { }', - parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, + code: 'const foo = {}as {}', + output: 'const foo = {} as {}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedBefore('as'), }, { - code: 'async function wrap() { }', + code: 'const foo = {} as{}', + output: 'const foo = {}as{}', options: [NEITHER], - parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // break - //---------------------------------------------------------------------- - - 'A: for (;;) { {} break A; }', - { code: 'A: for(;;) { {}break A; }', options: [NEITHER] }, - { code: 'A: for(;;) { {} break A; }', options: [override('break', BOTH)] }, - { - code: 'A: for (;;) { {}break A; }', - options: [override('break', NEITHER)], - }, - - // not conflict with `block-spacing` - 'for (;;) {break}', - { code: 'for(;;) { break }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'for (;;) { ;break; }', - { code: 'for(;;) { ; break ; }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // case - //---------------------------------------------------------------------- - - 'switch (a) { case 0: {} case +1: }', - 'switch (a) { case 0: {} case (1): }', - { code: 'switch(a) { case 0: {}case+1: }', options: [NEITHER] }, - { code: 'switch(a) { case 0: {}case(1): }', options: [NEITHER] }, - { - code: 'switch(a) { case 0: {} case +1: }', - options: [override('case', BOTH)], - }, - { - code: 'switch (a) { case 0: {}case+1: }', - options: [override('case', NEITHER)], - }, - - // not conflict with `block-spacing` - 'switch (a) {case 0: }', - { code: 'switch(a) { case 0: }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'switch (a) { case 0: ;case 1: }', - { code: 'switch(a) { case 0: ; case 1: }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // catch - //---------------------------------------------------------------------- - - 'try {} catch (e) {}', - { code: 'try{}catch(e) {}', options: [NEITHER] }, - { code: 'try{} catch (e) {}', options: [override('catch', BOTH)] }, - { code: 'try {}catch(e) {}', options: [override('catch', NEITHER)] }, - 'try {}\ncatch (e) {}', - { code: 'try{}\ncatch(e) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // class - //---------------------------------------------------------------------- - - { code: '{} class Bar {}', parserOptions: { ecmaVersion: 6 } }, - { code: '(class {})', parserOptions: { ecmaVersion: 6 } }, - { - code: '{}class Bar {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '(class{})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{} class Bar {}', - options: [override('class', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}class Bar {}', - options: [override('class', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `array-bracket-spacing` - { code: '[class {}]', parserOptions: { ecmaVersion: 6 } }, - { - code: '[ class{}]', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `arrow-spacing` - { code: '() =>class {}', parserOptions: { ecmaVersion: 6 } }, - { - code: '() => class{}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - { code: '{class Bar {} }', parserOptions: { ecmaVersion: 6 } }, - { - code: '{ class Bar {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `comma-spacing` - { code: '(0,class {})', parserOptions: { ecmaVersion: 6 } }, - { - code: '(0, class{})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `computed-property-spacing` - { code: 'a[class {}]', parserOptions: { ecmaVersion: 6 } }, - { code: '({[class {}]: 0})', parserOptions: { ecmaVersion: 6 } }, - { - code: 'a[ class{}]', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({[ class{}]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - { code: '({a:class {} })', parserOptions: { ecmaVersion: 6 } }, - { - code: '({a: class{} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { code: ';class Bar {};', parserOptions: { ecmaVersion: 6 } }, - { - code: '; class Bar {} ;', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-in-parens` - { - code: '( class{})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-infix-ops` - { code: 'a =class {}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'a = class{}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-unary-ops` - { code: '!class {}', parserOptions: { ecmaVersion: 6 } }, - { - code: '! class{}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `template-curly-spacing` - { code: '`${class {}}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ class{}}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // const - //---------------------------------------------------------------------- - - { code: '{} const [a] = b', parserOptions: { ecmaVersion: 6 } }, - { code: '{} const {a} = b', parserOptions: { ecmaVersion: 6 } }, - { - code: '{}const[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}const{a} = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{} const [a] = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{} const {a} = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}const[a] = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}const{a} = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - { code: '{const a = b}', parserOptions: { ecmaVersion: 6 } }, - { - code: '{ const a = b}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { code: ';const a = b;', parserOptions: { ecmaVersion: 6 } }, - { - code: '; const a = b ;', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // continue - //---------------------------------------------------------------------- - - 'A: for (;;) { {} continue A; }', - { code: 'A: for(;;) { {}continue A; }', options: [NEITHER] }, - { - code: 'A: for(;;) { {} continue A; }', - options: [override('continue', BOTH)], - }, - { - code: 'A: for (;;) { {}continue A; }', - options: [override('continue', NEITHER)], - }, - - // not conflict with `block-spacing` - 'for (;;) {continue}', - { code: 'for(;;) { continue }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'for (;;) { ;continue; }', - { code: 'for(;;) { ; continue ; }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // debugger - //---------------------------------------------------------------------- - - '{} debugger', - { code: '{}debugger', options: [NEITHER] }, - { code: '{} debugger', options: [override('debugger', BOTH)] }, - { code: '{}debugger', options: [override('debugger', NEITHER)] }, - - // not conflict with `block-spacing` - '{debugger}', - { code: '{ debugger }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';debugger;', - { code: '; debugger ;', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // default - //---------------------------------------------------------------------- - - 'switch (a) { case 0: {} default: }', - { code: 'switch(a) { case 0: {}default: }', options: [NEITHER] }, - { - code: 'switch(a) { case 0: {} default: }', - options: [override('default', BOTH)], - }, - { - code: 'switch (a) { case 0: {}default: }', - options: [override('default', NEITHER)], - }, - - // not conflict with `block-spacing` - 'switch (a) {default:}', - { code: 'switch(a) { default: }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'switch (a) { case 0: ;default: }', - { code: 'switch(a) { case 0: ; default: }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // delete - //---------------------------------------------------------------------- - - '{} delete foo.a', - { code: '{}delete foo.a', options: [NEITHER] }, - { code: '{} delete foo.a', options: [override('delete', BOTH)] }, - { code: '{}delete foo.a', options: [override('delete', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[delete foo.a]', - { code: '[ delete foo.a]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>delete foo.a)', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => delete foo.a)', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{delete foo.a }', - { code: '{ delete foo.a }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,delete foo.a)', - { code: '(0, delete foo.a)', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[delete foo.a]', - { code: '({[delete foo.a]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ delete foo.a]', options: [NEITHER] }, - { - code: '({[ delete foo.a]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:delete foo.a })', - { code: '({a: delete foo.a })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';delete foo.a', - { code: '; delete foo.a', options: [NEITHER] }, - - // not conflict with `space-in-parens` - '(delete foo.a)', - { code: '( delete foo.a)', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =delete foo.a', - { code: 'a = delete foo.a', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!delete(foo.a)', - { code: '! delete (foo.a)', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${delete foo.a}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ delete foo.a}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // do - //---------------------------------------------------------------------- - - '{} do {} while (true)', - { code: '{}do{}while(true)', options: [NEITHER] }, - { code: '{} do {}while(true)', options: [override('do', BOTH)] }, - { code: '{}do{} while (true)', options: [override('do', NEITHER)] }, - '{}\ndo\n{} while (true)', - { code: '{}\ndo\n{}while(true)', options: [NEITHER] }, - - // not conflict with `block-spacing` - '{do {} while (true)}', - { code: '{ do{}while(true) }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';do; while (true)', - { code: '; do ;while(true)', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // else - //---------------------------------------------------------------------- - - 'if (a) {} else {}', - 'if (a) {} else if (b) {}', - 'if (a) {} else (0)', - 'if (a) {} else []', - 'if (a) {} else +1', - 'if (a) {} else "a"', - { code: 'if(a){}else{}', options: [NEITHER] }, - { code: 'if(a){}else if(b) {}', options: [NEITHER] }, - { code: 'if(a) {}else(0)', options: [NEITHER] }, - { code: 'if(a) {}else[]', options: [NEITHER] }, - { code: 'if(a) {}else+1', options: [NEITHER] }, - { code: 'if(a) {}else"a"', options: [NEITHER] }, - { code: 'if(a) {} else {}', options: [override('else', BOTH)] }, - { code: 'if (a) {}else{}', options: [override('else', NEITHER)] }, - 'if (a) {}\nelse\n{}', - { code: 'if(a) {}\nelse\n{}', options: [NEITHER] }, - { - code: 'if(a){ }else{ }', - options: [ - { - before: false, - after: true, - overrides: { else: { after: false }, if: { after: false } }, - }, - ], - }, - { - code: 'if(a){ }else{ }', - options: [ - { - before: true, - after: false, - overrides: { else: { before: false }, if: { before: false } }, - }, - ], - }, - - // not conflict with `semi-spacing` - 'if (a);else;', - { code: 'if(a); else ;', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // export - //---------------------------------------------------------------------- - - { - code: 'var a = 0; {} export {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} export default a', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} export * from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'var a = 0; {}export{a}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'var a = 0; {} export {a}', - options: [override('export', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'var a = 0; {}export{a}', - options: [override('export', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - - // not conflict with `semi-spacing` - { - code: 'var a = 0;\n;export {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'var a = 0;\n; export{a}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - - //---------------------------------------------------------------------- - // extends - //---------------------------------------------------------------------- - - { code: 'class Bar extends [] {}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'class Bar extends[] {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class Bar extends [] {}', - options: [override('extends', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class Bar extends[] {}', - options: [override('extends', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // finally - //---------------------------------------------------------------------- - - 'try {} finally {}', - { code: 'try{}finally{}', options: [NEITHER] }, - { code: 'try{} finally {}', options: [override('finally', BOTH)] }, - { code: 'try {}finally{}', options: [override('finally', NEITHER)] }, - 'try {}\nfinally\n{}', - { code: 'try{}\nfinally\n{}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // for - //---------------------------------------------------------------------- - - '{} for (;;) {}', - '{} for (var foo in obj) {}', - { code: '{} for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, - { code: '{}for(;;) {}', options: [NEITHER] }, - { code: '{}for(var foo in obj) {}', options: [NEITHER] }, - { - code: '{}for(var foo of list) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { code: '{} for (;;) {}', options: [override('for', BOTH)] }, - { code: '{} for (var foo in obj) {}', options: [override('for', BOTH)] }, - { - code: '{} for (var foo of list) {}', - options: [override('for', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { code: '{}for(;;) {}', options: [override('for', NEITHER)] }, - { code: '{}for(var foo in obj) {}', options: [override('for', NEITHER)] }, - { - code: '{}for(var foo of list) {}', - options: [override('for', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{for (;;) {} }', - '{for (var foo in obj) {} }', - { code: '{for (var foo of list) {} }', parserOptions: { ecmaVersion: 6 } }, - { code: '{ for(;;) {} }', options: [NEITHER] }, - { code: '{ for(var foo in obj) {} }', options: [NEITHER] }, - { - code: '{ for(var foo of list) {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - ';for (;;) {}', - ';for (var foo in obj) {}', - { code: ';for (var foo of list) {}', parserOptions: { ecmaVersion: 6 } }, - { code: '; for(;;) {}', options: [NEITHER] }, - { code: '; for(var foo in obj) {}', options: [NEITHER] }, - { - code: '; for(var foo of list) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // from - //---------------------------------------------------------------------- - - { - code: 'import {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export * from "foo"', parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export*from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export* from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'import {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: 'export *from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - - //---------------------------------------------------------------------- - // function - //---------------------------------------------------------------------- - - '{} function foo() {}', - { code: '{}function foo() {}', options: [NEITHER] }, - { code: '{} function foo() {}', options: [override('function', BOTH)] }, - { code: '{}function foo() {}', options: [override('function', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[function() {}]', - { code: '[ function() {}]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>function() {})', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => function() {})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{function foo() {} }', - { code: '{ function foo() {} }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,function() {})', - { code: '(0, function() {})', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[function() {}]', - { code: '({[function() {}]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ function() {}]', options: [NEITHER] }, - { - code: '({[ function(){}]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `generator-star-spacing` - { code: 'function* foo() {}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function *foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:function() {} })', - { code: '({a: function() {} })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';function foo() {};', - { code: '; function foo() {} ;', options: [NEITHER] }, - - /* - * not conflict with `space-before-function-paren` - * not conflict with `space-in-parens` - */ - '(function() {})', - { code: '( function () {})', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =function() {}', - { code: 'a = function() {}', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!function() {}', - { code: '! function() {}', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${function() {}}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ function() {}}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // get - //---------------------------------------------------------------------- - - { code: '({ get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, - { - code: 'class A { a() {} get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {} static get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ get[b]() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}static get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ get [b]() {} })', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {} get [b]() {} }', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ get[b]() {} })', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}get[b]() {} }', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `comma-spacing` - { code: '({ a,get [b]() {} })', parserOptions: { ecmaVersion: 6 } }, - { - code: '({ a, get[b]() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // if - //---------------------------------------------------------------------- - - '{} if (a) {}', - 'if (a) {} else if (a) {}', - { code: '{}if(a) {}', options: [NEITHER] }, - { code: 'if(a) {}else if(a) {}', options: [NEITHER] }, - { code: '{} if (a) {}', options: [override('if', BOTH)] }, - { code: 'if (a) {}else if (a) {}', options: [override('if', BOTH)] }, - { code: '{}if(a) {}', options: [override('if', NEITHER)] }, - { code: 'if(a) {} else if(a) {}', options: [override('if', NEITHER)] }, - - // not conflict with `block-spacing` - '{if (a) {} }', - { code: '{ if(a) {} }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';if (a) {}', - { code: '; if(a) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // import - //---------------------------------------------------------------------- - - { - code: '{} import {a} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} import a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} import * as a from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{}import{a}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{}import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} import {a}from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{} import *as a from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{}import{a} from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '{}import* as a from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - - // not conflict with `semi-spacing` - { - code: ';import {a} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - { - code: '; import{a}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - }, - - //---------------------------------------------------------------------- - // in - //---------------------------------------------------------------------- - - { code: 'for ([foo] in {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'for([foo]in{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'for([foo] in {foo: 0}) {}', - options: [override('in', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'for ([foo]in{foo: 0}) {}', - options: [override('in', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - { code: 'for ([foo] in ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, - - // not conflict with `space-infix-ops` - 'if ("foo"in{foo: 0}) {}', - { code: 'if("foo" in {foo: 0}) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // instanceof - //---------------------------------------------------------------------- - - // not conflict with `space-infix-ops` - 'if ("foo"instanceof{foo: 0}) {}', - { code: 'if("foo" instanceof {foo: 0}) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // let - //---------------------------------------------------------------------- - - { code: '{} let [a] = b', parserOptions: { ecmaVersion: 6 } }, - { - code: '{}let[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{} let [a] = b', - options: [override('let', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}let[a] = b', - options: [override('let', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - { code: '{let [a] = b }', parserOptions: { ecmaVersion: 6 } }, - { - code: '{ let[a] = b }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { code: ';let [a] = b', parserOptions: { ecmaVersion: 6 } }, - { - code: '; let[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // new - //---------------------------------------------------------------------- - - '{} new foo()', - { code: '{}new foo()', options: [NEITHER] }, - { code: '{} new foo()', options: [override('new', BOTH)] }, - { code: '{}new foo()', options: [override('new', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[new foo()]', - { code: '[ new foo()]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>new foo())', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => new foo())', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{new foo() }', - { code: '{ new foo() }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,new foo())', - { code: '(0, new foo())', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[new foo()]', - { code: '({[new foo()]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ new foo()]', options: [NEITHER] }, - { - code: '({[ new foo()]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:new foo() })', - { code: '({a: new foo() })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';new foo()', - { code: '; new foo()', options: [NEITHER] }, - - // not conflict with `space-in-parens` - '(new foo())', - { code: '( new foo())', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =new foo()', - { code: 'a = new foo()', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!new(foo)()', - { code: '! new (foo)()', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${new foo()}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ new foo()}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // of - //---------------------------------------------------------------------- - - { code: 'for ([foo] of {foo: 0}) {}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'for([foo]of{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'for([foo] of {foo: 0}) {}', - options: [override('of', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'for ([foo]of{foo: 0}) {}', - options: [override('of', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - { code: 'for ([foo] of ({foo: 0})) {}', parserOptions: { ecmaVersion: 6 } }, - - //---------------------------------------------------------------------- - // return - //---------------------------------------------------------------------- - - 'function foo() { {} return +a }', - { code: 'function foo() { {}return+a }', options: [NEITHER] }, - { - code: 'function foo() { {} return +a }', - options: [override('return', BOTH)], - }, - { - code: 'function foo() { {}return+a }', - options: [override('return', NEITHER)], - }, - 'function foo() {\nreturn\n}', - { code: 'function foo() {\nreturn\n}', options: [NEITHER] }, - - // not conflict with `block-spacing` - 'function foo() {return}', - { code: 'function foo() { return }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'function foo() { ;return; }', - { code: 'function foo() { ; return ; }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // set - //---------------------------------------------------------------------- - - { code: '({ set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, - { - code: 'class A { a() {} set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {} static set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ set[b](value) {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}set[b](value) {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ set [b](value) {} })', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {} set [b](value) {} }', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '({ set[b](value) {} })', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}set[b](value) {} }', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `comma-spacing` - { code: '({ a,set [b](value) {} })', parserOptions: { ecmaVersion: 6 } }, - { - code: '({ a, set[b](value) {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // static - //---------------------------------------------------------------------- - - { - code: 'class A { a() {} static [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}static[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {} static [b]() {} }', - options: [override('static', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A { a() {}static[b]() {} }', - options: [override('static', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `generator-star-spacing` - { code: 'class A { static* [a]() {} }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'class A { static *[a]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { code: 'class A { ;static a() {} }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'class A { ; static a() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - //---------------------------------------------------------------------- - // super - //---------------------------------------------------------------------- - - { - code: 'class A extends B { a() { {} super[b](); } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { a() { {}super[b](); } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { a() { {} super[b](); } }', - options: [override('super', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { a() { {}super[b](); } }', - options: [override('super', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `array-bracket-spacing` - { - code: 'class A extends B { constructor() { [super()]; } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { [ super() ]; } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `arrow-spacing` - { - code: 'class A extends B { constructor() { () =>super(); } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { () => super(); } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - { - code: 'class A extends B { constructor() {super()} }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { super() } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `comma-spacing` - { - code: 'class A extends B { constructor() { (0,super()) } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { (0, super()) } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `computed-property-spacing` - { - code: 'class A extends B { constructor() { ({[super()]: 0}) } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { ({[ super() ]: 0}) } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - { - code: 'class A extends B { constructor() { ({a:super() }) } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { ({a: super() }) } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `func-call-spacing` - { - code: 'class A extends B { constructor() { super(); } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { super (); } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { - code: 'class A extends B { constructor() { ;super(); } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { ; super() ; } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-in-parens` - { - code: 'class A extends B { constructor() { (super()) } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { ( super() ) } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-infix-ops` - { - code: 'class A extends B { constructor() { b =super() } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { b = super() } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-unary-ops` - { - code: 'class A extends B { constructor() { !super() } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { ! super() } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `template-curly-spacing` - { - code: 'class A extends B { constructor() { `${super()}` } }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'class A extends B { constructor() { `${ super() }` } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: 'class A extends B { constructor() { } }', - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: - 'class A extends B { constructor() { } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // switch - //---------------------------------------------------------------------- - - '{} switch (a) {}', - { code: '{}switch(a) {}', options: [NEITHER] }, - { code: '{} switch (a) {}', options: [override('switch', BOTH)] }, - { code: '{}switch(a) {}', options: [override('switch', NEITHER)] }, - - // not conflict with `block-spacing` - '{switch (a) {} }', - { code: '{ switch(a) {} }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';switch (a) {}', - { code: '; switch(a) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // this - //---------------------------------------------------------------------- - - '{} this[a]', - { code: '{}this[a]', options: [NEITHER] }, - { code: '{} this[a]', options: [override('this', BOTH)] }, - { code: '{}this[a]', options: [override('this', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[this]', - { code: '[ this ]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>this)', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => this)', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{this}', - { code: '{ this }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,this)', - { code: '(0, this)', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[this]', - { code: '({[this]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ this ]', options: [NEITHER] }, - { - code: '({[ this ]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:this })', - { code: '({a: this })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';this', - { code: '; this', options: [NEITHER] }, - - // not conflict with `space-in-parens` - '(this)', - { code: '( this )', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =this', - { code: 'a = this', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!this', - { code: '! this', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${this}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ this }`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // throw - //---------------------------------------------------------------------- - - 'function foo() { {} throw +a }', - { code: 'function foo() { {}throw+a }', options: [NEITHER] }, - { - code: 'function foo() { {} throw +a }', - options: [override('throw', BOTH)], - }, - { - code: 'function foo() { {}throw+a }', - options: [override('throw', NEITHER)], - }, - 'function foo() {\nthrow a\n}', - { code: 'function foo() {\nthrow a\n}', options: [NEITHER] }, - - // not conflict with `block-spacing` - 'function foo() {throw a }', - { code: 'function foo() { throw a }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - 'function foo() { ;throw a }', - { code: 'function foo() { ; throw a }', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // try - //---------------------------------------------------------------------- - - '{} try {} finally {}', - { code: '{}try{}finally{}', options: [NEITHER] }, - { code: '{} try {}finally{}', options: [override('try', BOTH)] }, - { code: '{}try{} finally {}', options: [override('try', NEITHER)] }, - - // not conflict with `block-spacing` - '{try {} finally {}}', - { code: '{ try{}finally{}}', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';try {} finally {}', - { code: '; try{}finally{}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // typeof - //---------------------------------------------------------------------- - - '{} typeof foo', - { code: '{}typeof foo', options: [NEITHER] }, - { code: '{} typeof foo', options: [override('typeof', BOTH)] }, - { code: '{}typeof foo', options: [override('typeof', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[typeof foo]', - { code: '[ typeof foo]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>typeof foo)', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => typeof foo)', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{typeof foo }', - { code: '{ typeof foo }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,typeof foo)', - { code: '(0, typeof foo)', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[typeof foo]', - { code: '({[typeof foo]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ typeof foo]', options: [NEITHER] }, - { - code: '({[ typeof foo]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:typeof foo })', - { code: '({a: typeof foo })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';typeof foo', - { code: '; typeof foo', options: [NEITHER] }, - - // not conflict with `space-in-parens` - '(typeof foo)', - { code: '( typeof foo)', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =typeof foo', - { code: 'a = typeof foo', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!typeof+foo', - { code: '! typeof +foo', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${typeof foo}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ typeof foo}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // var - //---------------------------------------------------------------------- - - { code: '{} var [a] = b', parserOptions: { ecmaVersion: 6 } }, - { - code: '{}var[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{} var [a] = b', - options: [override('var', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '{}var[a] = b', - options: [override('var', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - 'for (var foo in [1, 2, 3]) {}', - - // not conflict with `block-spacing` - '{var a = b }', - { code: '{ var a = b }', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';var a = b', - { code: '; var a = b', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // void - //---------------------------------------------------------------------- - - '{} void foo', - { code: '{}void foo', options: [NEITHER] }, - { code: '{} void foo', options: [override('void', BOTH)] }, - { code: '{}void foo', options: [override('void', NEITHER)] }, - - // not conflict with `array-bracket-spacing` - '[void foo]', - { code: '[ void foo]', options: [NEITHER] }, - - // not conflict with `arrow-spacing` - { code: '(() =>void foo)', parserOptions: { ecmaVersion: 6 } }, - { - code: '(() => void foo)', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `block-spacing` - '{void foo }', - { code: '{ void foo }', options: [NEITHER] }, - - // not conflict with `comma-spacing` - '(0,void foo)', - { code: '(0, void foo)', options: [NEITHER] }, - - // not conflict with `computed-property-spacing` - 'a[void foo]', - { code: '({[void foo]: 0})', parserOptions: { ecmaVersion: 6 } }, - { code: 'a[ void foo]', options: [NEITHER] }, - { - code: '({[ void foo]: 0})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - '({a:void foo })', - { code: '({a: void foo })', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';void foo', - { code: '; void foo', options: [NEITHER] }, - - // not conflict with `space-in-parens` - '(void foo)', - { code: '( void foo)', options: [NEITHER] }, - - // not conflict with `space-infix-ops` - 'a =void foo', - { code: 'a = void foo', options: [NEITHER] }, - - // not conflict with `space-unary-ops` - '!void+foo', - { code: '! void +foo', options: [NEITHER] }, - - // not conflict with `template-curly-spacing` - { code: '`${void foo}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ void foo}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: '', - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - { - code: '', - options: [NEITHER], - parserOptions: { ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // while - //---------------------------------------------------------------------- - - '{} while (a) {}', - 'do {} while (a)', - { code: '{}while(a) {}', options: [NEITHER] }, - { code: 'do{}while(a)', options: [NEITHER] }, - { code: '{} while (a) {}', options: [override('while', BOTH)] }, - { code: 'do{} while (a)', options: [override('while', BOTH)] }, - { code: '{}while(a) {}', options: [override('while', NEITHER)] }, - { code: 'do {}while(a)', options: [override('while', NEITHER)] }, - 'do {}\nwhile (a)', - { code: 'do{}\nwhile(a)', options: [NEITHER] }, - - // not conflict with `block-spacing` - '{while (a) {}}', - { code: '{ while(a) {}}', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';while (a);', - 'do;while (a);', - { code: '; while(a) ;', options: [NEITHER] }, - { code: 'do ; while(a) ;', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // with - //---------------------------------------------------------------------- - - '{} with (obj) {}', - { code: '{}with(obj) {}', options: [NEITHER] }, - { code: '{} with (obj) {}', options: [override('with', BOTH)] }, - { code: '{}with(obj) {}', options: [override('with', NEITHER)] }, - - // not conflict with `block-spacing` - '{with (obj) {}}', - { code: '{ with(obj) {}}', options: [NEITHER] }, - - // not conflict with `semi-spacing` - ';with (obj) {}', - { code: '; with(obj) {}', options: [NEITHER] }, - - //---------------------------------------------------------------------- - // yield - //---------------------------------------------------------------------- - - { - code: 'function* foo() { {} yield foo }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { {}yield foo }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { {} yield foo }', - options: [override('yield', BOTH)], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { {}yield foo }', - options: [override('yield', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `array-bracket-spacing` - { code: 'function* foo() { [yield] }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function* foo() { [ yield ] }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - /* - * This is invalid syntax: https://github.com/eslint/eslint/issues/5405 - * not conflict with `arrow-spacing` - * {code: 'function* foo() { (() =>yield foo) }', parserOptions: {ecmaVersion: 6}}, - * {code: 'function* foo() { (() => yield foo) }', options: [NEITHER], parserOptions: {ecmaVersion: 6}}, - * not conflict with `block-spacing` - */ - { code: 'function* foo() {yield}', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function* foo() { yield }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `comma-spacing` - { - code: 'function* foo() { (0,yield foo) }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { (0, yield foo) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `computed-property-spacing` - { code: 'function* foo() { a[yield] }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function* foo() { ({[yield]: 0}) }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { a[ yield ] }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { ({[ yield ]: 0}) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `key-spacing` - { - code: 'function* foo() { ({a:yield foo }) }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { ({a: yield foo }) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `semi-spacing` - { code: 'function* foo() { ;yield; }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function* foo() { ; yield ; }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-in-parens` - { code: 'function* foo() { (yield) }', parserOptions: { ecmaVersion: 6 } }, - { - code: 'function* foo() { ( yield ) }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-infix-ops` - { - code: 'function* foo() { a =yield foo }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { a = yield foo }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `space-unary-ops` - { - code: 'function* foo() { yield+foo }', - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'function* foo() { yield +foo }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `template-curly-spacing` - { code: '`${yield}`', parserOptions: { ecmaVersion: 6 } }, - { - code: '`${ yield}`', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - }, - - // not conflict with `jsx-curly-spacing` - { - code: 'function* foo() { }', - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: 'function* foo() { }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - - //---------------------------------------------------------------------- - // typescript parser - //---------------------------------------------------------------------- - - // // class declaration don't error with decorator - '@dec class Foo {}', - - // get, set, async methods don't error with decorator - 'class Foo { @dec get bar() {} @dec set baz() {} @dec async baw() {} }', - 'class Foo { @dec static qux() {} @dec static get bar() {} @dec static set baz() {} @dec static async baw() {} }', - - // type keywords can be used as parameters in arrow functions - 'symbol => 4;', - ] as TSESLint.ValidTestCase[], - - invalid: [ - //---------------------------------------------------------------------- - // as (import) - //---------------------------------------------------------------------- - - { - code: 'import *as a from "foo"', - output: 'import * as a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as'), - }, - { - code: 'import* as a from"foo"', - output: 'import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as'), - }, - { - code: 'import*as a from"foo"', - output: 'import* as a from"foo"', - options: [override('as', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as'), - }, - { - code: 'import * as a from "foo"', - output: 'import *as a from "foo"', - options: [override('as', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as'), - }, - - //---------------------------------------------------------------------- - // as (typing) - //---------------------------------------------------------------------- - - { - code: 'const foo = {}as {}', - output: 'const foo = {} as {}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('as'), - }, - { - code: 'const foo = {} as{}', - output: 'const foo = {}as{}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBefore('as'), - }, - - //---------------------------------------------------------------------- - // async - //---------------------------------------------------------------------- - - { - code: '{}async function foo() {}', - output: '{} async function foo() {}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async'), - }, - { - code: '{} async function foo() {}', - output: '{}async function foo() {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async'), - }, - { - code: '{}async function foo() {}', - output: '{} async function foo() {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async'), - }, - { - code: '{} async function foo() {}', - output: '{}async function foo() {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async'), - }, - { - code: '{}async () => {}', - output: '{} async () => {}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async'), - }, - { - code: '{} async () => {}', - output: '{}async () => {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async'), - }, - { - code: '{}async () => {}', - output: '{} async () => {}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('async'), - }, - { - code: '{} async () => {}', - output: '{}async () => {}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('async'), - }, - { - code: '({async[b]() {}})', - output: '({async [b]() {}})', - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter('async'), - }, - { - code: '({async [b]() {}})', - output: '({async[b]() {}})', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter('async'), - }, - { - code: '({async[b]() {}})', - output: '({async [b]() {}})', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter('async'), - }, - { - code: '({async [b]() {}})', - output: '({async[b]() {}})', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter('async'), - }, - { - code: 'class A {a(){}async[b]() {}}', - output: 'class A {a(){} async [b]() {}}', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter('async'), - }, - { - code: 'class A {a(){} async [b]() {}}', - output: 'class A {a(){}async[b]() {}}', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter('async'), - }, - { - code: 'class A {a(){}async[b]() {}}', - output: 'class A {a(){} async [b]() {}}', - options: [override('async', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter('async'), - }, - { - code: 'class A {a(){} async [b]() {}}', - output: 'class A {a(){}async[b]() {}}', - options: [override('async', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter('async'), - }, - - //---------------------------------------------------------------------- - // await - //---------------------------------------------------------------------- - - { - code: 'async function wrap() { {}await a }', - output: 'async function wrap() { {} await a }', - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('await'), - }, - { - code: 'async function wrap() { {} await a }', - output: 'async function wrap() { {}await a }', - options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('await'), - }, - { - code: 'async function wrap() { {}await a }', - output: 'async function wrap() { {} await a }', - options: [override('await', BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore('await'), - }, - { - code: 'async function wrap() { {} await a }', - output: 'async function wrap() { {}await a }', - options: [override('await', NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore('await'), - }, - - { - code: 'async function wrap() { for await(x of xs); }', - output: 'async function wrap() { for await (x of xs); }', - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter('await'), - }, - { - code: 'async function wrap() { for await (x of xs); }', - output: 'async function wrap() { for await(x of xs); }', - options: [NEITHER], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter('await'), - }, - { - code: 'async function wrap() { for await(x of xs); }', - output: 'async function wrap() { for await (x of xs); }', - options: [override('await', BOTH)], - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter('await'), - }, - { - code: 'async function wrap() { for await (x of xs); }', - output: 'async function wrap() { for await(x of xs); }', - options: [override('await', NEITHER)], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter('await'), - }, - - //---------------------------------------------------------------------- - // break - //---------------------------------------------------------------------- - - { - code: 'A: for (;;) { {}break A; }', - output: 'A: for (;;) { {} break A; }', - errors: expectedBefore('break'), - }, - { - code: 'A: for(;;) { {} break A; }', - output: 'A: for(;;) { {}break A; }', - options: [NEITHER], - errors: unexpectedBefore('break'), - }, - { - code: 'A: for(;;) { {}break A; }', - output: 'A: for(;;) { {} break A; }', - options: [override('break', BOTH)], - errors: expectedBefore('break'), - }, - { - code: 'A: for (;;) { {} break A; }', - output: 'A: for (;;) { {}break A; }', - options: [override('break', NEITHER)], - errors: unexpectedBefore('break'), - }, - - //---------------------------------------------------------------------- - // case - //---------------------------------------------------------------------- - - { - code: 'switch (a) { case 0: {}case+1: }', - output: 'switch (a) { case 0: {} case +1: }', - errors: expectedBeforeAndAfter('case'), - }, - { - code: 'switch (a) { case 0: {}case(1): }', - output: 'switch (a) { case 0: {} case (1): }', - errors: expectedBeforeAndAfter('case'), - }, - { - code: 'switch(a) { case 0: {} case +1: }', - output: 'switch(a) { case 0: {}case+1: }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('case'), - }, - { - code: 'switch(a) { case 0: {} case (1): }', - output: 'switch(a) { case 0: {}case(1): }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('case'), - }, - { - code: 'switch(a) { case 0: {}case+1: }', - output: 'switch(a) { case 0: {} case +1: }', - options: [override('case', BOTH)], - errors: expectedBeforeAndAfter('case'), - }, - { - code: 'switch (a) { case 0: {} case +1: }', - output: 'switch (a) { case 0: {}case+1: }', - options: [override('case', NEITHER)], - errors: unexpectedBeforeAndAfter('case'), - }, - - //---------------------------------------------------------------------- - // catch - //---------------------------------------------------------------------- - - { - code: 'try {}catch(e) {}', - output: 'try {} catch (e) {}', - errors: expectedBeforeAndAfter('catch'), - }, - { - code: 'try{} catch (e) {}', - output: 'try{}catch(e) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('catch'), - }, - { - code: 'try{}catch(e) {}', - output: 'try{} catch (e) {}', - options: [override('catch', BOTH)], - errors: expectedBeforeAndAfter('catch'), - }, - { - code: 'try {} catch (e) {}', - output: 'try {}catch(e) {}', - options: [override('catch', NEITHER)], - errors: unexpectedBeforeAndAfter('catch'), - }, - - //---------------------------------------------------------------------- - // class - //---------------------------------------------------------------------- - - { - code: '{}class Bar {}', - output: '{} class Bar {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('class'), - }, - { - code: '(class{})', - output: '(class {})', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('class'), - }, - { - code: '{} class Bar {}', - output: '{}class Bar {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('class'), - }, - { - code: '(class {})', - output: '(class{})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('class'), - }, - { - code: '{}class Bar {}', - output: '{} class Bar {}', - options: [override('class', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('class'), - }, - { - code: '{} class Bar {}', - output: '{}class Bar {}', - options: [override('class', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('class'), - }, - - //---------------------------------------------------------------------- - // const - //---------------------------------------------------------------------- - - { - code: '{}const[a] = b', - output: '{} const [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const'), - }, - { - code: '{}const{a} = b', - output: '{} const {a} = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const'), - }, - { - code: '{} const [a] = b', - output: '{}const[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const'), - }, - { - code: '{} const {a} = b', - output: '{}const{a} = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const'), - }, - { - code: '{}const[a] = b', - output: '{} const [a] = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const'), - }, - { - code: '{}const{a} = b', - output: '{} const {a} = b', - options: [override('const', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('const'), - }, - { - code: '{} const [a] = b', - output: '{}const[a] = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const'), - }, - { - code: '{} const {a} = b', - output: '{}const{a} = b', - options: [override('const', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('const'), - }, - - //---------------------------------------------------------------------- - // continue - //---------------------------------------------------------------------- - - { - code: 'A: for (;;) { {}continue A; }', - output: 'A: for (;;) { {} continue A; }', - errors: expectedBefore('continue'), - }, - { - code: 'A: for(;;) { {} continue A; }', - output: 'A: for(;;) { {}continue A; }', - options: [NEITHER], - errors: unexpectedBefore('continue'), - }, - { - code: 'A: for(;;) { {}continue A; }', - output: 'A: for(;;) { {} continue A; }', - options: [override('continue', BOTH)], - errors: expectedBefore('continue'), - }, - { - code: 'A: for (;;) { {} continue A; }', - output: 'A: for (;;) { {}continue A; }', - options: [override('continue', NEITHER)], - errors: unexpectedBefore('continue'), - }, - - //---------------------------------------------------------------------- - // debugger - //---------------------------------------------------------------------- - - { - code: '{}debugger', - output: '{} debugger', - errors: expectedBefore('debugger'), - }, - { - code: '{} debugger', - output: '{}debugger', - options: [NEITHER], - errors: unexpectedBefore('debugger'), - }, - { - code: '{}debugger', - output: '{} debugger', - options: [override('debugger', BOTH)], - errors: expectedBefore('debugger'), - }, - { - code: '{} debugger', - output: '{}debugger', - options: [override('debugger', NEITHER)], - errors: unexpectedBefore('debugger'), - }, - - //---------------------------------------------------------------------- - // default - //---------------------------------------------------------------------- - - { - code: 'switch (a) { case 0: {}default: }', - output: 'switch (a) { case 0: {} default: }', - errors: expectedBefore('default'), - }, - { - code: 'switch(a) { case 0: {} default: }', - output: 'switch(a) { case 0: {}default: }', - options: [NEITHER], - errors: unexpectedBefore('default'), - }, - { - code: 'switch(a) { case 0: {}default: }', - output: 'switch(a) { case 0: {} default: }', - options: [override('default', BOTH)], - errors: expectedBefore('default'), - }, - { - code: 'switch (a) { case 0: {} default: }', - output: 'switch (a) { case 0: {}default: }', - options: [override('default', NEITHER)], - errors: unexpectedBefore('default'), - }, - - //---------------------------------------------------------------------- - // delete - //---------------------------------------------------------------------- - - { - code: '{}delete foo.a', - output: '{} delete foo.a', - errors: expectedBefore('delete'), - }, - { - code: '{} delete foo.a', - output: '{}delete foo.a', - options: [NEITHER], - errors: unexpectedBefore('delete'), - }, - { - code: '{}delete foo.a', - output: '{} delete foo.a', - options: [override('delete', BOTH)], - errors: expectedBefore('delete'), - }, - { - code: '{} delete foo.a', - output: '{}delete foo.a', - options: [override('delete', NEITHER)], - errors: unexpectedBefore('delete'), - }, - - //---------------------------------------------------------------------- - // do - //---------------------------------------------------------------------- - - { - code: '{}do{} while (true)', - output: '{} do {} while (true)', - errors: expectedBeforeAndAfter('do'), - }, - { - code: '{} do {}while(true)', - output: '{}do{}while(true)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('do'), - }, - { - code: '{}do{}while(true)', - output: '{} do {}while(true)', - options: [override('do', BOTH)], - errors: expectedBeforeAndAfter('do'), - }, - { - code: '{} do {} while (true)', - output: '{}do{} while (true)', - options: [override('do', NEITHER)], - errors: unexpectedBeforeAndAfter('do'), - }, - - //---------------------------------------------------------------------- - // else - //---------------------------------------------------------------------- - - { - code: 'if (a) {}else{}', - output: 'if (a) {} else {}', - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if (a) {}else if (b) {}', - output: 'if (a) {} else if (b) {}', - errors: expectedBefore('else'), - }, - { - code: 'if (a) {}else(0)', - output: 'if (a) {} else (0)', - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if (a) {}else[]', - output: 'if (a) {} else []', - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if (a) {}else+1', - output: 'if (a) {} else +1', - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if (a) {}else"a"', - output: 'if (a) {} else "a"', - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if(a){} else {}', - output: 'if(a){}else{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else'), - }, - { - code: 'if(a){} else if(b) {}', - output: 'if(a){}else if(b) {}', - options: [NEITHER], - errors: unexpectedBefore('else'), - }, - { - code: 'if(a) {} else (0)', - output: 'if(a) {}else(0)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else'), - }, - { - code: 'if(a) {} else []', - output: 'if(a) {}else[]', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else'), - }, - { - code: 'if(a) {} else +1', - output: 'if(a) {}else+1', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else'), - }, - { - code: 'if(a) {} else "a"', - output: 'if(a) {}else"a"', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('else'), - }, - { - code: 'if(a) {}else{}', - output: 'if(a) {} else {}', - options: [override('else', BOTH)], - errors: expectedBeforeAndAfter('else'), - }, - { - code: 'if (a) {} else {}', - output: 'if (a) {}else{}', - options: [override('else', NEITHER)], - errors: unexpectedBeforeAndAfter('else'), - }, - - { - code: 'if (a) {}else {}', - output: 'if (a) {} else {}', - errors: expectedBefore('else'), - }, - { - code: 'if (a) {} else{}', - output: 'if (a) {} else {}', - errors: expectedAfter('else'), - }, - { - code: 'if(a) {} else{}', - output: 'if(a) {}else{}', - options: [NEITHER], - errors: unexpectedBefore('else'), - }, - { - code: 'if(a) {}else {}', - output: 'if(a) {}else{}', - options: [NEITHER], - errors: unexpectedAfter('else'), - }, - - //---------------------------------------------------------------------- - // export - //---------------------------------------------------------------------- - - { - code: 'var a = 0; {}export{a}', - output: 'var a = 0; {} export {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export'), - }, - { - code: 'var a = 0; {}export default a', - output: 'var a = 0; {} export default a', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('export'), - }, - { - code: 'var a = 0; export default{a}', - output: 'var a = 0; export default {a}', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedAfter('default'), - }, - { - code: '{}export* from "a"', - output: '{} export * from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export'), - }, - { - code: 'var a = 0; {} export {a}', - output: 'var a = 0; {}export{a}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('export'), - }, - { - code: 'var a = 0; {}export{a}', - output: 'var a = 0; {} export {a}', - options: [override('export', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('export'), - }, - { - code: 'var a = 0; {} export {a}', - output: 'var a = 0; {}export{a}', - options: [override('export', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('export'), - }, - - //---------------------------------------------------------------------- - // extends - //---------------------------------------------------------------------- - - { - code: 'class Bar extends[] {}', - output: 'class Bar extends [] {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends'), - }, - { - code: '(class extends[] {})', - output: '(class extends [] {})', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends'), - }, - { - code: 'class Bar extends [] {}', - output: 'class Bar extends[] {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends'), - }, - { - code: '(class extends [] {})', - output: '(class extends[] {})', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends'), - }, - { - code: 'class Bar extends[] {}', - output: 'class Bar extends [] {}', - options: [override('extends', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends'), - }, - { - code: 'class Bar extends [] {}', - output: 'class Bar extends[] {}', - options: [override('extends', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('extends'), - }, - { - code: 'class Bar extends`}` {}', - output: 'class Bar extends `}` {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('extends'), - }, - - //---------------------------------------------------------------------- - // finally - //---------------------------------------------------------------------- - - { - code: 'try {}finally{}', - output: 'try {} finally {}', - errors: expectedBeforeAndAfter('finally'), - }, - { - code: 'try{} finally {}', - output: 'try{}finally{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('finally'), - }, - { - code: 'try{}finally{}', - output: 'try{} finally {}', - options: [override('finally', BOTH)], - errors: expectedBeforeAndAfter('finally'), - }, - { - code: 'try {} finally {}', - output: 'try {}finally{}', - options: [override('finally', NEITHER)], - errors: unexpectedBeforeAndAfter('finally'), - }, - - //---------------------------------------------------------------------- - // for - //---------------------------------------------------------------------- - - { - code: '{}for(;;) {}', - output: '{} for (;;) {}', - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{}for(var foo in obj) {}', - output: '{} for (var foo in obj) {}', - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{}for(var foo of list) {}', - output: '{} for (var foo of list) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{} for (;;) {}', - output: '{}for(;;) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('for'), - }, - { - code: '{} for (var foo in obj) {}', - output: '{}for(var foo in obj) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('for'), - }, - { - code: '{} for (var foo of list) {}', - output: '{}for(var foo of list) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('for'), - }, - { - code: '{}for(;;) {}', - output: '{} for (;;) {}', - options: [override('for', BOTH)], - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{}for(var foo in obj) {}', - output: '{} for (var foo in obj) {}', - options: [override('for', BOTH)], - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{}for(var foo of list) {}', - output: '{} for (var foo of list) {}', - options: [override('for', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('for'), - }, - { - code: '{} for (;;) {}', - output: '{}for(;;) {}', - options: [override('for', NEITHER)], - errors: unexpectedBeforeAndAfter('for'), - }, - { - code: '{} for (var foo in obj) {}', - output: '{}for(var foo in obj) {}', - options: [override('for', NEITHER)], - errors: unexpectedBeforeAndAfter('for'), - }, - { - code: '{} for (var foo of list) {}', - output: '{}for(var foo of list) {}', - options: [override('for', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('for'), - }, - - //---------------------------------------------------------------------- - // from - //---------------------------------------------------------------------- - - { - code: 'import {foo}from"foo"', - output: 'import {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'export {foo}from"foo"', - output: 'export {foo} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'export *from"foo"', - output: 'export * from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'import{foo} from "foo"', - output: 'import{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - { - code: 'export{foo} from "foo"', - output: 'export{foo}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - { - code: 'export* from "foo"', - output: 'export*from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - { - code: 'import{foo}from"foo"', - output: 'import{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'export{foo}from"foo"', - output: 'export{foo} from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'export*from"foo"', - output: 'export* from "foo"', - options: [override('from', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('from'), - }, - { - code: 'import {foo} from "foo"', - output: 'import {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - { - code: 'export {foo} from "foo"', - output: 'export {foo}from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - { - code: 'export * from "foo"', - output: 'export *from"foo"', - options: [override('from', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('from'), - }, - - //---------------------------------------------------------------------- - // function - //---------------------------------------------------------------------- - - { - code: '{}function foo() {}', - output: '{} function foo() {}', - errors: expectedBefore('function'), - }, - { - code: '{} function foo() {}', - output: '{}function foo() {}', - options: [NEITHER], - errors: unexpectedBefore('function'), - }, - { - code: '{}function foo() {}', - output: '{} function foo() {}', - options: [override('function', BOTH)], - errors: expectedBefore('function'), - }, - { - code: '{} function foo() {}', - output: '{}function foo() {}', - options: [override('function', NEITHER)], - errors: unexpectedBefore('function'), - }, - - //---------------------------------------------------------------------- - // get - //---------------------------------------------------------------------- - - { - code: '({ get[b]() {} })', - output: '({ get [b]() {} })', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get'), - }, - { - code: 'class A { a() {}get[b]() {} }', - output: 'class A { a() {} get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('get'), - }, - { - code: 'class A { a() {} static get[b]() {} }', - output: 'class A { a() {} static get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get'), - }, - { - code: '({ get [b]() {} })', - output: '({ get[b]() {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get'), - }, - { - code: 'class A { a() {} get [b]() {} }', - output: 'class A { a() {}get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('get'), - }, - { - code: 'class A { a() {}static get [b]() {} }', - output: 'class A { a() {}static get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get'), - }, - { - code: '({ get[b]() {} })', - output: '({ get [b]() {} })', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('get'), - }, - { - code: 'class A { a() {}get[b]() {} }', - output: 'class A { a() {} get [b]() {} }', - options: [override('get', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('get'), - }, - { - code: '({ get [b]() {} })', - output: '({ get[b]() {} })', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('get'), - }, - { - code: 'class A { a() {} get [b]() {} }', - output: 'class A { a() {}get[b]() {} }', - options: [override('get', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('get'), - }, - - //---------------------------------------------------------------------- - // if - //---------------------------------------------------------------------- - - { - code: '{}if(a) {}', - output: '{} if (a) {}', - errors: expectedBeforeAndAfter('if'), - }, - { - code: 'if (a) {} else if(b) {}', - output: 'if (a) {} else if (b) {}', - errors: expectedAfter('if'), - }, - { - code: '{} if (a) {}', - output: '{}if(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('if'), - }, - { - code: 'if(a) {}else if (b) {}', - output: 'if(a) {}else if(b) {}', - options: [NEITHER], - errors: unexpectedAfter('if'), - }, - { - code: '{}if(a) {}', - output: '{} if (a) {}', - options: [override('if', BOTH)], - errors: expectedBeforeAndAfter('if'), - }, - { - code: 'if (a) {}else if(b) {}', - output: 'if (a) {}else if (b) {}', - options: [override('if', BOTH)], - errors: expectedAfter('if'), - }, - { - code: '{} if (a) {}', - output: '{}if(a) {}', - options: [override('if', NEITHER)], - errors: unexpectedBeforeAndAfter('if'), - }, - { - code: 'if(a) {} else if (b) {}', - output: 'if(a) {} else if(b) {}', - options: [override('if', NEITHER)], - errors: unexpectedAfter('if'), - }, - - //---------------------------------------------------------------------- - // import - //---------------------------------------------------------------------- - - { - code: '{}import{a} from "foo"', - output: '{} import {a} from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import'), - }, - { - code: '{}import a from "foo"', - output: '{} import a from "foo"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBefore('import'), - }, - { - code: '{}import* as a from "a"', - output: '{} import * as a from "a"', - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import'), - }, - { - code: '{} import {a}from"foo"', - output: '{}import{a}from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import'), - }, - { - code: '{} import *as a from"foo"', - output: '{}import*as a from"foo"', - options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import'), - }, - { - code: '{}import{a}from"foo"', - output: '{} import {a}from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import'), - }, - { - code: '{}import*as a from"foo"', - output: '{} import *as a from"foo"', - options: [override('import', BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: expectedBeforeAndAfter('import'), - }, - { - code: '{} import {a} from "foo"', - output: '{}import{a} from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import'), - }, - { - code: '{} import * as a from "foo"', - output: '{}import* as a from "foo"', - options: [override('import', NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: 'module' }, - errors: unexpectedBeforeAndAfter('import'), - }, - - //---------------------------------------------------------------------- - // in - //---------------------------------------------------------------------- - - { - code: 'for ([foo]in{foo: 0}) {}', - output: 'for ([foo] in {foo: 0}) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('in'), - }, - { - code: 'for([foo] in {foo: 0}) {}', - output: 'for([foo]in{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('in'), - }, - { - code: 'for([foo]in{foo: 0}) {}', - output: 'for([foo] in {foo: 0}) {}', - options: [override('in', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('in'), - }, - { - code: 'for ([foo] in {foo: 0}) {}', - output: 'for ([foo]in{foo: 0}) {}', - options: [override('in', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('in'), - }, - - //---------------------------------------------------------------------- - // instanceof - //---------------------------------------------------------------------- - - // ignores - - //---------------------------------------------------------------------- - // let - //---------------------------------------------------------------------- - - { - code: '{}let[a] = b', - output: '{} let [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('let'), - }, - { - code: '{} let [a] = b', - output: '{}let[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('let'), - }, - { - code: '{}let[a] = b', - output: '{} let [a] = b', - options: [override('let', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('let'), - }, - { - code: '{} let [a] = b', - output: '{}let[a] = b', - options: [override('let', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('let'), - }, - - //---------------------------------------------------------------------- - // new - //---------------------------------------------------------------------- - - { - code: '{}new foo()', - output: '{} new foo()', - errors: expectedBefore('new'), - }, - { - code: '{} new foo()', - output: '{}new foo()', - options: [NEITHER], - errors: unexpectedBefore('new'), - }, - { - code: '{}new foo()', - output: '{} new foo()', - options: [override('new', BOTH)], - errors: expectedBefore('new'), - }, - { - code: '{} new foo()', - output: '{}new foo()', - options: [override('new', NEITHER)], - errors: unexpectedBefore('new'), - }, - - //---------------------------------------------------------------------- - // of - //---------------------------------------------------------------------- - - { - code: 'for ([foo]of{foo: 0}) {}', - output: 'for ([foo] of {foo: 0}) {}', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('of'), - }, - { - code: 'for([foo] of {foo: 0}) {}', - output: 'for([foo]of{foo: 0}) {}', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('of'), - }, - { - code: 'for([foo]of{foo: 0}) {}', - output: 'for([foo] of {foo: 0}) {}', - options: [override('of', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('of'), - }, - { - code: 'for ([foo] of {foo: 0}) {}', - output: 'for ([foo]of{foo: 0}) {}', - options: [override('of', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('of'), - }, - - //---------------------------------------------------------------------- - // return - //---------------------------------------------------------------------- - - { - code: 'function foo() { {}return+a }', - output: 'function foo() { {} return +a }', - errors: expectedBeforeAndAfter('return'), - }, - { - code: 'function foo() { {} return +a }', - output: 'function foo() { {}return+a }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('return'), - }, - { - code: 'function foo() { {}return+a }', - output: 'function foo() { {} return +a }', - options: [override('return', BOTH)], - errors: expectedBeforeAndAfter('return'), - }, - { - code: 'function foo() { {} return +a }', - output: 'function foo() { {}return+a }', - options: [override('return', NEITHER)], - errors: unexpectedBeforeAndAfter('return'), - }, - - //---------------------------------------------------------------------- - // set - //---------------------------------------------------------------------- - - { - code: '({ set[b](value) {} })', - output: '({ set [b](value) {} })', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set'), - }, - { - code: 'class A { a() {}set[b](value) {} }', - output: 'class A { a() {} set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('set'), - }, - { - code: 'class A { a() {} static set[b](value) {} }', - output: 'class A { a() {} static set [b](value) {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set'), - }, - { - code: '({ set [b](value) {} })', - output: '({ set[b](value) {} })', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('set'), - }, - { - code: 'class A { a() {} set [b](value) {} }', - output: 'class A { a() {}set[b](value) {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('set'), - }, - { - code: '({ set[b](value) {} })', - output: '({ set [b](value) {} })', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter('set'), - }, - { - code: 'class A { a() {}set[b](value) {} }', - output: 'class A { a() {} set [b](value) {} }', - options: [override('set', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('set'), - }, - { - code: '({ set [b](value) {} })', - output: '({ set[b](value) {} })', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter('set'), - }, - { - code: 'class A { a() {} set [b](value) {} }', - output: 'class A { a() {}set[b](value) {} }', - options: [override('set', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('set'), - }, - - //---------------------------------------------------------------------- - // static - //---------------------------------------------------------------------- - - { - code: 'class A { a() {}static[b]() {} }', - output: 'class A { a() {} static [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('static'), - }, - { - code: 'class A { a() {}static get [b]() {} }', - output: 'class A { a() {} static get [b]() {} }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('static'), - }, - { - code: 'class A { a() {} static [b]() {} }', - output: 'class A { a() {}static[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('static'), - }, - { - code: 'class A { a() {} static get[b]() {} }', - output: 'class A { a() {}static get[b]() {} }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('static'), - }, - { - code: 'class A { a() {}static[b]() {} }', - output: 'class A { a() {} static [b]() {} }', - options: [override('static', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('static'), - }, - { - code: 'class A { a() {} static [b]() {} }', - output: 'class A { a() {}static[b]() {} }', - options: [override('static', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('static'), - }, - - //---------------------------------------------------------------------- - // super - //---------------------------------------------------------------------- - - { - code: 'class A { a() { {}super[b]; } }', - output: 'class A { a() { {} super[b]; } }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('super'), - }, - { - code: 'class A { a() { {} super[b]; } }', - output: 'class A { a() { {}super[b]; } }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('super'), - }, - { - code: 'class A { a() { {}super[b]; } }', - output: 'class A { a() { {} super[b]; } }', - options: [override('super', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('super'), - }, - { - code: 'class A { a() { {} super[b]; } }', - output: 'class A { a() { {}super[b]; } }', - options: [override('super', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('super'), - }, - - //---------------------------------------------------------------------- - // switch - //---------------------------------------------------------------------- - - { - code: '{}switch(a) {}', - output: '{} switch (a) {}', - errors: expectedBeforeAndAfter('switch'), - }, - { - code: '{} switch (a) {}', - output: '{}switch(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('switch'), - }, - { - code: '{}switch(a) {}', - output: '{} switch (a) {}', - options: [override('switch', BOTH)], - errors: expectedBeforeAndAfter('switch'), - }, - { - code: '{} switch (a) {}', - output: '{}switch(a) {}', - options: [override('switch', NEITHER)], - errors: unexpectedBeforeAndAfter('switch'), - }, - - //---------------------------------------------------------------------- - // this - //---------------------------------------------------------------------- - - { - code: '{}this[a]', - output: '{} this[a]', - errors: expectedBefore('this'), - }, - { - code: '{} this[a]', - output: '{}this[a]', - options: [NEITHER], - errors: unexpectedBefore('this'), - }, - { - code: '{}this[a]', - output: '{} this[a]', - options: [override('this', BOTH)], - errors: expectedBefore('this'), - }, - { - code: '{} this[a]', - output: '{}this[a]', - options: [override('this', NEITHER)], - errors: unexpectedBefore('this'), - }, - - //---------------------------------------------------------------------- - // throw - //---------------------------------------------------------------------- - - { - code: 'function foo() { {}throw+a }', - output: 'function foo() { {} throw +a }', - errors: expectedBeforeAndAfter('throw'), - }, - { - code: 'function foo() { {} throw +a }', - output: 'function foo() { {}throw+a }', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('throw'), - }, - { - code: 'function foo() { {}throw+a }', - output: 'function foo() { {} throw +a }', - options: [override('throw', BOTH)], - errors: expectedBeforeAndAfter('throw'), - }, - { - code: 'function foo() { {} throw +a }', - output: 'function foo() { {}throw+a }', - options: [override('throw', NEITHER)], - errors: unexpectedBeforeAndAfter('throw'), - }, - - //---------------------------------------------------------------------- - // try - //---------------------------------------------------------------------- - - { - code: '{}try{} finally {}', - output: '{} try {} finally {}', - errors: expectedBeforeAndAfter('try'), - }, - { - code: '{} try {}finally{}', - output: '{}try{}finally{}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('try'), - }, - { - code: '{}try{}finally{}', - output: '{} try {}finally{}', - options: [override('try', BOTH)], - errors: expectedBeforeAndAfter('try'), - }, - { - code: '{} try {} finally {}', - output: '{}try{} finally {}', - options: [override('try', NEITHER)], - errors: unexpectedBeforeAndAfter('try'), - }, - - //---------------------------------------------------------------------- - // typeof - //---------------------------------------------------------------------- - - { - code: '{}typeof foo', - output: '{} typeof foo', - errors: expectedBefore('typeof'), - }, - { - code: '{} typeof foo', - output: '{}typeof foo', - options: [NEITHER], - errors: unexpectedBefore('typeof'), - }, - { - code: '{}typeof foo', - output: '{} typeof foo', - options: [override('typeof', BOTH)], - errors: expectedBefore('typeof'), - }, - { - code: '{} typeof foo', - output: '{}typeof foo', - options: [override('typeof', NEITHER)], - errors: unexpectedBefore('typeof'), - }, - - //---------------------------------------------------------------------- - // var - //---------------------------------------------------------------------- - - { - code: '{}var[a] = b', - output: '{} var [a] = b', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('var'), - }, - { - code: '{} var [a] = b', - output: '{}var[a] = b', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('var'), - }, - { - code: '{}var[a] = b', - output: '{} var [a] = b', - options: [override('var', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter('var'), - }, - { - code: '{} var [a] = b', - output: '{}var[a] = b', - options: [override('var', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter('var'), - }, - - //---------------------------------------------------------------------- - // void - //---------------------------------------------------------------------- - - { - code: '{}void foo', - output: '{} void foo', - errors: expectedBefore('void'), - }, - { - code: '{} void foo', - output: '{}void foo', - options: [NEITHER], - errors: unexpectedBefore('void'), - }, - { - code: '{}void foo', - output: '{} void foo', - options: [override('void', BOTH)], - errors: expectedBefore('void'), - }, - { - code: '{} void foo', - output: '{}void foo', - options: [override('void', NEITHER)], - errors: unexpectedBefore('void'), - }, - - //---------------------------------------------------------------------- - // while - //---------------------------------------------------------------------- - - { - code: '{}while(a) {}', - output: '{} while (a) {}', - errors: expectedBeforeAndAfter('while'), - }, - { - code: 'do {}while(a)', - output: 'do {} while (a)', - errors: expectedBeforeAndAfter('while'), - }, - { - code: '{} while (a) {}', - output: '{}while(a) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('while'), - }, - { - code: 'do{} while (a)', - output: 'do{}while(a)', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('while'), - }, - { - code: '{}while(a) {}', - output: '{} while (a) {}', - options: [override('while', BOTH)], - errors: expectedBeforeAndAfter('while'), - }, - { - code: 'do{}while(a)', - output: 'do{} while (a)', - options: [override('while', BOTH)], - errors: expectedBeforeAndAfter('while'), - }, - { - code: '{} while (a) {}', - output: '{}while(a) {}', - options: [override('while', NEITHER)], - errors: unexpectedBeforeAndAfter('while'), - }, - { - code: 'do {} while (a)', - output: 'do {}while(a)', - options: [override('while', NEITHER)], - errors: unexpectedBeforeAndAfter('while'), - }, - - //---------------------------------------------------------------------- - // with - //---------------------------------------------------------------------- - - { - code: '{}with(obj) {}', - output: '{} with (obj) {}', - errors: expectedBeforeAndAfter('with'), - }, - { - code: '{} with (obj) {}', - output: '{}with(obj) {}', - options: [NEITHER], - errors: unexpectedBeforeAndAfter('with'), - }, - { - code: '{}with(obj) {}', - output: '{} with (obj) {}', - options: [override('with', BOTH)], - errors: expectedBeforeAndAfter('with'), - }, - { - code: '{} with (obj) {}', - output: '{}with(obj) {}', - options: [override('with', NEITHER)], - errors: unexpectedBeforeAndAfter('with'), - }, - - //---------------------------------------------------------------------- - // yield - //---------------------------------------------------------------------- - - { - code: 'function* foo() { {}yield foo }', - output: 'function* foo() { {} yield foo }', - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('yield'), - }, - { - code: 'function* foo() { {} yield foo }', - output: 'function* foo() { {}yield foo }', - options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('yield'), - }, - { - code: 'function* foo() { {}yield foo }', - output: 'function* foo() { {} yield foo }', - options: [override('yield', BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore('yield'), - }, - { - code: 'function* foo() { {} yield foo }', - output: 'function* foo() { {}yield foo }', - options: [override('yield', NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore('yield'), - }, - - //---------------------------------------------------------------------- - // typescript parser - //---------------------------------------------------------------------- - - // get, set, async decorator keywords shouldn't be detected - { - code: - 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }', - output: - 'class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }', - errors: expectedAfter('async'), + errors: unexpectedBefore('as'), }, ] as TSESLint.InvalidTestCase[], }); diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 9d9c88b73bb2..29abfc467a36 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -1,9 +1,81 @@ +// import keywords from 'eslint/lib/rules/utils/keywords'; + // don't provide a general import case so that people have to strictly type out a declaration // declare module 'eslint/lib/rules/*' TSESLint, { // const rule: TSESLint.RuleModule; // export = rule; // } +declare type Keyword = + | 'abstract' + | 'boolean' + | 'break' + | 'byte' + | 'case' + | 'catch' + | 'char' + | 'class' + | 'const' + | 'continue' + | 'debugger' + | 'default' + | 'delete' + | 'do' + | 'double' + | 'else' + | 'enum' + | 'export' + | 'extends' + | 'false' + | 'final' + | 'finally' + | 'float' + | 'for' + | 'function' + | 'goto' + | 'if' + | 'implements' + | 'import' + | 'in' + | 'instanceof' + | 'int' + | 'interface' + | 'long' + | 'native' + | 'new' + | 'null' + | 'package' + | 'private' + | 'protected' + | 'public' + | 'return' + | 'short' + | 'static' + | 'super' + | 'switch' + | 'synchronized' + | 'this' + | 'throw' + | 'throws' + | 'transient' + | 'true' + | 'try' + | 'typeof' + | 'var' + | 'void' + | 'volatile' + | 'while' + | 'with' + | 'as' + | 'async' + | 'await' + | 'from' + | 'get' + | 'let' + | 'of' + | 'set' + | 'yield'; + declare module 'eslint/lib/rules/arrow-parens' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; @@ -144,10 +216,21 @@ declare module 'eslint/lib/rules/indent' { declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; - + export type Option = Partial<{ + before: boolean; + after: boolean; + }>; + export type OverrideOptions = Partial>; + export type RootOption = Option & { overrides?: OverrideOptions }; + export type Options = [RootOption]; + export type MessageIds = + | 'expectedBefore' + | 'expectedAfter' + | 'unexpectedBefore' + | 'unexpectedAfter'; const rule: TSESLint.RuleModule< - 'expectedBefore' | 'expectedAfter' | 'unexpectedBefore' | 'unexpectedAfter', - [], + MessageIds, + Options, { // Statements DebuggerStatement: (node: TSESTree.DebuggerStatement) => void; @@ -202,7 +285,7 @@ declare module 'eslint/lib/rules/keyword-spacing' { Property: (node: TSESTree.Property) => void; } >; - export = rule; + export default rule; } declare module 'eslint/lib/rules/no-dupe-class-members' { From de86f6f9bb6c300cd828d06ba0233c32f81458cf Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 14:53:24 +0100 Subject: [PATCH 12/31] Better typing --- .../tests/rules/keyword-spacing.test.ts | 7 +- .../typings/eslint-keywords.d.ts | 73 ++++++++- .../eslint-plugin/typings/eslint-rules.d.ts | 144 +++++------------- 3 files changed, 106 insertions(+), 118 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 7bd5c6e5baa3..bffc2b1e5791 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -66,7 +66,6 @@ ruleTester.run('keyword-spacing', rule, { //---------------------------------------------------------------------- // as (typing) //---------------------------------------------------------------------- - { code: 'const foo = {} as {}', parserOptions: { ecmaVersion: 6, sourceType: 'module' }, @@ -86,13 +85,11 @@ ruleTester.run('keyword-spacing', rule, { options: [override('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, - ] as TSESLint.ValidTestCase[], - + ], invalid: [ //---------------------------------------------------------------------- // as (typing) //---------------------------------------------------------------------- - { code: 'const foo = {}as {}', output: 'const foo = {} as {}', @@ -106,5 +103,5 @@ ruleTester.run('keyword-spacing', rule, { parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: unexpectedBefore('as'), }, - ] as TSESLint.InvalidTestCase[], + ], }); diff --git a/packages/eslint-plugin/typings/eslint-keywords.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts index 2124fdd784b0..3b99d01a59a5 100644 --- a/packages/eslint-plugin/typings/eslint-keywords.d.ts +++ b/packages/eslint-plugin/typings/eslint-keywords.d.ts @@ -1,4 +1,69 @@ -declare module 'eslint/lib/rules/utils/keywords' { - const keywords: string[]; - export default keywords; -} +declare type Keyword = + | 'abstract' + | 'boolean' + | 'break' + | 'byte' + | 'case' + | 'catch' + | 'char' + | 'class' + | 'const' + | 'continue' + | 'debugger' + | 'default' + | 'delete' + | 'do' + | 'double' + | 'else' + | 'enum' + | 'export' + | 'extends' + | 'false' + | 'final' + | 'finally' + | 'float' + | 'for' + | 'function' + | 'goto' + | 'if' + | 'implements' + | 'import' + | 'in' + | 'instanceof' + | 'int' + | 'interface' + | 'long' + | 'native' + | 'new' + | 'null' + | 'package' + | 'private' + | 'protected' + | 'public' + | 'return' + | 'short' + | 'static' + | 'super' + | 'switch' + | 'synchronized' + | 'this' + | 'throw' + | 'throws' + | 'transient' + | 'true' + | 'try' + | 'typeof' + | 'var' + | 'void' + | 'volatile' + | 'while' + | 'with' + | 'as' + | 'async' + | 'await' + | 'from' + | 'get' + | 'let' + | 'of' + | 'set' + | 'yield'; diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 29abfc467a36..9210899b318b 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -1,80 +1,9 @@ -// import keywords from 'eslint/lib/rules/utils/keywords'; - // don't provide a general import case so that people have to strictly type out a declaration // declare module 'eslint/lib/rules/*' TSESLint, { // const rule: TSESLint.RuleModule; // export = rule; // } -declare type Keyword = - | 'abstract' - | 'boolean' - | 'break' - | 'byte' - | 'case' - | 'catch' - | 'char' - | 'class' - | 'const' - | 'continue' - | 'debugger' - | 'default' - | 'delete' - | 'do' - | 'double' - | 'else' - | 'enum' - | 'export' - | 'extends' - | 'false' - | 'final' - | 'finally' - | 'float' - | 'for' - | 'function' - | 'goto' - | 'if' - | 'implements' - | 'import' - | 'in' - | 'instanceof' - | 'int' - | 'interface' - | 'long' - | 'native' - | 'new' - | 'null' - | 'package' - | 'private' - | 'protected' - | 'public' - | 'return' - | 'short' - | 'static' - | 'super' - | 'switch' - | 'synchronized' - | 'this' - | 'throw' - | 'throws' - | 'transient' - | 'true' - | 'try' - | 'typeof' - | 'var' - | 'void' - | 'volatile' - | 'while' - | 'with' - | 'as' - | 'async' - | 'await' - | 'from' - | 'get' - | 'let' - | 'of' - | 'set' - | 'yield'; declare module 'eslint/lib/rules/arrow-parens' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; @@ -216,6 +145,7 @@ declare module 'eslint/lib/rules/indent' { declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; + import { RuleFunction } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; export type Option = Partial<{ before: boolean; after: boolean; @@ -233,56 +163,52 @@ declare module 'eslint/lib/rules/keyword-spacing' { Options, { // Statements - DebuggerStatement: (node: TSESTree.DebuggerStatement) => void; - WithStatement: (node: TSESTree.WithStatement) => void; + DebuggerStatement: RuleFunction; + WithStatement: RuleFunction; // Statements - Control flow - BreakStatement: (node: TSESTree.BreakStatement) => void; - ContinueStatement: (node: TSESTree.ContinueStatement) => void; - ReturnStatement: (node: TSESTree.ReturnStatement) => void; - ThrowStatement: (node: TSESTree.ThrowStatement) => void; - TryStatement: (node: TSESTree.TryStatement) => void; + BreakStatement: RuleFunction; + ContinueStatement: RuleFunction; + ReturnStatement: RuleFunction; + ThrowStatement: RuleFunction; + TryStatement: RuleFunction; // Statements - Choice - IfStatement: (node: TSESTree.IfStatement) => void; - SwitchStatement: (node: TSESTree.Node) => void; - SwitchCase: (node: TSESTree.Node) => void; + IfStatement: RuleFunction; + SwitchStatement: RuleFunction; + SwitchCase: RuleFunction; // Statements - Loops - DoWhileStatement: (node: TSESTree.DoWhileStatement) => void; - ForInStatement: (node: TSESTree.ForInStatement) => void; - ForOfStatement: (node: TSESTree.ForOfStatement) => void; - ForStatement: (node: TSESTree.ForStatement) => void; - WhileStatement: (node: TSESTree.WhileStatement) => void; + DoWhileStatement: RuleFunction; + ForInStatement: RuleFunction; + ForOfStatement: RuleFunction; + ForStatement: RuleFunction; + WhileStatement: RuleFunction; // Statements - Declarations - ClassDeclaration: (node: TSESTree.ClassDeclaration) => void; - ExportNamedDeclaration: (node: TSESTree.ExportNamedDeclaration) => void; - ExportDefaultDeclaration: ( - node: TSESTree.ExportDefaultDeclaration, - ) => void; - ExportAllDeclaration: (node: TSESTree.ExportAllDeclaration) => void; - FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void; - ImportDeclaration: (node: TSESTree.ImportDeclaration) => void; - VariableDeclaration: (node: TSESTree.VariableDeclaration) => void; + ClassDeclaration: RuleFunction; + ExportNamedDeclaration: RuleFunction; + ExportDefaultDeclaration: RuleFunction; + ExportAllDeclaration: RuleFunction; + FunctionDeclaration: RuleFunction; + ImportDeclaration: RuleFunction; + VariableDeclaration: RuleFunction; // Expressions - ArrowFunctionExpression: (node: TSESTree.ArrowFunctionExpression) => void; - AwaitExpression: (node: TSESTree.AwaitExpression) => void; - ClassExpression: (node: TSESTree.ClassExpression) => void; - FunctionExpression: (node: TSESTree.FunctionExpression) => void; - NewExpression: (node: TSESTree.NewExpression) => void; - Super: (node: TSESTree.Super) => void; - ThisExpression: (node: TSESTree.ThisExpression) => void; - UnaryExpression: (node: TSESTree.UnaryExpression) => void; - YieldExpression: (node: TSESTree.YieldExpression) => void; + ArrowFunctionExpression: RuleFunction; + AwaitExpression: RuleFunction; + ClassExpression: RuleFunction; + FunctionExpression: RuleFunction; + NewExpression: RuleFunction; + Super: RuleFunction; + ThisExpression: RuleFunction; + UnaryExpression: RuleFunction; + YieldExpression: RuleFunction; // Others - ImportNamespaceSpecifier: ( - node: TSESTree.ImportNamespaceSpecifier, - ) => void; - MethodDefinition: (node: TSESTree.MethodDefinition) => void; - Property: (node: TSESTree.Property) => void; + ImportNamespaceSpecifier: RuleFunction; + MethodDefinition: RuleFunction; + Property: RuleFunction; } >; export default rule; From 7d0dd8148b7a00364bc7afbd59f52669658722b0 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 14:59:07 +0100 Subject: [PATCH 13/31] export Options --- packages/eslint-plugin/src/rules/keyword-spacing.ts | 6 +++--- packages/eslint-plugin/tests/rules/keyword-spacing.test.ts | 1 - packages/eslint-plugin/typings/eslint-rules.d.ts | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index c9f4435ecc78..0be5c18e05ca 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,14 +1,14 @@ import baseRule, { - Options, RootOption, OverrideOptions, - MessageIds, } from 'eslint/lib/rules/keyword-spacing'; import { TSESTree } from '@typescript-eslint/experimental-utils'; import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; - import * as util from '../util'; +export type Options = util.InferOptionsTypeFromRule; +export type MessageIds = util.InferMessageIdsTypeFromRule; + const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; const TEMPLATE_OPEN_PAREN = /\$\{$/u; diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index bffc2b1e5791..41016a80f622 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -56,7 +56,6 @@ function unexpectedBefore( return [{ messageId: 'unexpectedBefore', data: { value: keyword } }]; } - const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 9210899b318b..73f7f824a28b 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -4,7 +4,6 @@ // export = rule; // } - declare module 'eslint/lib/rules/arrow-parens' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; From f40bc1cb8ed40b0e56c5b48d633f7fb3b3a43be5 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 15:01:56 +0100 Subject: [PATCH 14/31] Fixed typing --- packages/eslint-plugin/tests/rules/keyword-spacing.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 41016a80f622..518a7ab62b39 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,7 +1,7 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/keyword-spacing'; import { RuleTester } from '../RuleTester'; -import { MessageIds, Options } from 'eslint/lib/rules/keyword-spacing'; +import { MessageIds, Option, RootOption } from 'eslint/lib/rules/keyword-spacing'; //------------------------------------------------------------------------------ // Helpers From 88e4e703580a32dd23c61f4efd45511b08513507 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 15:53:31 +0100 Subject: [PATCH 15/31] pretty --- packages/eslint-plugin/tests/rules/keyword-spacing.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 518a7ab62b39..fc92c22d4048 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,7 +1,11 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import rule from '../../src/rules/keyword-spacing'; import { RuleTester } from '../RuleTester'; -import { MessageIds, Option, RootOption } from 'eslint/lib/rules/keyword-spacing'; +import { + MessageIds, + Option, + RootOption, +} from 'eslint/lib/rules/keyword-spacing'; //------------------------------------------------------------------------------ // Helpers From e9bb02934ee23d017746507cc0e5c94516c64b27 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 16:05:23 +0100 Subject: [PATCH 16/31] Linting --- .../src/rules/keyword-spacing.ts | 32 +++++++++---------- .../eslint-plugin/typings/eslint-rules.d.ts | 1 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 0be5c18e05ca..a37b9c91c3ca 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -2,7 +2,7 @@ import baseRule, { RootOption, OverrideOptions, } from 'eslint/lib/rules/keyword-spacing'; -import { TSESTree } from '@typescript-eslint/experimental-utils'; +import { TSESTree, AST_TOKEN_TYPES } from '@typescript-eslint/experimental-utils'; import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; import * as util from '../util'; @@ -23,8 +23,8 @@ const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; * @param token A token to check. * @returns `true` if the token is a "Template" token ends with "${". */ -function isOpenParenOfTemplate(token: TSESTree.Token) { - return token.type === 'Template' && TEMPLATE_OPEN_PAREN.test(token.value); +function isOpenParenOfTemplate(token: TSESTree.Token): boolean { + return token.type === AST_TOKEN_TYPES.Template && TEMPLATE_OPEN_PAREN.test(token.value); } /** @@ -32,8 +32,8 @@ function isOpenParenOfTemplate(token: TSESTree.Token) { * @param token A token to check. * @returns `true` if the token is a "Template" token starts with "}". */ -function isCloseParenOfTemplate(token: TSESTree.Token) { - return token.type === 'Template' && TEMPLATE_CLOSE_PAREN.test(token.value); +function isCloseParenOfTemplate(token: TSESTree.Token): boolean { + return token.type === AST_TOKEN_TYPES.Template && TEMPLATE_CLOSE_PAREN.test(token.value); } export default util.createRule({ @@ -61,7 +61,7 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the previous token to check. */ - function expectSpaceBefore(token: TSESTree.Token, pattern: RegExp) { + function expectSpaceBefore(token: TSESTree.Token, pattern: RegExp): void { const prevToken = sourceCode.getTokenBefore(token); if ( @@ -89,7 +89,7 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the previous token to check. */ - function unexpectSpaceBefore(token: TSESTree.Token, pattern: RegExp) { + function unexpectSpaceBefore(token: TSESTree.Token, pattern: RegExp): void { const prevToken = sourceCode.getTokenBefore(token); if ( @@ -117,7 +117,7 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the next token to check. */ - function expectSpaceAfter(token: TSESTree.Token, pattern: RegExp) { + function expectSpaceAfter(token: TSESTree.Token, pattern: RegExp): void { const nextToken = sourceCode.getTokenAfter(token); if ( @@ -145,7 +145,7 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the next token to check. */ - function unexpectSpaceAfter(token: TSESTree.Token, pattern: RegExp) { + function unexpectSpaceAfter(token: TSESTree.Token, pattern: RegExp): void { const nextToken = sourceCode.getTokenAfter(token); if ( @@ -184,7 +184,7 @@ export default util.createRule({ before: before ? expectSpaceBefore : unexpectSpaceBefore, after: after ? expectSpaceAfter : unexpectSpaceAfter, }; - const overrides: OverrideOptions = (options && options.overrides) || {}; + const overrides: OverrideOptions = options?.overrides || {}; const retv = Object.create(null); for (let i = 0; i < KEYWORDS.length; ++i) { @@ -213,8 +213,8 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the previous token to check. */ - function checkSpacingBefore(token: TSESTree.Token, pattern?: RegExp) { - checkMethodMap[token.value].before(token, pattern || PREV_TOKEN); + function checkSpacingBefore(token: TSESTree.Token, pattern?: RegExp): void { + checkMethodMap[token.value].before(token, pattern ?? PREV_TOKEN); } /** @@ -222,15 +222,15 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the next token to check. */ - function checkSpacingAfter(token: TSESTree.Token, pattern?: RegExp) { - checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN); + function checkSpacingAfter(token: TSESTree.Token, pattern?: RegExp): void { + checkMethodMap[token.value].after(token, pattern ?? NEXT_TOKEN); } /** * Reports a given token if usage of spacing around the token is invalid. * @param token A token to report. */ - function checkSpacingAround(token: TSESTree.Token) { + function checkSpacingAround(token: TSESTree.Token): void { checkSpacingBefore(token); checkSpacingAfter(token); } @@ -240,7 +240,7 @@ export default util.createRule({ * this keyword is invalid. * @param node A node to report. */ - function checkSpacingForAsExpression(node: TSESTree.TSAsExpression) { + function checkSpacingForAsExpression(node: TSESTree.TSAsExpression): void { const token = sourceCode.getTokenAfter(node.expression)!; // get the `as` identifier. checkSpacingAround(token); } diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 73f7f824a28b..979a24581583 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -145,6 +145,7 @@ declare module 'eslint/lib/rules/indent' { declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; import { RuleFunction } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; + export type Option = Partial<{ before: boolean; after: boolean; From 678910272b9b8baf212a21289057af776d26425b Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 16:09:02 +0100 Subject: [PATCH 17/31] Linting again... --- .../eslint-plugin/src/rules/keyword-spacing.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index a37b9c91c3ca..7adb9467ba47 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -2,7 +2,10 @@ import baseRule, { RootOption, OverrideOptions, } from 'eslint/lib/rules/keyword-spacing'; -import { TSESTree, AST_TOKEN_TYPES } from '@typescript-eslint/experimental-utils'; +import { + TSESTree, + AST_TOKEN_TYPES, +} from '@typescript-eslint/experimental-utils'; import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; import * as util from '../util'; @@ -24,7 +27,10 @@ const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; * @returns `true` if the token is a "Template" token ends with "${". */ function isOpenParenOfTemplate(token: TSESTree.Token): boolean { - return token.type === AST_TOKEN_TYPES.Template && TEMPLATE_OPEN_PAREN.test(token.value); + return ( + token.type === AST_TOKEN_TYPES.Template && + TEMPLATE_OPEN_PAREN.test(token.value) + ); } /** @@ -33,7 +39,10 @@ function isOpenParenOfTemplate(token: TSESTree.Token): boolean { * @returns `true` if the token is a "Template" token starts with "}". */ function isCloseParenOfTemplate(token: TSESTree.Token): boolean { - return token.type === AST_TOKEN_TYPES.Template && TEMPLATE_CLOSE_PAREN.test(token.value); + return ( + token.type === AST_TOKEN_TYPES.Template && + TEMPLATE_CLOSE_PAREN.test(token.value) + ); } export default util.createRule({ From 94eccbc6cbec8475db6f50722d252f0fd39492a1 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 16:58:16 +0100 Subject: [PATCH 18/31] Better typing --- .../src/rules/keyword-spacing.ts | 22 +++++++++++-------- .../eslint-plugin/typings/eslint-rules.d.ts | 13 ++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 7adb9467ba47..34618fae6224 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,7 +1,4 @@ -import baseRule, { - RootOption, - OverrideOptions, -} from 'eslint/lib/rules/keyword-spacing'; +import baseRule from 'eslint/lib/rules/keyword-spacing'; import { TSESTree, AST_TOKEN_TYPES, @@ -9,13 +6,20 @@ import { import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; import * as util from '../util'; +type Option = Partial<{ + before: boolean; + after: boolean; +}>; +type OverrideOptions = Partial>; +type RootOption = Option & { overrides?: OverrideOptions }; + export type Options = util.InferOptionsTypeFromRule; export type MessageIds = util.InferMessageIdsTypeFromRule; const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; -const TEMPLATE_OPEN_PAREN = /\$\{$/u; -const TEMPLATE_CLOSE_PAREN = /^\}/u; +const TEMPLATE_OPEN_PAREN = '${'; +const TEMPLATE_CLOSE_PAREN = '}'; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; //------------------------------------------------------------------------------ // Helpers @@ -29,7 +33,7 @@ const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; function isOpenParenOfTemplate(token: TSESTree.Token): boolean { return ( token.type === AST_TOKEN_TYPES.Template && - TEMPLATE_OPEN_PAREN.test(token.value) + token.value.startsWith(TEMPLATE_OPEN_PAREN) ); } @@ -41,7 +45,7 @@ function isOpenParenOfTemplate(token: TSESTree.Token): boolean { function isCloseParenOfTemplate(token: TSESTree.Token): boolean { return ( token.type === AST_TOKEN_TYPES.Template && - TEMPLATE_CLOSE_PAREN.test(token.value) + token.value.endsWith(TEMPLATE_CLOSE_PAREN) ); } @@ -193,7 +197,7 @@ export default util.createRule({ before: before ? expectSpaceBefore : unexpectSpaceBefore, after: after ? expectSpaceAfter : unexpectSpaceAfter, }; - const overrides: OverrideOptions = options?.overrides || {}; + const overrides: OverrideOptions = options?.overrides ?? {}; const retv = Object.create(null); for (let i = 0; i < KEYWORDS.length; ++i) { diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 979a24581583..471335158e23 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -146,18 +146,19 @@ declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; import { RuleFunction } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; - export type Option = Partial<{ + type Option = Partial<{ before: boolean; after: boolean; }>; - export type OverrideOptions = Partial>; - export type RootOption = Option & { overrides?: OverrideOptions }; - export type Options = [RootOption]; - export type MessageIds = + type OverrideOptions = Partial>; + type RootOption = Option & { overrides?: OverrideOptions }; + type Options = [RootOption]; + type MessageIds = | 'expectedBefore' | 'expectedAfter' | 'unexpectedBefore' | 'unexpectedAfter'; + const rule: TSESLint.RuleModule< MessageIds, Options, @@ -211,7 +212,7 @@ declare module 'eslint/lib/rules/keyword-spacing' { Property: RuleFunction; } >; - export default rule; + export = rule; } declare module 'eslint/lib/rules/no-dupe-class-members' { From 2941964ef1ce70a7c7783f5fb7eb9e0d21f233e7 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 17:02:19 +0100 Subject: [PATCH 19/31] typing, typing, typing... --- packages/eslint-plugin/src/rules/keyword-spacing.ts | 6 +++--- .../eslint-plugin/tests/rules/keyword-spacing.test.ts | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 34618fae6224..af98a138c989 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -6,12 +6,12 @@ import { import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; import * as util from '../util'; -type Option = Partial<{ +export type Option = Partial<{ before: boolean; after: boolean; }>; -type OverrideOptions = Partial>; -type RootOption = Option & { overrides?: OverrideOptions }; +export type OverrideOptions = Partial>; +export type RootOption = Option & { overrides?: OverrideOptions }; export type Options = util.InferOptionsTypeFromRule; export type MessageIds = util.InferMessageIdsTypeFromRule; diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index fc92c22d4048..6765c579bebf 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,11 +1,10 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import rule from '../../src/rules/keyword-spacing'; -import { RuleTester } from '../RuleTester'; -import { - MessageIds, +import rule, { Option, RootOption, -} from 'eslint/lib/rules/keyword-spacing'; + MessageIds, +} from '../../src/rules/keyword-spacing'; +import { RuleTester } from '../RuleTester'; //------------------------------------------------------------------------------ // Helpers From 0022f7eee47c258f7e5597f302402c45623d1bc3 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 17:06:55 +0100 Subject: [PATCH 20/31] typo --- packages/eslint-plugin/tests/rules/keyword-spacing.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 6765c579bebf..b789ebf97386 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -27,7 +27,7 @@ const NEITHER = { before: false, after: false }; * after: false, * overrides: {as: {before: true, after: true}} * } - * @param keyword A keyword to be overriden. + * @param keyword A keyword to be overridden. * @param value A value to override. * @returns An option object to test an 'overrides' option. */ From f4011c94bad0ac5f7b50ec67f7a792aa813c3f69 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Tue, 17 Mar 2020 18:08:23 +0100 Subject: [PATCH 21/31] Test coverage for `after` --- .../tests/rules/keyword-spacing.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index b789ebf97386..04af96bc2b82 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -48,6 +48,15 @@ function expectedBefore(keyword: string): TSESLint.TestCaseError[] { return [{ messageId: 'expectedBefore', data: { value: keyword } }]; } +/** + * Gets an error message that expected space(s) after a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ +function expectedAfter(keyword: string): TSESLint.TestCaseError[] { + return [{ messageId: 'expectedAfter', data: { value: keyword } }]; +} + /** * Gets an error message that unexpected space(s) before a specified keyword. * @param keyword A keyword. @@ -59,6 +68,17 @@ function unexpectedBefore( return [{ messageId: 'unexpectedBefore', data: { value: keyword } }]; } +/** + * Gets an error message that unexpected space(s) after a specified keyword. + * @param keyword A keyword. + * @returns An error message. + */ +function unexpectedAfter( + keyword: string, +): TSESLint.TestCaseError[] { + return [{ messageId: 'unexpectedAfter', data: { value: keyword } }]; +} + const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); @@ -105,5 +125,18 @@ ruleTester.run('keyword-spacing', rule, { parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: unexpectedBefore('as'), }, + { + code: 'const foo = {} as{}', + output: 'const foo = {} as {}', + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedAfter('as'), + }, + { + code: 'const foo = {}as {}', + output: 'const foo = {}as{}', + options: [NEITHER], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: unexpectedAfter('as'), + }, ], }); From bdab59d3c56f370ffcea2261757e36e40cef2eca Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Wed, 18 Mar 2020 19:47:01 +0100 Subject: [PATCH 22/31] import the keyword list --- packages/eslint-plugin/typings/eslint-keywords.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/eslint-plugin/typings/eslint-keywords.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts index 3b99d01a59a5..a40b568f33bd 100644 --- a/packages/eslint-plugin/typings/eslint-keywords.d.ts +++ b/packages/eslint-plugin/typings/eslint-keywords.d.ts @@ -1,3 +1,9 @@ +declare module 'eslint/lib/rules/utils/keywords' { + const keywords: string[]; + export default keywords; +} + + declare type Keyword = | 'abstract' | 'boolean' From c8b69fd574546e8a1f1a392f9cf49da73ecd31bc Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Wed, 18 Mar 2020 20:31:10 +0100 Subject: [PATCH 23/31] Dropped Keyword const type --- .../src/rules/keyword-spacing.ts | 33 ++++++++- .../typings/eslint-keywords.d.ts | 71 ------------------- .../eslint-plugin/typings/eslint-rules.d.ts | 2 +- 3 files changed, 31 insertions(+), 75 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index af98a138c989..11c65a4c3f6e 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,16 +1,17 @@ import baseRule from 'eslint/lib/rules/keyword-spacing'; +import ESLINT_UTILS_KEYWORDS from 'eslint/lib/rules/utils/keywords'; import { TSESTree, AST_TOKEN_TYPES, } from '@typescript-eslint/experimental-utils'; -import { isTokenOnSameLine, KEYWORDS } from '../util/astUtils'; +import { isTokenOnSameLine } from '../util/astUtils'; import * as util from '../util'; export type Option = Partial<{ before: boolean; after: boolean; }>; -export type OverrideOptions = Partial>; +export type OverrideOptions = Partial>; export type RootOption = Option & { overrides?: OverrideOptions }; export type Options = util.InferOptionsTypeFromRule; @@ -21,6 +22,32 @@ const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; const TEMPLATE_OPEN_PAREN = '${'; const TEMPLATE_CLOSE_PAREN = '}'; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; + +const KEYWORDS = ESLINT_UTILS_KEYWORDS.concat([ + // Eslint Utils does no provide all keywords, so we complete the list here. + 'as', + 'async', + 'await', + 'from', + 'get', + 'let', + 'of', + 'set', + 'yield', +]); + +// Check duplications. +(function() { + KEYWORDS.sort(); + for (let i = 1; i < KEYWORDS.length; ++i) { + if (KEYWORDS[i] === KEYWORDS[i - 1]) { + throw new Error( + `Duplication was found in the keyword list: ${KEYWORDS[i]}`, + ); + } + } +})(); + //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -201,7 +228,7 @@ export default util.createRule({ const retv = Object.create(null); for (let i = 0; i < KEYWORDS.length; ++i) { - const key = KEYWORDS[i] as Keyword; + const key = KEYWORDS[i]; const override = overrides[key]; if (override) { diff --git a/packages/eslint-plugin/typings/eslint-keywords.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts index a40b568f33bd..2124fdd784b0 100644 --- a/packages/eslint-plugin/typings/eslint-keywords.d.ts +++ b/packages/eslint-plugin/typings/eslint-keywords.d.ts @@ -2,74 +2,3 @@ declare module 'eslint/lib/rules/utils/keywords' { const keywords: string[]; export default keywords; } - - -declare type Keyword = - | 'abstract' - | 'boolean' - | 'break' - | 'byte' - | 'case' - | 'catch' - | 'char' - | 'class' - | 'const' - | 'continue' - | 'debugger' - | 'default' - | 'delete' - | 'do' - | 'double' - | 'else' - | 'enum' - | 'export' - | 'extends' - | 'false' - | 'final' - | 'finally' - | 'float' - | 'for' - | 'function' - | 'goto' - | 'if' - | 'implements' - | 'import' - | 'in' - | 'instanceof' - | 'int' - | 'interface' - | 'long' - | 'native' - | 'new' - | 'null' - | 'package' - | 'private' - | 'protected' - | 'public' - | 'return' - | 'short' - | 'static' - | 'super' - | 'switch' - | 'synchronized' - | 'this' - | 'throw' - | 'throws' - | 'transient' - | 'true' - | 'try' - | 'typeof' - | 'var' - | 'void' - | 'volatile' - | 'while' - | 'with' - | 'as' - | 'async' - | 'await' - | 'from' - | 'get' - | 'let' - | 'of' - | 'set' - | 'yield'; diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 471335158e23..0bd21aa680e3 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -150,7 +150,7 @@ declare module 'eslint/lib/rules/keyword-spacing' { before: boolean; after: boolean; }>; - type OverrideOptions = Partial>; + type OverrideOptions = Partial>; type RootOption = Option & { overrides?: OverrideOptions }; type Options = [RootOption]; type MessageIds = From 80dcfe784aea02a28180458569cefb88594c4374 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Wed, 18 Mar 2020 20:37:33 +0100 Subject: [PATCH 24/31] linting --- packages/eslint-plugin/src/rules/keyword-spacing.ts | 2 +- packages/eslint-plugin/typings/eslint-keywords.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index 11c65a4c3f6e..ba54fe2e6f3c 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -37,7 +37,7 @@ const KEYWORDS = ESLINT_UTILS_KEYWORDS.concat([ ]); // Check duplications. -(function() { +(function(): void { KEYWORDS.sort(); for (let i = 1; i < KEYWORDS.length; ++i) { if (KEYWORDS[i] === KEYWORDS[i - 1]) { diff --git a/packages/eslint-plugin/typings/eslint-keywords.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts index 2124fdd784b0..3aae5fd9b590 100644 --- a/packages/eslint-plugin/typings/eslint-keywords.d.ts +++ b/packages/eslint-plugin/typings/eslint-keywords.d.ts @@ -1,4 +1,4 @@ declare module 'eslint/lib/rules/utils/keywords' { const keywords: string[]; - export default keywords; + export = keywords; } From 1cee759ee511b289bcce065c3ca103b069c5d044 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Wed, 18 Mar 2020 21:24:14 +0100 Subject: [PATCH 25/31] Added some tests to please the coverage check --- .../eslint-plugin/src/rules/keyword-spacing.ts | 8 ++++---- .../tests/rules/keyword-spacing.test.ts | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index ba54fe2e6f3c..c825e23efc2c 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -253,8 +253,8 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the previous token to check. */ - function checkSpacingBefore(token: TSESTree.Token, pattern?: RegExp): void { - checkMethodMap[token.value].before(token, pattern ?? PREV_TOKEN); + function checkSpacingBefore(token: TSESTree.Token): void { + checkMethodMap[token.value].before(token, PREV_TOKEN); } /** @@ -262,8 +262,8 @@ export default util.createRule({ * @param token A token to report. * @param pattern A pattern of the next token to check. */ - function checkSpacingAfter(token: TSESTree.Token, pattern?: RegExp): void { - checkMethodMap[token.value].after(token, pattern ?? NEXT_TOKEN); + function checkSpacingAfter(token: TSESTree.Token): void { + checkMethodMap[token.value].after(token, NEXT_TOKEN); } /** diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 04af96bc2b82..8e6b49fad9a6 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -31,7 +31,7 @@ const NEITHER = { before: false, after: false }; * @param value A value to override. * @returns An option object to test an 'overrides' option. */ -function override(keyword: string, value: Option): RootOption { +function overrides(keyword: string, value: Option): RootOption { return { before: value.before === false, after: value.after === false, @@ -99,12 +99,17 @@ ruleTester.run('keyword-spacing', rule, { }, { code: 'const foo = {} as {}', - options: [override('as', BOTH)], + options: [overrides('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, { code: 'const foo = {}as{}', - options: [override('as', NEITHER)], + options: [overrides('as', NEITHER)], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, + { + code: 'const foo = {} as {}', + options: [{ overrides: { as: {} } }], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, ], @@ -138,5 +143,11 @@ ruleTester.run('keyword-spacing', rule, { parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: unexpectedAfter('as'), }, + { + code: 'const foo = {} as{}', + options: [{ overrides: { as: {} } }], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: expectedAfter('as'), + }, ], }); From b2973c43d6ed33b3ef9cb42741ddc69df813ca3f Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Sun, 12 Apr 2020 13:01:44 +0200 Subject: [PATCH 26/31] Update packages/eslint-plugin/src/rules/keyword-spacing.ts Co-Authored-By: Brad Zacher --- .../eslint-plugin/src/rules/keyword-spacing.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index c825e23efc2c..a9a2bee77da3 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -23,7 +23,7 @@ const TEMPLATE_OPEN_PAREN = '${'; const TEMPLATE_CLOSE_PAREN = '}'; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; -const KEYWORDS = ESLINT_UTILS_KEYWORDS.concat([ +const KEYWORDS = new Set(ESLINT_UTILS_KEYWORDS.concat([ // Eslint Utils does no provide all keywords, so we complete the list here. 'as', 'async', @@ -34,19 +34,7 @@ const KEYWORDS = ESLINT_UTILS_KEYWORDS.concat([ 'of', 'set', 'yield', -]); - -// Check duplications. -(function(): void { - KEYWORDS.sort(); - for (let i = 1; i < KEYWORDS.length; ++i) { - if (KEYWORDS[i] === KEYWORDS[i - 1]) { - throw new Error( - `Duplication was found in the keyword list: ${KEYWORDS[i]}`, - ); - } - } -})(); +])); //------------------------------------------------------------------------------ // Helpers From 1a757d0909bd7ef2c9fb5e3e38ed80dea7589aa8 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Sun, 12 Apr 2020 13:02:24 +0200 Subject: [PATCH 27/31] Update packages/eslint-plugin/typings/eslint-rules.d.ts Co-Authored-By: Brad Zacher --- .../eslint-plugin/typings/eslint-rules.d.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 0bd21aa680e3..5d67ab5957f2 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -146,13 +146,16 @@ declare module 'eslint/lib/rules/keyword-spacing' { import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; import { RuleFunction } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; - type Option = Partial<{ - before: boolean; - after: boolean; - }>; - type OverrideOptions = Partial>; - type RootOption = Option & { overrides?: OverrideOptions }; - type Options = [RootOption]; + type Options = [ + { + before?: boolean; + after?: boolean; + overrides?: Record; + } + ]; type MessageIds = | 'expectedBefore' | 'expectedAfter' From c9795c73b912c4123c74a670fc20546e23dfd9f4 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Sun, 12 Apr 2020 13:03:05 +0200 Subject: [PATCH 28/31] Update packages/eslint-plugin/src/rules/keyword-spacing.ts Co-Authored-By: Brad Zacher --- packages/eslint-plugin/src/rules/keyword-spacing.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index a9a2bee77da3..cdc4731459b1 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -7,12 +7,6 @@ import { import { isTokenOnSameLine } from '../util/astUtils'; import * as util from '../util'; -export type Option = Partial<{ - before: boolean; - after: boolean; -}>; -export type OverrideOptions = Partial>; -export type RootOption = Option & { overrides?: OverrideOptions }; export type Options = util.InferOptionsTypeFromRule; export type MessageIds = util.InferMessageIdsTypeFromRule; From 4dd789eac314145bb9da648bdf3a1b0bde92bc55 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Sun, 12 Apr 2020 13:22:50 +0200 Subject: [PATCH 29/31] Stuff --- .../src/rules/keyword-spacing.ts | 267 ++---------------- .../tests/rules/keyword-spacing.test.ts | 40 +-- .../typings/eslint-keywords.d.ts | 4 - .../eslint-plugin/typings/eslint-rules.d.ts | 19 +- 4 files changed, 53 insertions(+), 277 deletions(-) delete mode 100644 packages/eslint-plugin/typings/eslint-keywords.d.ts diff --git a/packages/eslint-plugin/src/rules/keyword-spacing.ts b/packages/eslint-plugin/src/rules/keyword-spacing.ts index cdc4731459b1..8c4ff1d38ff6 100644 --- a/packages/eslint-plugin/src/rules/keyword-spacing.ts +++ b/packages/eslint-plugin/src/rules/keyword-spacing.ts @@ -1,63 +1,10 @@ +import { AST_TOKEN_TYPES } from '@typescript-eslint/experimental-utils'; import baseRule from 'eslint/lib/rules/keyword-spacing'; -import ESLINT_UTILS_KEYWORDS from 'eslint/lib/rules/utils/keywords'; -import { - TSESTree, - AST_TOKEN_TYPES, -} from '@typescript-eslint/experimental-utils'; -import { isTokenOnSameLine } from '../util/astUtils'; import * as util from '../util'; - export type Options = util.InferOptionsTypeFromRule; export type MessageIds = util.InferMessageIdsTypeFromRule; -const PREV_TOKEN = /^[)\]}>]$/u; -const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; -const TEMPLATE_OPEN_PAREN = '${'; -const TEMPLATE_CLOSE_PAREN = '}'; -const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u; - -const KEYWORDS = new Set(ESLINT_UTILS_KEYWORDS.concat([ - // Eslint Utils does no provide all keywords, so we complete the list here. - 'as', - 'async', - 'await', - 'from', - 'get', - 'let', - 'of', - 'set', - 'yield', -])); - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Checks whether or not a given token is a "Template" token ends with "${". - * @param token A token to check. - * @returns `true` if the token is a "Template" token ends with "${". - */ -function isOpenParenOfTemplate(token: TSESTree.Token): boolean { - return ( - token.type === AST_TOKEN_TYPES.Template && - token.value.startsWith(TEMPLATE_OPEN_PAREN) - ); -} - -/** - * Checks whether or not a given token is a "Template" token starts with "}". - * @param token A token to check. - * @returns `true` if the token is a "Template" token starts with "}". - */ -function isCloseParenOfTemplate(token: TSESTree.Token): boolean { - return ( - token.type === AST_TOKEN_TYPES.Template && - token.value.endsWith(TEMPLATE_CLOSE_PAREN) - ); -} - export default util.createRule({ name: 'keyword-spacing', meta: { @@ -77,199 +24,29 @@ export default util.createRule({ create(context) { const sourceCode = context.getSourceCode(); const baseRules = baseRule.create(context); - - /** - * Reports a given token if there are not space(s) before the token. - * @param token A token to report. - * @param pattern A pattern of the previous token to check. - */ - function expectSpaceBefore(token: TSESTree.Token, pattern: RegExp): void { - const prevToken = sourceCode.getTokenBefore(token); - - if ( - prevToken && - (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && - !isOpenParenOfTemplate(prevToken) && - isTokenOnSameLine(prevToken, token) && - !sourceCode.isSpaceBetweenTokens(prevToken, token) - ) { - context.report({ - loc: token.loc.start, - messageId: 'expectedBefore', - data: { - value: token.value, - }, - fix(fixer) { - return fixer.insertTextBefore(token, ' '); - }, - }); - } - } - - /** - * Reports a given token if there are space(s) before the token. - * @param token A token to report. - * @param pattern A pattern of the previous token to check. - */ - function unexpectSpaceBefore(token: TSESTree.Token, pattern: RegExp): void { - const prevToken = sourceCode.getTokenBefore(token); - - if ( - prevToken && - (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && - !isOpenParenOfTemplate(prevToken) && - isTokenOnSameLine(prevToken, token) && - sourceCode.isSpaceBetweenTokens(prevToken, token) - ) { - context.report({ - loc: token.loc.start, - messageId: 'unexpectedBefore', - data: { - value: token.value, - }, - fix(fixer) { - return fixer.removeRange([prevToken.range[1], token.range[0]]); - }, - }); - } - } - - /** - * Reports a given token if there are not space(s) after the token. - * @param token A token to report. - * @param pattern A pattern of the next token to check. - */ - function expectSpaceAfter(token: TSESTree.Token, pattern: RegExp): void { - const nextToken = sourceCode.getTokenAfter(token); - - if ( - nextToken && - (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && - !isCloseParenOfTemplate(nextToken) && - isTokenOnSameLine(token, nextToken) && - !sourceCode.isSpaceBetweenTokens(token, nextToken) - ) { - context.report({ - loc: token.loc.start, - messageId: 'expectedAfter', - data: { - value: token.value, - }, - fix(fixer) { - return fixer.insertTextAfter(token, ' '); - }, - }); - } - } - - /** - * Reports a given token if there are space(s) after the token. - * @param token A token to report. - * @param pattern A pattern of the next token to check. - */ - function unexpectSpaceAfter(token: TSESTree.Token, pattern: RegExp): void { - const nextToken = sourceCode.getTokenAfter(token); - - if ( - nextToken && - (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && - !isCloseParenOfTemplate(nextToken) && - isTokenOnSameLine(token, nextToken) && - sourceCode.isSpaceBetweenTokens(token, nextToken) - ) { - context.report({ - loc: token.loc.start, - messageId: 'unexpectedAfter', - data: { - value: token.value, - }, - fix(fixer) { - return fixer.removeRange([token.range[1], nextToken.range[0]]); - }, - }); - } - } - - /** - * Parses the option object and determines check methods for each keyword. - * @param options The option object to parse. - * @returns Normalized option object. - * Keys are keywords (there are for every keyword). - * Values are instances of `{"before": function, "after": function}`. - */ - function parseOptions( - options: RootOption = {}, - ): { [keyword: string]: { before: Function; after: Function } } { - const before = options.before !== false; - const after = options.after !== false; - const defaultValue = { - before: before ? expectSpaceBefore : unexpectSpaceBefore, - after: after ? expectSpaceAfter : unexpectSpaceAfter, - }; - const overrides: OverrideOptions = options?.overrides ?? {}; - const retv = Object.create(null); - - for (let i = 0; i < KEYWORDS.length; ++i) { - const key = KEYWORDS[i]; - const override = overrides[key]; - - if (override) { - const thisBefore = 'before' in override ? override.before : before; - const thisAfter = 'after' in override ? override.after : after; - - retv[key] = { - before: thisBefore ? expectSpaceBefore : unexpectSpaceBefore, - after: thisAfter ? expectSpaceAfter : unexpectSpaceAfter, - }; - } else { - retv[key] = defaultValue; - } - } - return retv; - } - - const checkMethodMap = parseOptions(context.options[0]); - - /** - * Reports a given token if usage of spacing followed by the token is invalid. - * @param token A token to report. - * @param pattern A pattern of the previous token to check. - */ - function checkSpacingBefore(token: TSESTree.Token): void { - checkMethodMap[token.value].before(token, PREV_TOKEN); - } - - /** - * Reports a given token if usage of spacing preceded by the token is invalid. - * @param token A token to report. - * @param pattern A pattern of the next token to check. - */ - function checkSpacingAfter(token: TSESTree.Token): void { - checkMethodMap[token.value].after(token, NEXT_TOKEN); - } - - /** - * Reports a given token if usage of spacing around the token is invalid. - * @param token A token to report. - */ - function checkSpacingAround(token: TSESTree.Token): void { - checkSpacingBefore(token); - checkSpacingAfter(token); - } - - /** - * Reports `as` keyword of a given node if usage of spacing before - * this keyword is invalid. - * @param node A node to report. - */ - function checkSpacingForAsExpression(node: TSESTree.TSAsExpression): void { - const token = sourceCode.getTokenAfter(node.expression)!; // get the `as` identifier. - checkSpacingAround(token); - } - return { ...baseRules, - TSAsExpression: checkSpacingForAsExpression, + TSAsExpression(node): void { + const asToken = util.nullThrows( + sourceCode.getTokenAfter( + node.expression, + token => token.value === 'as', + ), + util.NullThrowsReasons.MissingToken('as', node.type), + ); + const oldTokenType = asToken.type; + // as is a contextual keyword, so it's always reported as an Identifier + // the rule looks for keyword tokens, so we temporarily override it + // we mutate it at the token level because the rule calls sourceCode.getFirstToken, + // so mutating a copy would not change the underlying copy returned by that method + asToken.type = AST_TOKEN_TYPES.Keyword; + + // use this selector just because it is just a call to `checkSpacingAroundFirstToken` + baseRules.DebuggerStatement(asToken as never); + + // make sure to reset the type afterward so we don't permanently mutate the AST + asToken.type = oldTokenType; + }, }; }, }); diff --git a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts index 8e6b49fad9a6..987caebb1e43 100644 --- a/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/keyword-spacing.test.ts @@ -1,9 +1,9 @@ +/* eslint-disable eslint-comments/no-use */ +// this rule tests the spacing, which prettier will want to fix and break the tests +/* eslint "@typescript-eslint/internal/plugin-test-formatting": ["error", { formatWithPrettier: false }] */ +/* eslint-enable eslint-comments/no-use */ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import rule, { - Option, - RootOption, - MessageIds, -} from '../../src/rules/keyword-spacing'; +import rule, { MessageIds, Options } from '../../src/rules/keyword-spacing'; import { RuleTester } from '../RuleTester'; //------------------------------------------------------------------------------ @@ -31,7 +31,7 @@ const NEITHER = { before: false, after: false }; * @param value A value to override. * @returns An option object to test an 'overrides' option. */ -function overrides(keyword: string, value: Option): RootOption { +function overrides(keyword: string, value: Options[0]): Options[0] { return { before: value.before === false, after: value.after === false, @@ -89,26 +89,26 @@ ruleTester.run('keyword-spacing', rule, { // as (typing) //---------------------------------------------------------------------- { - code: 'const foo = {} as {}', + code: 'const foo = {} as {};', parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, { - code: 'const foo = {}as{}', + code: 'const foo = {}as{};', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, { - code: 'const foo = {} as {}', + code: 'const foo = {} as {};', options: [overrides('as', BOTH)], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, { - code: 'const foo = {}as{}', + code: 'const foo = {}as{};', options: [overrides('as', NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, { - code: 'const foo = {} as {}', + code: 'const foo = {} as {};', options: [{ overrides: { as: {} } }], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, @@ -118,33 +118,33 @@ ruleTester.run('keyword-spacing', rule, { // as (typing) //---------------------------------------------------------------------- { - code: 'const foo = {}as {}', - output: 'const foo = {} as {}', + code: 'const foo = {}as {};', + output: 'const foo = {} as {};', parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: expectedBefore('as'), }, { - code: 'const foo = {} as{}', - output: 'const foo = {}as{}', + code: 'const foo = {} as{};', + output: 'const foo = {}as{};', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: unexpectedBefore('as'), }, { - code: 'const foo = {} as{}', - output: 'const foo = {} as {}', + code: 'const foo = {} as{};', + output: 'const foo = {} as {};', parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: expectedAfter('as'), }, { - code: 'const foo = {}as {}', - output: 'const foo = {}as{}', + code: 'const foo = {}as {};', + output: 'const foo = {}as{};', options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: unexpectedAfter('as'), }, { - code: 'const foo = {} as{}', + code: 'const foo = {} as{};', options: [{ overrides: { as: {} } }], parserOptions: { ecmaVersion: 6, sourceType: 'module' }, errors: expectedAfter('as'), diff --git a/packages/eslint-plugin/typings/eslint-keywords.d.ts b/packages/eslint-plugin/typings/eslint-keywords.d.ts deleted file mode 100644 index 3aae5fd9b590..000000000000 --- a/packages/eslint-plugin/typings/eslint-keywords.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'eslint/lib/rules/utils/keywords' { - const keywords: string[]; - export = keywords; -} diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 5d67ab5957f2..ac8700d42e56 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -147,14 +147,17 @@ declare module 'eslint/lib/rules/keyword-spacing' { import { RuleFunction } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; type Options = [ - { - before?: boolean; - after?: boolean; - overrides?: Record; - } + { + before?: boolean; + after?: boolean; + overrides?: Record< + string, + { + before?: boolean; + after?: boolean; + } + >; + }, ]; type MessageIds = | 'expectedBefore' From c26af99fc55257614e97297dc71f784bd0e33122 Mon Sep 17 00:00:00 2001 From: Pascal Heitz Date: Mon, 13 Apr 2020 16:29:30 +0200 Subject: [PATCH 30/31] Apparently these tools dont like force-push From 0715791c39e03ba260b0987b6ff6eca7a99069b2 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sun, 19 Apr 2020 21:59:39 -0700 Subject: [PATCH 31/31] Update keyword-spacing.md --- .../docs/rules/keyword-spacing.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index ff96657f67ae..ca2926d6c825 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -1,26 +1,8 @@ # Enforce consistent spacing before and after keywords (`keyword-spacing`) -Keywords are syntax elements of JavaScript, such as `try` and `if`. -These keywords have special meaning to the language and so often appear in a different color in code editors. -As an important part of the language, style guides often refer to the spacing that should be used around keywords. -For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean `if-else` statements must look like this: - -```js -if (foo) { - // ... -} else { - // ... -} -``` - -Of course, you could also have a style guide that disallows spaces around keywords. - -However, if you want to enforce the style of spacing between the `function` keyword and the following opening parenthesis, please refer to [space-before-function-paren](space-before-function-paren.md). - ## Rule Details This rule extends the base [`eslint/keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing) rule. -It supports all options and features of the base rule. This version adds support for generic type parameters on function calls. ## How to use pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy