Skip to content

Commit 884ac7f

Browse files
authored
feat(consistent-list-newline): support if statement (#47)
1 parent e4fa7a5 commit 884ac7f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/rules/__snapshots__/consistent-list-newline.test.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,13 @@ a,
173173
b
174174
]) => {})"
175175
`;
176+
177+
exports[`consistent-list-newline > invalid > Invalid #28: if (
178+
a) {} 1`] = `
179+
"if (
180+
a
181+
) {}"
182+
`;
183+
184+
exports[`consistent-list-newline > invalid > Invalid #29: if (a
185+
) {} 1`] = `"if (a) {}"`;

src/rules/consistent-list-newline.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { run } from './_test'
66
import rule, { RULE_NAME } from './consistent-list-newline'
77

88
const valids: ValidTestCase[] = [
9+
'if (a) {}',
10+
'if (\na\n) {}',
911
'const a = { foo: "bar", bar: 2 }',
1012
'const a = {\nfoo: "bar",\nbar: 2\n}',
1113
'const a = [1, 2, 3]',
@@ -275,6 +277,8 @@ const invalid: InvalidTestCase[] = [
275277
'const {a,\nb\n} = c',
276278
'const [\na,b] = c',
277279
'foo(([\na,b]) => {})',
280+
'if (\na) {}',
281+
'if (a\n) {}',
278282

279283
{
280284
description: 'CRLF',

src/rules/consistent-list-newline.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type Options = [{
1313
ExportNamedDeclaration?: boolean
1414
FunctionDeclaration?: boolean
1515
FunctionExpression?: boolean
16+
IfStatement?: boolean
1617
ImportDeclaration?: boolean
1718
JSONArrayExpression?: boolean
1819
JSONObjectExpression?: boolean
@@ -46,6 +47,7 @@ export default createEslintRule<Options, MessageIds>({
4647
ExportNamedDeclaration: { type: 'boolean' },
4748
FunctionDeclaration: { type: 'boolean' },
4849
FunctionExpression: { type: 'boolean' },
50+
IfStatement: { type: 'boolean' },
4951
ImportDeclaration: { type: 'boolean' },
5052
JSONArrayExpression: { type: 'boolean' },
5153
JSONObjectExpression: { type: 'boolean' },
@@ -72,6 +74,7 @@ export default createEslintRule<Options, MessageIds>({
7274
const multilineNodes = new Set([
7375
'ArrayExpression',
7476
'FunctionDeclaration',
77+
'IfStatement',
7578
'ObjectExpression',
7679
'ObjectPattern',
7780
'TSTypeLiteral',
@@ -262,6 +265,9 @@ export default createEslintRule<Options, MessageIds>({
262265
node.returnType || node.body,
263266
)
264267
},
268+
IfStatement: (node) => {
269+
check(node, [node.test])
270+
},
265271
ArrowFunctionExpression: (node) => {
266272
if (node.params.length <= 1)
267273
return

0 commit comments

Comments
 (0)