Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
91eeaa8
Add package.json
Jan 22, 2026
e063b7c
Add index.ts
Jan 22, 2026
a558156
Add tsup config
Jan 22, 2026
1af79a1
Add a dummy rule for testing
Jan 22, 2026
d0b6651
Add testing infrastructure
Jan 22, 2026
bb433b8
Add a proper rule
Jan 22, 2026
dfbaddd
Remove the dummy rule
Jan 22, 2026
4eead5a
Add a readme stub
Jan 22, 2026
19bbcd7
Add formatting
Jan 22, 2026
0ec6db1
Check for a cast in parent
Jan 22, 2026
6712b4b
Review fixes
Jan 22, 2026
320563b
Add a describe to please vitest gods
Jan 23, 2026
b5d3a21
Add configuration for test:types
Jan 23, 2026
c255562
Increase old size limit
Jan 23, 2026
ea990e6
Bump attest
Jan 23, 2026
cfd112e
Fix failing build
Jan 23, 2026
30af466
Add recommended rules
Jan 23, 2026
adb6799
Add all rules
Jan 23, 2026
340a924
Fix configuration so that the plugin is usable
Jan 23, 2026
9042d4e
Update lock
Jan 23, 2026
2ea027a
Merge remote-tracking branch 'origin/main' into feat/type-aware-lint-…
Jan 23, 2026
a49362e
Review fixes
Jan 23, 2026
ff415f6
Remove an unnecessary dependency
Jan 23, 2026
0795486
smol
Jan 23, 2026
0c879de
Merge branch 'main' into feat/type-aware-lint-plugin-poc
Jan 30, 2026
460e199
Report on || instead of &&
Feb 4, 2026
99a4b32
Merge remote-tracking branch 'origin/main' into feat/type-aware-lint-…
Feb 4, 2026
8312172
Fix lock
Feb 9, 2026
7825379
Merge remote-tracking branch 'origin/main' into feat/type-aware-lint-…
Feb 9, 2026
3b6ee06
Add a base for the rule
Jan 30, 2026
a2cc376
Rule enhancers POC
Jan 30, 2026
f2a0ff1
Clean up types
Jan 30, 2026
252665f
Update directiveTracking API
Jan 30, 2026
ec684e3
Add more tests and implement rule logic
Jan 30, 2026
770fd03
Implement directive tracking
Jan 30, 2026
7c91882
Self review
Jan 30, 2026
2664a72
Ignores returns
Feb 9, 2026
8e85376
Handle nested structs
Feb 9, 2026
6c6b9e6
Add spreadOperator rule
Feb 10, 2026
e08e883
Add uninitializedVariable rule
Feb 10, 2026
9ccb7d4
Add math rule
Feb 10, 2026
384e05e
Update configs
Feb 10, 2026
e74192b
Nits
Feb 10, 2026
86808d4
Update packages/eslint-plugin/src/rules/math.ts
aleksanderkatan Feb 10, 2026
ae072c2
Merge remote-tracking branch 'origin/main' into feat/simple-rules
Mar 19, 2026
cf810de
Remove the spread operator rule (delegated to a different PR)
Mar 19, 2026
c19c195
Post-merge fix
Mar 19, 2026
89db14c
Fix tet name
Mar 19, 2026
d819f80
Add exception for `for...of`
Mar 19, 2026
8ab729c
Fix tests
Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/eslint-plugin/src/configs.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import type { TSESLint } from '@typescript-eslint/utils';
import { integerDivision } from './rules/integerDivision.ts';
import { unwrappedPojos } from './rules/unwrappedPojos.ts';
import { math } from './rules/math.ts';
import { uninitializedVariable } from './rules/uninitializedVariable.ts';

export const rules = {
'integer-division': integerDivision,
'unwrapped-pojo': unwrappedPojos,
'uninitialized-variable': uninitializedVariable,
math: math,
} as const;

type Rules = Record<`typegpu/${keyof typeof rules}`, TSESLint.FlatConfig.RuleEntry>;

export const recommendedRules: Rules = {
'typegpu/integer-division': 'warn',
'typegpu/unwrapped-pojo': 'warn',
'typegpu/uninitialized-variable': 'warn',
'typegpu/math': 'warn',
};

export const allRules: Rules = {
'typegpu/integer-division': 'error',
'typegpu/unwrapped-pojo': 'error',
'typegpu/uninitialized-variable': 'error',
'typegpu/math': 'error',
};
42 changes: 42 additions & 0 deletions packages/eslint-plugin/src/rules/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createRule } from '../ruleCreator.ts';
import { enhanceRule } from '../enhanceRule.ts';
import { directiveTracking } from '../enhancers/directiveTracking.ts';

export const math = createRule({
name: 'math',
meta: {
type: 'suggestion',
docs: {
description: `Disallow usage of JavaScript 'Math' methods inside 'use gpu' functions; use 'std' instead.`,
},
messages: {
math: "Using Math methods, such as '{{snippet}}', is not advised, and may not work as expected. Use 'std' instead.",
},
schema: [],
},
defaultOptions: [],

create: enhanceRule({ directives: directiveTracking }, (context, state) => {
const { directives } = state;

return {
CallExpression(node) {
if (!directives.insideUseGpu()) {
return;
}

if (
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'Math'
) {
context.report({
node,
messageId: 'math',
data: { snippet: context.sourceCode.getText(node) },
});
}
},
};
}),
});
41 changes: 41 additions & 0 deletions packages/eslint-plugin/src/rules/uninitializedVariable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { enhanceRule } from '../enhanceRule.ts';
import { directiveTracking } from '../enhancers/directiveTracking.ts';
import { createRule } from '../ruleCreator.ts';

export const uninitializedVariable = createRule({
name: 'uninitialized-variable',
meta: {
type: 'problem',
docs: {
description: `Always assign an initial value when declaring a variable inside TypeGPU functions.`,
},
messages: {
uninitializedVariable: "'{{snippet}}' should have an initial value.",
},
schema: [],
},
defaultOptions: [],

create: enhanceRule({ directives: directiveTracking }, (context, state) => {
const { directives } = state;

return {
VariableDeclarator(node) {
if (!directives.insideUseGpu()) {
return;
}
if (node.parent?.parent?.type === 'ForOfStatement') {
// one exception where we allow uninitialized variable
return;
}
if (node.init === null) {
context.report({
node,
messageId: 'uninitializedVariable',
data: { snippet: context.sourceCode.getText(node) },
});
}
},
};
}),
});
24 changes: 24 additions & 0 deletions packages/eslint-plugin/tests/math.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe } from 'vitest';
import { ruleTester } from './ruleTester.ts';
import { math } from '../src/rules/math.ts';

describe('math', () => {
ruleTester.run('math', math, {
valid: [
'const result = Math.sin(1);',
'const t = std.sin(Math.PI)',
"const fn = () => { 'use gpu'; const vec = std.sin(Math.PI); }",
],
invalid: [
{
code: "const fn = () => { 'use gpu'; const vec = Math.sin(0); }",
errors: [
{
messageId: 'math',
data: { snippet: 'Math.sin(0)' },
},
],
},
],
});
});
44 changes: 44 additions & 0 deletions packages/eslint-plugin/tests/uninitializedVariable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe } from 'vitest';
import { ruleTester } from './ruleTester.ts';
import { uninitializedVariable } from '../src/rules/uninitializedVariable.ts';

describe('uninitializedVariable', () => {
ruleTester.run('uninitializedVariable', uninitializedVariable, {
valid: [
'let a;',
'let a, b;',
"const fn = () => { 'use gpu'; const vec = d.vec3f(); }",
"const fn = () => { 'use gpu'; let vec = d.vec3f(); }",
`const fn = () => { 'use gpu';
let a = 0;
for (const foo of tgpu.unroll([1, 2, 3])) {
a += foo;
}
}`,
],
invalid: [
{
code: "const fn = () => { 'use gpu'; let vec; }",
errors: [
{
messageId: 'uninitializedVariable',
data: { snippet: 'vec' },
},
],
},
{
code: "const fn = () => { 'use gpu'; let a = 1, b, c = d.vec3f(), d; }",
errors: [
{
messageId: 'uninitializedVariable',
data: { snippet: 'b' },
},
{
messageId: 'uninitializedVariable',
data: { snippet: 'd' },
},
],
},
],
});
});
6 changes: 6 additions & 0 deletions packages/typegpu/tests/jsMath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Math', () => {
const myFn = () => {
'use gpu';
const a = 0.5;
// oxlint-disable-next-line typegpu/math
const b = Math.sin(a);
};

Expand All @@ -33,6 +34,7 @@ describe('Math', () => {
it('precomputes Math.sin when applicable', () => {
const myFn = () => {
'use gpu';
// oxlint-disable-next-line typegpu/math
const a = Math.sin(0.5);
};

Expand All @@ -47,6 +49,7 @@ describe('Math', () => {
const myFn = () => {
'use gpu';
const a = d.u32();
// oxlint-disable-next-line typegpu/math
const b = Math.sin(a);
};

Expand All @@ -62,6 +65,7 @@ describe('Math', () => {
const myFn = () => {
'use gpu';
const a = d.u32();
// oxlint-disable-next-line typegpu/math
const b = Math.min(a, 1, 2, 3);
};

Expand All @@ -76,6 +80,7 @@ describe('Math', () => {
it('throws a readable error when unsupported Math feature is used', () => {
const myFn = () => {
'use gpu';
// oxlint-disable-next-line typegpu/math
const a = Math.log1p(1);
};

Expand All @@ -90,6 +95,7 @@ describe('Math', () => {
it('correctly applies Math.fround', () => {
const myFn = () => {
'use gpu';
// oxlint-disable-next-line typegpu/math
const a = Math.fround(16777217);
};

Expand Down
Loading