|
1 | | -// This can be a single line |
2 | | -const arr = ['first', 'second'] |
| 1 | +/* eslint-disable no-unused-vars */ |
3 | 2 |
|
4 | | -// This is not a single line already and should be one element per line |
5 | | -const arr2 = [ |
| 3 | +// ❌ Trailing comma is required to make multi-line array diff-safe on changing the last element |
| 4 | +// Here the trailing comma is missing on a multi-line array and extra comma is present on a single-line array |
| 5 | +const items = [ |
6 | 6 | 'first', |
7 | 7 | 'second', |
8 | 8 | 'third', |
9 | | - 'and', |
10 | | - 'so', |
11 | | - 'on', |
12 | 9 | ] |
| 10 | +const LATIN_VOWELS = ['a', 'e', 'i', 'o', 'u'] |
13 | 11 |
|
14 | | -// This has a missing trailing comma causing too much git diff |
15 | | -const arr3 = [ |
16 | | - 'first', |
17 | | - 'second', |
18 | | - 'third', |
| 12 | +// ❌ Multi-line array should have a single element per line to make it diff-safe and readable |
| 13 | +// Here the last two elements are on the same line |
| 14 | +const VARIANTS = [ |
| 15 | + 'primary', |
| 16 | + 'secondary', |
| 17 | + 'tertiary', |
| 18 | + 'tertiary-no-background', |
| 19 | +] |
| 20 | + |
| 21 | +// ✅ In general it is recommended to prefer a multi-line array to make it diff-safe on adding/removing elements |
| 22 | +// It is especially important for dynamic array which entries may change |
| 23 | +const sampleUsers = [ |
| 24 | + 'admin', |
| 25 | + 'alice', |
| 26 | + 'bob', |
| 27 | +] |
| 28 | +// Even if there is only one element at the moment (more elements may be added later) |
| 29 | +const MUTE_NOTIFICATIONS_USER_STATUSES = [ |
| 30 | + 'dnd', |
| 31 | +] |
| 32 | + |
| 33 | +// ✅ Single-line arrays are also fine for short and stable arrays which are not expected to change |
| 34 | +// This is a developer's choice |
| 35 | +const selectedItems = ['default_item'] |
| 36 | +const HTML_FORM_ACTIONS = ['POST', 'GET'] |
| 37 | + |
| 38 | +// ❌ Single-line array should have brackets on the same line while multi-line array should have brackets on the next line |
| 39 | +const USER_STATUSES = [ |
| 40 | + 'online', |
| 41 | + 'away', |
| 42 | + 'dnd', |
| 43 | + 'invisible', |
| 44 | + 'offline', |
19 | 45 | ] |
| 46 | +// 🚧 Currently this is an edge case and isn't fixed properly... |
| 47 | +const WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] |
0 commit comments