Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e253963
Implement rule
Mar 19, 2026
2bbe811
Update messages and reorder
Mar 19, 2026
09f1ff8
Clean up
Mar 19, 2026
226a7aa
Report assignment pattern
Mar 19, 2026
245154a
Add a rule for private identifiers
Mar 19, 2026
d92702f
Add missing tests
Mar 19, 2026
096069e
Reorder tests
Mar 19, 2026
bd32605
lint
Mar 19, 2026
2f38104
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan Mar 19, 2026
c40da2b
Potential fix for pull request finding
aleksanderkatan Mar 19, 2026
c55d427
Potential fix for pull request finding
aleksanderkatan Mar 19, 2026
e0c6bfb
Merge remote-tracking branch 'origin/main' into feat/lint-rule-for-un…
aleksanderkatan Apr 1, 2026
471e7c2
Merge fixes
aleksanderkatan Apr 1, 2026
eba340b
Report eqeq
aleksanderkatan Apr 1, 2026
b2a1d91
Move tests
aleksanderkatan Apr 1, 2026
ebe784e
Update directiveTracking
aleksanderkatan Apr 1, 2026
46867ea
Report functions
aleksanderkatan Apr 1, 2026
d595ca3
Omit reporting object methods
aleksanderkatan Apr 2, 2026
97fbfb4
Update readme
aleksanderkatan Apr 2, 2026
4247655
Report chain expression
aleksanderkatan Apr 2, 2026
d268b4b
Report ??
aleksanderkatan Apr 2, 2026
51f780f
Report unsupported unary operators
aleksanderkatan Apr 2, 2026
47cb18c
Update binary and unary operators
aleksanderkatan Apr 2, 2026
d264738
Better types
aleksanderkatan Apr 2, 2026
d78b9dd
Review fixes
aleksanderkatan Apr 2, 2026
a319001
Merge branch 'main' into feat/lint-rule-for-unsupported-js
aleksanderkatan Apr 2, 2026
e2a777b
Change from warn to error
aleksanderkatan Apr 2, 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
5 changes: 1 addition & 4 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { defineConfig } from 'oxlint';
import typegpu from 'eslint-plugin-typegpu';
import eslintPlugin from 'eslint-plugin-eslint-plugin';

const typegpuPreset = typegpu.configs?.recommended;
const typegpuRules = typegpuPreset && 'rules' in typegpuPreset ? typegpuPreset.rules : {};

export default defineConfig({
plugins: ['eslint', 'typescript', 'import', 'unicorn', 'oxc'],
jsPlugins: ['eslint-plugin-typegpu', 'eslint-plugin-eslint-plugin'],
Expand All @@ -13,7 +10,7 @@ export default defineConfig({
suspicious: 'warn',
},
rules: {
...typegpuRules,
...typegpu.configs.recommended.rules,
'typescript/no-unsafe-enum-comparison': 'off',
'typescript/restrict-template-expressions': 'off',
'typescript/no-unsafe-type-assertion': 'off',
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default defineConfig([
| [no-invalid-assignment](docs/rules/no-invalid-assignment.md) | Disallow assignments that will generate invalid WGSL | ⭐ | |
| [no-math](docs/rules/no-math.md) | Disallow usage of JavaScript 'Math' methods inside 'use gpu' functions | | ⭐ |
| [no-uninitialized-variables](docs/rules/no-uninitialized-variables.md) | Disallow variable declarations without initializers inside 'use gpu' functions | ⭐ | |
| [no-unsupported-syntax](docs/rules/no-unsupported-syntax.md) | Disallow JS syntax that will not be parsed to correct WGSL. | ⭐ | |
| [no-unwrapped-objects](docs/rules/no-unwrapped-objects.md) | Disallow unwrapped Plain Old JavaScript Objects inside 'use gpu' functions (except returns) | ⭐ | |

<!-- end auto-generated rules list -->
64 changes: 64 additions & 0 deletions packages/eslint-plugin/docs/rules/no-unsupported-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# typegpu/no-unsupported-syntax

📝 Disallow JS syntax that will not be parsed to correct WGSL.

🚨 This rule is enabled in the ⭐ `recommended` config.

<!-- end auto-generated rule header -->

## Rule details

Examples of **incorrect** code for this rule:

```ts
const fn = () => {
'use gpu';
const helper = (n) => 2 * n; // ArrowFunctionExpression
return helper(1);
}
```
```ts
const fn = () => {
'use gpu';
const myStruct = Struct({prop: 1});
const otherStruct = Struct({...myStruct}); // SpreadElement
return otherStruct;
}
```
```ts
const fn = () => {
'use gpu';
throw new Error(); // ThrowStatement
}
```

Examples of **correct** code for this rule:

```ts
const fn = (a) => {
'use gpu';
let counter = 0;
let i = a;
while (i) {
if (i % 2 === 1) {
counter += 1;
}
i >>= 1;
}
return otherFn(counter);
}
```
```ts
const fn = () => {
'use gpu';
let a = 0;
const arr = [1, 2, 3];
for (const item of arr) {
a += item;
}
return a;
}
```

Note that it is possible that TypeGPU starts/stops supporting JS syntax from version to version.
Make sure that the minor versions of `typegpu` and `eslint-plugin-typegpu` match.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { noUnwrappedObjects } from './rules/noUnwrappedObjects.ts';
import { noMath } from './rules/noMath.ts';
import { noUninitializedVariables } from './rules/noUninitializedVariables.ts';
import { noInvalidAssignment } from './rules/noInvalidAssignment.ts';
import { noUnsupportedSyntax } from './rules/noUnsupportedSyntax.ts';

export const rules = {
'no-integer-division': noIntegerDivision,
'no-unwrapped-objects': noUnwrappedObjects,
'no-uninitialized-variables': noUninitializedVariables,
'no-math': noMath,
'no-invalid-assignment': noInvalidAssignment,
'no-unsupported-syntax': noUnsupportedSyntax,
} as const;

type Rules = Record<`typegpu/${keyof typeof rules}`, TSESLint.FlatConfig.RuleEntry>;
Expand All @@ -21,6 +23,7 @@ export const recommendedRules: Rules = {
'typegpu/no-uninitialized-variables': 'error',
'typegpu/no-math': 'warn',
'typegpu/no-invalid-assignment': 'error',
'typegpu/no-unsupported-syntax': 'error',
};

export const allRules: Rules = {
Expand All @@ -29,4 +32,5 @@ export const allRules: Rules = {
'typegpu/no-uninitialized-variables': 'error',
'typegpu/no-math': 'error',
'typegpu/no-invalid-assignment': 'error',
'typegpu/no-unsupported-syntax': 'error',
};
6 changes: 5 additions & 1 deletion packages/eslint-plugin/src/enhancers/directiveTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type FunctionNode =

export type DirectiveData = {
getEnclosingTypegpuFunction: () => FunctionNode | undefined;
getDirectiveStack: () => readonly { node: FunctionNode; directives: string[] }[];
};

/**
Expand Down Expand Up @@ -48,13 +49,16 @@ export const directiveTracking: RuleEnhancer<DirectiveData> = () => {
return {
visitors,
state: {
getEnclosingTypegpuFunction: () => {
getEnclosingTypegpuFunction() {
const current = stack.at(-1);
if (current && current.directives.includes('use gpu')) {
return current.node;
}
return undefined;
},
getDirectiveStack() {
return stack;
},
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const all: TSESLint.FlatConfig.Config = {
rules: allRules,
};

const plugin: TSESLint.FlatConfig.Plugin = {
const plugin = {
...pluginBase,
configs: {
recommended,
Expand Down
Loading
Loading