From 725d8a9bae5181b955145ca08a0334cc6da58e2c Mon Sep 17 00:00:00 2001 From: Omri Luzon Date: Sat, 17 Dec 2022 01:42:23 +0200 Subject: [PATCH] more concise --- .../tests/rules/block-spacing.test.ts | 73 ++++++++----------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/block-spacing.test.ts b/packages/eslint-plugin/tests/rules/block-spacing.test.ts index 64840461adb..49578b8c061 100644 --- a/packages/eslint-plugin/tests/rules/block-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/block-spacing.test.ts @@ -34,6 +34,7 @@ const typeDeclarations = [ ]; const emptyBlocks = ['{}', '{ }']; const singlePropertyBlocks = ['{bar: true}', '{ bar: true }']; +const blockComment = '/* comment */'; ruleTester.run('block-spacing', rule, { valid: [ @@ -110,49 +111,35 @@ ruleTester.run('block-spacing', rule, { ); }), ), - // With block comments - ...typeDeclarations.flatMap(typeDec => { - const property = - typeDec.nodeType === AST_NODE_TYPES.TSEnumDeclaration - ? 'bar = 1' - : 'bar: true;'; - return [ - { - code: `${typeDec.stringPrefix}{ /* comment */ ${property} /* comment */ } /* never */`, - output: `${typeDec.stringPrefix}{/* comment */ ${property} /* comment */} /* never */`, - options: ['never'], - errors: [ - { - type: typeDec.nodeType, - messageId: 'extra', - data: { location: 'after', token: '{' }, - }, - { - type: typeDec.nodeType, - messageId: 'extra', - data: { location: 'before', token: '}' }, - }, - ], - }, - { - code: `${typeDec.stringPrefix}{/* comment */ ${property} /* comment */} /* always */`, - output: `${typeDec.stringPrefix}{ /* comment */ ${property} /* comment */ } /* always */`, - options: ['always'], - errors: [ - { - type: typeDec.nodeType, - messageId: 'missing', - data: { location: 'after', token: '{' }, - }, - { - type: typeDec.nodeType, - messageId: 'missing', - data: { location: 'before', token: '}' }, - }, - ], - }, - ]; - }), + ...options.flatMap(option => + typeDeclarations.flatMap(typeDec => { + const property = + typeDec.nodeType === AST_NODE_TYPES.TSEnumDeclaration + ? 'bar = 1' + : 'bar: true;'; + const alwaysSpace = option === 'always' ? '' : ' '; + const neverSpace = option === 'always' ? ' ' : ''; + return [ + { + code: `${typeDec.stringPrefix}{${alwaysSpace}${blockComment}${property}${blockComment}${alwaysSpace}} /* ${option} */`, + output: `${typeDec.stringPrefix}{${neverSpace}${blockComment}${property}${blockComment}${neverSpace}} /* ${option} */`, + options: [option], + errors: [ + { + type: typeDec.nodeType, + messageId: option === 'always' ? 'missing' : 'extra', + data: { location: 'after', token: '{' }, + }, + { + type: typeDec.nodeType, + messageId: option === 'always' ? 'missing' : 'extra', + data: { location: 'before', token: '}' }, + }, + ], + }, + ]; + }), + ), ], });