@rainstormy/presets-biome 2.0.0-alpha.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -68
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
# Opinionated Presets for Biome
|
|
2
2
|
|
|
3
3
|
This package provides predefined, opinionated [Biome](https://biomejs.dev)
|
|
4
|
-
configurations
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
configurations carefully crafted for
|
|
5
|
+
modern [TypeScript](https://www.typescriptlang.org) projects with add-ons
|
|
6
|
+
for [Next.js](https://nextjs.org), [React Router](https://reactrouter.com),
|
|
7
|
+
[Storybook](https://storybook.js.org), and [Vitest](https://vitest.dev).
|
|
7
8
|
|
|
8
9
|
## Code style
|
|
9
|
-
The preset configurations apply the default formatting and
|
|
10
|
-
Biome with a few twists:
|
|
10
|
+
The preset configurations apply the default formatting and enable most linting
|
|
11
|
+
rules in Biome with a few twists:
|
|
11
12
|
|
|
12
|
-
- **Locate source code in the `src` directory** to
|
|
13
|
-
|
|
13
|
+
- **Locate source code in the `src` directory** to improve discoverability and
|
|
14
|
+
scalability by simplifying glob patterns and giving all projects a consistent
|
|
15
|
+
structure.
|
|
14
16
|
- **Omit semicolons** and rely fully
|
|
15
17
|
on [automatic semicolon insertion](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion)
|
|
16
|
-
to reduce visual noise in the code. Using semicolons
|
|
17
|
-
behaviour of automatic semicolon insertion anyway.
|
|
18
|
+
to reduce cognitive complexity and visual noise in the code. Using semicolons
|
|
19
|
+
does not disable the behaviour of automatic semicolon insertion anyway. See
|
|
20
|
+
also [Hacking Semicolons](https://slides.com/evanyou/semicolons) by Evan You.
|
|
18
21
|
- **Use the generic `Array<T>` type** instead of the shorthand `T[]` syntax to
|
|
19
22
|
make arrays of union types cleaner and to remain consistent with other
|
|
20
23
|
built-in types such as `Set<T>`, `Map<K, V>`, and `Promise<T>`.
|
|
21
|
-
- **Use
|
|
22
|
-
with
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
- **Use the `type` alias syntax** instead of the `interface` syntax to improve
|
|
25
|
+
flexibility with union types, intersection types, and generic wrapper types
|
|
26
|
+
such as `Readonly<T>` and `Partial<T>`.
|
|
27
|
+
- **Access JSX component props directly on the `props` object** (including React
|
|
28
|
+
components) instead of destructuring it to avoid duplicating the prop names in
|
|
29
|
+
type declarations.
|
|
30
|
+
- **Use a top-down declaration order** to improve readability and reduce
|
|
31
|
+
cognitive complexity by sticking to a predictable declaration order. See also
|
|
32
|
+
the [Stepdown Rule](https://dzone.com/articles/the-stepdown-rule), originally
|
|
33
|
+
described in Clean Code by Robert C. Martin (a.k.a. Uncle Bob).
|
|
34
|
+
- **Use `function` declarations** instead of `const` with arrow functions to
|
|
35
|
+
improve type safety and to enable top-down declaration orders, as function
|
|
36
|
+
declarations are hoisted.
|
|
37
|
+
- **Import `devDependencies` only in non-production code** such as configuration
|
|
38
|
+
files and tests to prevent accidental bundling of development dependencies in
|
|
39
|
+
production artefacts.
|
|
40
|
+
- **Use PascalCase for filenames** to reduce cognitive complexity by sticking to
|
|
41
|
+
a simple naming convention that is consistent with type names and component
|
|
42
|
+
names.
|
|
40
43
|
|
|
41
44
|
> [!NOTE]
|
|
42
|
-
> Biome uses **tabs** for indentation to
|
|
43
|
-
>
|
|
45
|
+
> Biome uses **tabs** for indentation to improve developers' accessibility
|
|
46
|
+
> through customisable indentation widths, to reduce the number of required
|
|
44
47
|
> keystrokes, and to reduce the file sizes.
|
|
45
48
|
|
|
46
49
|
## Installation
|
|
@@ -59,57 +62,50 @@ yarn add --dev @biomejs/biome @rainstormy/presets-biome
|
|
|
59
62
|
```
|
|
60
63
|
|
|
61
64
|
## Usage
|
|
62
|
-
Create a [`biome.json`](https://biomejs.dev/reference/configuration) file
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| Configuration | Description |
|
|
70
|
-
|------------------------------------------|----------------------------------------------------------------------------------|
|
|
71
|
-
| `@rainstormy/presets-biome/nextjs` | Adds support for [Next.js](https://nextjs.org) apps using the app router. |
|
|
72
|
-
| `@rainstormy/presets-biome/react-router` | Adds support for [React Router](https://reactrouter.com) apps using file routes. |
|
|
73
|
-
| `@rainstormy/presets-biome/storybook` | Adds support for CSF3-based stories in [Storybook](https://storybook.js.org). |
|
|
74
|
-
| `@rainstormy/presets-biome/vitest` | Adds support for unit test suites in [Vitest](https://vitest.dev). |
|
|
75
|
-
|
|
76
|
-
You can override the predefined settings by specifying the desired options like
|
|
77
|
-
`files` and `overrides` as usual.
|
|
78
|
-
|
|
79
|
-
For example:
|
|
65
|
+
Create a [`biome.json`](https://biomejs.dev/reference/configuration) file (or a
|
|
66
|
+
`biome.jsonc` file)
|
|
67
|
+
and [extend](https://biomejs.dev/guides/configure-biome/#share-a-configuration-file)
|
|
68
|
+
`@rainstormy/presets-biome/2.2` to enable the opinionated formatting and linting
|
|
69
|
+
configuration in general. Specify other options like `files` and `overrides` as
|
|
70
|
+
usual. For example:
|
|
80
71
|
|
|
81
72
|
```json
|
|
82
73
|
{
|
|
83
|
-
"$schema": "https://biomejs.dev/schemas/
|
|
74
|
+
"$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
|
|
84
75
|
"extends": [
|
|
85
|
-
"@rainstormy/presets-biome/
|
|
86
|
-
"@rainstormy/presets-biome/nextjs",
|
|
87
|
-
"@rainstormy/presets-biome/storybook",
|
|
88
|
-
"@rainstormy/presets-biome/vitest"
|
|
76
|
+
"@rainstormy/presets-biome/2.2"
|
|
89
77
|
],
|
|
90
78
|
"files": {
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
79
|
+
"includes": [
|
|
80
|
+
".github/**",
|
|
81
|
+
".vscode/**",
|
|
82
|
+
"src/**",
|
|
83
|
+
"*.{js,json,jsonc,ts}"
|
|
84
|
+
]
|
|
97
85
|
},
|
|
98
86
|
"overrides": [
|
|
99
87
|
{
|
|
100
|
-
"
|
|
88
|
+
"includes": ["src/**/*.tsx"],
|
|
101
89
|
"linter": {
|
|
102
90
|
"rules": {
|
|
103
91
|
"correctness": {
|
|
104
|
-
"
|
|
92
|
+
"noRestrictedElements": {
|
|
93
|
+
"level": "warn",
|
|
94
|
+
"options": {
|
|
95
|
+
"elements": {
|
|
96
|
+
"a": "Use <Hyperlink> instead of <a>"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"style": {
|
|
102
|
+
"noRestrictedImports": {
|
|
105
103
|
"level": "warn",
|
|
106
104
|
"options": {
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
]
|
|
105
|
+
"paths": {
|
|
106
|
+
"next/image": "Use <FancyImage> instead of <NextImage>",
|
|
107
|
+
"next/script": "Use <FancyScript> instead of <NextScript>"
|
|
108
|
+
}
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
}
|
|
@@ -120,7 +116,103 @@ For example:
|
|
|
120
116
|
}
|
|
121
117
|
```
|
|
122
118
|
|
|
119
|
+
> [!TIP]
|
|
120
|
+
> Explicitly specified options in `biome.json` take precedence over the presets
|
|
121
|
+
> in `extends`.
|
|
122
|
+
|
|
123
|
+
### [Next.js](https://nextjs.org)
|
|
124
|
+
Add `@rainstormy/presets-biome/2.2/nextjs` to the `extends` array to support the
|
|
125
|
+
app router and React components in Next.js apps:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"extends": [
|
|
130
|
+
"@rainstormy/presets-biome/2.2",
|
|
131
|
+
"@rainstormy/presets-biome/2.2/nextjs"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `app` directory and the `instrumentation.ts` and `middleware.ts` files must
|
|
137
|
+
reside in the `src` directory. React components and other files in general must
|
|
138
|
+
_not_ reside in the `app` directory to improve the scalability of the project.
|
|
139
|
+
|
|
140
|
+
### [React Router](https://reactrouter.com)
|
|
141
|
+
Add `@rainstormy/presets-biome/2.2/react-router` to the `extends` array to
|
|
142
|
+
support file routes and React components in React Router apps:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"extends": [
|
|
147
|
+
"@rainstormy/presets-biome/2.2",
|
|
148
|
+
"@rainstormy/presets-biome/2.2/react-router"
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The `routes` directory and the `root.tsx` and `routes.ts` files must reside in
|
|
154
|
+
the `src` directory.
|
|
155
|
+
|
|
156
|
+
### [Storybook](https://storybook.js.org)
|
|
157
|
+
Add `@rainstormy/presets-biome/2.2/storybook` to the `extends` array to support
|
|
158
|
+
the following kinds of files in Storybook (naming convention in parentheses):
|
|
159
|
+
|
|
160
|
+
- Stories based on
|
|
161
|
+
the [Component Story Format](https://storybook.js.org/docs/api/csf) (CSF 3)
|
|
162
|
+
(`*.stories.{ts,tsx}`)
|
|
163
|
+
- [Decorators](https://storybook.js.org/docs/writing-stories/decorators)
|
|
164
|
+
(`*.decorators.{ts,tsx}`)
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"extends": [
|
|
169
|
+
"@rainstormy/presets-biome/2.2",
|
|
170
|
+
"@rainstormy/presets-biome/2.2/storybook"
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Add `.storybook/**` to the `files.includes` array to cover Storybook
|
|
176
|
+
configuration files:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"files": {
|
|
181
|
+
"includes": [
|
|
182
|
+
".github/**",
|
|
183
|
+
".storybook/**",
|
|
184
|
+
".vscode/**",
|
|
185
|
+
"src/**",
|
|
186
|
+
"*.{js,json,jsonc,ts}"
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Stories must remain simple in terms of cognitive complexity, limiting the use of
|
|
193
|
+
conditional logic.
|
|
194
|
+
|
|
195
|
+
### [Vitest](https://vitest.dev)
|
|
196
|
+
Add `@rainstormy/presets-biome/2.2/vitest` to the `extends` array to support the
|
|
197
|
+
following kinds of files in Vitest (naming convention in parentheses):
|
|
198
|
+
|
|
199
|
+
- Unit test suites (`*.tests.{ts,tsx}`)
|
|
200
|
+
- Test fixtures such as test data, stubs, and utilities (`*.fixtures.{ts,tsx}`)
|
|
201
|
+
- [Module mocks](https://vitest.dev/guide/mocking#modules) (`*.mocks.{ts,tsx}`)
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"extends": [
|
|
206
|
+
"@rainstormy/presets-biome/2.2",
|
|
207
|
+
"@rainstormy/presets-biome/2.2/vitest"
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
To reduce the likelihood of buggy tests, test files must remain simple in terms
|
|
213
|
+
of cognitive complexity, limiting the use of conditional logic.
|
|
214
|
+
|
|
123
215
|
### Eject from the preset
|
|
124
216
|
Copy the relevant parts of
|
|
125
|
-
the [preset source files](https://github.com/rainstormy/presets-biome/tree/main/src)
|
|
217
|
+
the [preset source files](https://github.com/rainstormy/presets-biome/tree/main/src/2.2)
|
|
126
218
|
and insert them directly into the `biome.json` file. Make adjustments as needed.
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@rainstormy/presets-biome",
|
|
4
|
-
"version": "2.0.0
|
|
5
|
-
"description": "Predefined, opinionated Biome configurations
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"description": "Predefined, opinionated Biome configurations carefully crafted for modern TypeScript projects with add-ons for Next.js, React Router, Storybook, and Vitest.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"biome",
|
|
8
|
+
"configs",
|
|
8
9
|
"formatter",
|
|
9
10
|
"formatting",
|
|
10
11
|
"linter",
|
|
11
|
-
"linting"
|
|
12
|
+
"linting",
|
|
13
|
+
"next",
|
|
14
|
+
"nextjs",
|
|
15
|
+
"react",
|
|
16
|
+
"react-router",
|
|
17
|
+
"storybook",
|
|
18
|
+
"typescript",
|
|
19
|
+
"vitest"
|
|
12
20
|
],
|
|
13
21
|
"bugs": "https://github.com/rainstormy/presets-biome/issues",
|
|
14
22
|
"repository": {
|