Skip to content

Lint Plugin

eslint-plugin-typegpu is an optional (but highly recommended) tool for projects using TypeGPU. It helps with writing ‘use gpu’ functions by highlighting common pitfalls and unsupported syntax.

npm add -D eslint-plugin-typegpu

After installing, the plugin still needs to be added to a config. The way this is done depends on the linter used.

The plugin needs to be imported and included in defineConfig.

import { defineConfig } from 'eslint/config';
import typegpu from 'eslint-plugin-typegpu';
export default defineConfig([
{
plugins: { typegpu },
rules: {
'typegpu/no-integer-division': 'warn',
'typegpu/no-math': 'warn',
// other rules you want to enable
}
}
]);

The plugin also exports recommended and all configs, which may be used instead of listing the rules one by one.

import { defineConfig } from 'eslint/config';
import typegpu from 'eslint-plugin-typegpu';
export default defineConfig([
typegpu.configs.recommended,
]);

The plugin needs to be listed in jsPlugins. The rules can either be listed one by one, or a config can be used.

import { defineConfig } from 'oxlint';
import typegpu from 'eslint-plugin-typegpu';
export default defineConfig({
jsPlugins: ['eslint-plugin-typegpu'],
rules: {
...typegpu.configs.recommended.rules,
// (optional) changes from the recommended preset
},
});

The plugin needs to be listed in jsPlugins, and the rules have to be listed one by one. In this type of config there is no way to enable all rules

{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"jsPlugins": ["eslint-plugin-typegpu"],
"rules": {
"typegpu/no-integer-division": "warn",
"typegpu/no-math": "warn",
...
}
}

For the full list of supported rules, as well as their specifics, see the README.md of the plugin.