Skip to content

Commit

Permalink
more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
Omri Luzon committed Dec 16, 2022
1 parent 415733a commit 725d8a9
Showing 1 changed file with 30 additions and 43 deletions.
73 changes: 30 additions & 43 deletions packages/eslint-plugin/tests/rules/block-spacing.test.ts
Expand Up @@ -34,6 +34,7 @@ const typeDeclarations = [
];
const emptyBlocks = ['{}', '{ }'];
const singlePropertyBlocks = ['{bar: true}', '{ bar: true }'];
const blockComment = '/* comment */';

ruleTester.run('block-spacing', rule, {
valid: [
Expand Down Expand Up @@ -110,49 +111,35 @@ ruleTester.run('block-spacing', rule, {
);
}),
),

// With block comments
...typeDeclarations.flatMap<InvalidBlockSpacingTestCase>(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<InvalidBlockSpacingTestCase>(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: '}' },
},
],
},
];
}),
),
],
});

0 comments on commit 725d8a9

Please sign in to comment.