openpencil/tools/checks/lint
Danila Poyarkov cff091bc6a
test: resolve repository files without climbing directories (#946)
* test: resolve repository files without climbing directories

Twelve tests and helpers reached shared fixtures, package assets, and workers with ../.. paths from import.meta, which the import rule does not see. They now go through repoPath and testPath, a workspaceRoot() that finds the root by its lockfile, the core package's own root, or the #core alias through import.meta.resolve. The root finder derives its folder from import.meta.url, so Playwright specs running under Node can use the helpers too. open-pencil/no-deep-parent-relative-paths rejects climbing two levels in new URL(…, import.meta.url) and in path calls that start from import.meta.

* fix(lint): catch Windows separators and wrapped import.meta paths, and stop at template expressions

The path rule missed '..\..' and a base such as dirname(fileURLToPath(import.meta.url)), and read `../${folder}` followed by '..' as climbing two levels.
2026-10-07 12:35:39 +00:00
..
src
tests test: resolve repository files without climbing directories (#946) 2026-10-07 12:35:39 +00:00
NOTICE
package.json
README.md

OpenPencil lint rules

src/plugin.ts registers locally owned rules; the workspace oxlint.json selects policy. Run bun run --cwd tools/checks/lint test for rule tests and bun run lint for repository enforcement.

Test and type policies

  • no-module-mocking rejects Bun, Vitest, and Jest module registry mocking, including Bun's mock and jest exports and Vitest's vi and vitest exports. Scoped spies and injected dependencies remain supported. Detection covers direct framework calls and renamed named imports, not arbitrary alias propagation or destructuring.
  • no-reduce-accumulator-copy detects unbounded accumulator copies through Object.assign, Array.from, and array copy methods. It complements oxc/no-accumulating-spread. Literal-bounded slices such as slice(0, 2) and slice(-2) are allowed; slice(2) and slice(0, -1) still copy a potentially growing range. This is a conservative syntactic check, not a proof of quadratic runtime for every reducer.
  • no-widen-then-assert detects immutable local bindings widened to broad types and then asserted narrower in the same function. It intentionally avoids inferring arbitrary type aliases, imported return types, or cross-function flows.

The experimental known-value-widening audit is not included: its broad policy produced too many intentional-contract diagnostics to justify maintaining a separate type resolver.

Maintenance

Upstream attribution and the full license are in NOTICE. These are adapted, locally owned rules, not an automatically synchronized vendor directory. Compare any upstream updates against the recorded commit, preserve local behavior, and add positive and negative regression cases before changing enforcement.

Tests share tests/helpers/lint.ts, which invokes the real Oxlint plugin, rejects parser/configuration failures, and cleans each fixture in finally. Keep test infrastructure out of runtime source helpers.