Skip to content

Commit 0411ea1

Browse files
docs: Lint plugin (#2307)
1 parent ae3a2bf commit 0411ea1

4 files changed

Lines changed: 113 additions & 0 deletions

File tree

apps/typegpu-docs/astro.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ export default defineConfig({
246246
label: 'Build Plugin',
247247
slug: 'tooling/unplugin-typegpu',
248248
},
249+
{
250+
label: 'Lint Plugin',
251+
slug: 'tooling/eslint-plugin-typegpu',
252+
badge: { text: 'new' },
253+
},
249254
{
250255
label: 'Generator CLI',
251256
slug: 'tooling/tgpu-gen',

apps/typegpu-docs/src/content/docs/fundamentals/data-schemas.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const result = d.u32(3)/d.u32(2); // 1.5
4747
```
4848

4949
To achieve consistent behavior of 'use gpu' functions in JS and on the GPU, TypeGPU wraps all divisions in `f32` casts implicitly.
50+
51+
Our [lint plugin](/TypeGPU/tooling/eslint-plugin-typegpu) helps with detecting situations like these.
5052
:::
5153

5254
For each of the scalar types, there is a vector schema of 2, 3 and 4 elements of that type.

apps/typegpu-docs/src/content/docs/getting-started.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function foo() {
7777
```
7878
:::
7979

80+
:::tip
81+
We provide a [lint plugin](/TypeGPU/tooling/eslint-plugin-typegpu) that helps with writing 'use gpu' functions.
82+
:::
83+
8084
## Live Examples
8185

8286
Our [live examples](/TypeGPU/examples) showcase many use-cases of TypeGPU. Feel free to check them out! You can also open each of them on StackBlitz in order to edit the code and see the preview update live, or to bootstrap your own project.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Lint Plugin
3+
description: A guide on how to use the optional lint plugin for TypeGPU
4+
---
5+
import { Tabs, TabItem } from '@astrojs/starlight/components';
6+
7+
[eslint-plugin-typegpu](https://www.npmjs.com/package/eslint-plugin-typegpu) is an optional (but highly recommended) tool for projects using TypeGPU.
8+
It helps with writing 'use gpu' functions by highlighting common pitfalls and unsupported syntax.
9+
10+
## Installation
11+
12+
<Tabs syncKey='package-manager'>
13+
<TabItem label='npm' icon='seti:npm'>
14+
```sh frame=none
15+
npm add -D eslint-plugin-typegpu
16+
```
17+
</TabItem>
18+
<TabItem label='pnpm' icon='pnpm'>
19+
```sh frame=none
20+
pnpm add -D eslint-plugin-typegpu
21+
```
22+
</TabItem>
23+
<TabItem label='yarn' icon='seti:yarn'>
24+
```sh frame=none
25+
yarn add -D eslint-plugin-typegpu
26+
```
27+
</TabItem>
28+
</Tabs>
29+
30+
After installing, the plugin still needs to be added to a config.
31+
The way this is done depends on the linter used.
32+
33+
## Configuring
34+
35+
### ESLint (`eslint.config.js`)
36+
37+
The plugin needs to be imported and included in `defineConfig`.
38+
39+
```ts
40+
import { defineConfig } from 'eslint/config';
41+
import typegpu from 'eslint-plugin-typegpu';
42+
43+
export default defineConfig([
44+
{
45+
plugins: { typegpu },
46+
rules: {
47+
'typegpu/no-integer-division': 'warn',
48+
'typegpu/no-math': 'warn',
49+
// other rules you want to enable
50+
}
51+
}
52+
]);
53+
```
54+
55+
The plugin also exports `recommended` and `all` configs, which may be used instead of listing the rules one by one.
56+
57+
```ts
58+
import { defineConfig } from 'eslint/config';
59+
import typegpu from 'eslint-plugin-typegpu';
60+
61+
export default defineConfig([
62+
typegpu.configs.recommended,
63+
]);
64+
```
65+
66+
### Oxlint (`oxlint.config.ts`)
67+
68+
The plugin needs to be listed in `jsPlugins`. The rules can either be listed one by one, or a config can be used.
69+
70+
```ts
71+
import { defineConfig } from 'oxlint';
72+
import typegpu from 'eslint-plugin-typegpu';
73+
74+
export default defineConfig({
75+
jsPlugins: ['eslint-plugin-typegpu'],
76+
rules: {
77+
...typegpu.configs.recommended.rules,
78+
// (optional) changes from the recommended preset
79+
},
80+
});
81+
```
82+
83+
### Oxlint (`.oxlintrc.json`)
84+
85+
The plugin needs to be listed in `jsPlugins`, and the rules have to be listed one by one.
86+
In this type of config there is no way to enable all rules
87+
88+
```json
89+
{
90+
"$schema": "./node_modules/oxlint/configuration_schema.json",
91+
"jsPlugins": ["eslint-plugin-typegpu"],
92+
"rules": {
93+
"typegpu/no-integer-division": "warn",
94+
"typegpu/no-math": "warn",
95+
...
96+
}
97+
}
98+
```
99+
100+
## Rules
101+
102+
For the full list of supported rules, as well as their specifics, see the [README.md](https://www.npmjs.com/package/eslint-plugin-typegpu) of the plugin.

0 commit comments

Comments
 (0)