Skip to content

Commit 86ab57b

Browse files
MatissJanismatt-fidd
authored andcommitted
Patch tests
1 parent 572f6d0 commit 86ab57b

File tree

6 files changed

+319
-220
lines changed

6 files changed

+319
-220
lines changed

packages/eslint-plugin-actual/lib/rules/__tests__/prefer-if-statement.js

Lines changed: 0 additions & 138 deletions
This file was deleted.

packages/eslint-plugin-actual/lib/rules/__tests__/typography.js

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* eslint-disable rulesdir/typography */
2+
3+
//------------------------------------------------------------------------------
4+
// Requirements
5+
//------------------------------------------------------------------------------
6+
7+
import { runClassic } from 'eslint-vitest-rule-tester';
8+
9+
import * as rule from './prefer-if-statement';
10+
11+
//------------------------------------------------------------------------------
12+
// Tests
13+
//------------------------------------------------------------------------------
14+
15+
runClassic(
16+
'prefer-if-statement',
17+
rule,
18+
{
19+
valid: [
20+
`if (foo && bar) { console.log('Hello, world!'); }`,
21+
`myFunc(foo && bar);`,
22+
`if (foo || bar) { console.log('Hello, world!'); }`,
23+
`myFunc(foo || bar);`,
24+
`if (foo ? bar : baz) { console.log('Hello, world!'); }`,
25+
`<div>{foo && bar}</div>`,
26+
`<div>{foo || bar}</div>`,
27+
`<div>{foo ? bar : baz}</div>`,
28+
],
29+
30+
invalid: [
31+
{
32+
code: 'foo && bar;',
33+
output: null,
34+
errors: [
35+
{
36+
messageId: 'logical',
37+
data: { op: '&&' },
38+
type: 'ExpressionStatement',
39+
},
40+
],
41+
},
42+
{
43+
code: 'foo || bar;',
44+
output: null,
45+
errors: [
46+
{
47+
messageId: 'logical',
48+
data: { op: '||' },
49+
type: 'ExpressionStatement',
50+
},
51+
],
52+
},
53+
{
54+
code: 'foo ? bar : baz;',
55+
output: null,
56+
errors: [{ messageId: 'ternary', type: 'ExpressionStatement' }],
57+
},
58+
{
59+
code: 'function foo() { bar && baz; }',
60+
output: null,
61+
errors: [
62+
{
63+
messageId: 'logical',
64+
data: { op: '&&' },
65+
type: 'ExpressionStatement',
66+
},
67+
],
68+
},
69+
{
70+
code: 'function foo() { bar || baz; }',
71+
output: null,
72+
errors: [
73+
{
74+
messageId: 'logical',
75+
data: { op: '||' },
76+
type: 'ExpressionStatement',
77+
},
78+
],
79+
},
80+
{
81+
code: 'function foo() { bar ? baz : qux; }',
82+
output: null,
83+
errors: [{ messageId: 'ternary', type: 'ExpressionStatement' }],
84+
},
85+
{
86+
code: 'foo && foo();',
87+
output: 'foo?.();',
88+
errors: [
89+
{
90+
messageId: 'logical',
91+
data: { op: '&&' },
92+
type: 'ExpressionStatement',
93+
},
94+
],
95+
},
96+
{
97+
code: 'foo || foo();',
98+
output: null,
99+
errors: [
100+
{
101+
messageId: 'logical',
102+
data: { op: '||' },
103+
type: 'ExpressionStatement',
104+
},
105+
],
106+
},
107+
{
108+
code: 'foo.bar && foo.bar();',
109+
output: 'foo.bar?.();',
110+
errors: [
111+
{
112+
messageId: 'logical',
113+
data: { op: '&&' },
114+
type: 'ExpressionStatement',
115+
},
116+
],
117+
},
118+
{
119+
code: 'foo.bar && foo.bar.baz();',
120+
output: 'foo.bar?.baz();',
121+
errors: [
122+
{
123+
messageId: 'logical',
124+
data: { op: '&&' },
125+
type: 'ExpressionStatement',
126+
},
127+
],
128+
},
129+
{
130+
code: 'foo ? bar() : baz();',
131+
output: null,
132+
errors: [{ messageId: 'ternary', type: 'ExpressionStatement' }],
133+
},
134+
],
135+
},
136+
{
137+
parserOptions: {
138+
ecmaVersion: 2020,
139+
ecmaFeatures: { jsx: true },
140+
},
141+
},
142+
);

0 commit comments

Comments
 (0)