dx: Lint rule for imports#2345
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (353 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
There was a problem hiding this comment.
Pull request overview
Adds a new internal ESLint plugin consumed by the repo’s oxlint configuration to enforce import-path hygiene (simplifying redundant relative paths and preventing overly-deep relative imports in docs examples), and applies path simplifications across the TypeGPU package.
Changes:
- Introduces
packages/eslint-plugin-internalwith two rules:no-useless-path-segmentsandno-long-imports, plus Vitest-based rule tests. - Wires the new plugin + rules into
oxlint.config.tsand workspace dependencies. - Simplifies several TypeGPU internal imports by removing redundant path segments.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds the new workspace plugin and updates lock entries accordingly. |
| package.json | Adds eslint-plugin-internal as a workspace dev dependency. |
| oxlint.config.ts | Loads eslint-plugin-internal and enables the new rules (glob-scoped for examples). |
| packages/typegpu/src/tgsl/generationHelpers.ts | Simplifies internal imports to shorter relative paths. |
| packages/typegpu/src/core/unroll/tgpuUnroll.ts | Simplifies internal imports to shorter relative paths. |
| packages/typegpu/src/core/slot/slotTypes.ts | Fixes redundant/odd relative import segment (./../). |
| packages/typegpu/src/core/root/rootTypes.ts | Simplifies imports for querySet and tgpuComputeFn. |
| packages/typegpu/src/core/root/init.ts | Simplifies querySet imports. |
| packages/typegpu/src/core/querySet/querySet.ts | Simplifies root types import. |
| packages/typegpu/src/core/pipeline/renderPipeline.ts | Simplifies buffer/querySet imports. |
| packages/typegpu/src/core/pipeline/computePipeline.ts | Simplifies querySet import. |
| packages/eslint-plugin-internal/* | New internal lint plugin package, rules, tests, and build/test configs. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return { | ||
| ImportDeclaration(node) { | ||
| const importPath = node.source.value; | ||
| if (importPath.startsWith('../../') && !importPath.startsWith('../../common/')) { |
There was a problem hiding this comment.
Doesn't this introduce a pretty high chance of false positives?
There was a problem hiding this comment.
We only enable this rule on example files, where this will not work due to stackblitz pathing requirements
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.87, 1.73, 3.65, 6.38, 7.21, 10.71, 19.62, 24.58]
line [0.92, 1.85, 3.88, 6.06, 7.72, 10.94, 20.72, 23.69]
line [0.91, 1.84, 4.09, 6.37, 7.79, 10.03, 20.47, 21.71]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.32, 0.54, 0.68, 0.85, 1.12, 1.17, 1.35, 1.53]
line [0.32, 0.52, 0.66, 0.81, 1.09, 1.20, 1.40, 1.54]
line [0.30, 0.50, 0.63, 0.79, 1.07, 1.19, 1.43, 1.56]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.76, 1.92, 3.98, 5.82, 11.71, 24.08, 52.40, 106.17]
line [0.84, 2.02, 3.59, 5.87, 11.78, 24.50, 52.50, 108.54]
line [0.91, 2.01, 3.67, 5.82, 11.81, 25.08, 52.64, 108.76]
|
cieplypolar
left a comment
There was a problem hiding this comment.
Great work! I left some comments that should be addressed before merge.
This PR introduces a new internal lint plugin, along with
two rulesone rule.Rule
noUselessPathSegments- mirrors eslint-plugin-import rule that is not yet implemented in oxlint, it looks for unnecessary import segments like../../src/file.txt->../file.txt.RulenoLongImports- forbids imports starting with../..in examples (except../../common), since they are most likely an import mishap likeimport { vec2f } from '../../../../../../packages/typegpu/src/data/vector.ts';that won't work on stackblitz anyway.