Commit Graph

12 Commits

Author SHA1 Message Date
Boshen 1193c9dbaf chore(oxfmt): dogfood operator position at line start (#25937)
dogfood
2026-08-20 14:36:47 +00:00
Nicolas Le Cam 27de0448ae fix(linter/plugins): make spreading Comment instances keep loc property (#22238)
## Summary: Fixing unicorn/expiring-todo-comments via jsPlugin

## Problem

The `unicorn/expiring-todo-comments` rule failed when run through
oxlint's jsPlugin system with error:
```TypeError: Either `node` or `loc` is required```

The rule spreads Comment instances (`{...comment}`) to process each line of multi-line comments, but lost the `loc` property because:
- Comment's `loc` was a prototype getter (not an own enumerable property)
- Spread only copies own enumerable properties

## Solution

Define `loc` as an own accessor property on every `Comment` instance using
`__defineGetter__`. Own properties are visible to spread, `JSON.stringify,` and
`for…in` iteration, so all three work without any extra workarounds.

The getter function is defined in the class static block and captured in a `const`
(`getCommentLoc`). Using a `const` rather than a `let` lets V8 skip reassignment checks
at the `defineGetter(this, "loc", getCommentLoc)` call site — a pattern already
established in the codebase for `resetCommentLoc`.

As a result:
- `toJSON()` is removed — `JSON.stringify` now works via the own property directly.
- `Object.defineProperty(Comment.prototype, "loc", { enumerable: true })` is removed —
no longer needed.

## Test Results
- ✅ unicorn/expiring-todo-comments rule works (detects expired TODOs)
- ✅ updated comments fixture pass
- ✅ All untouched existing tests pass

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2026-06-06 02:06:28 +01:00
overlookmotel 532c9213fb fix(linter/plugins): include loc when call JSON.stringify on Tokens and Comments (#20512)
`loc` property of `Token`s and `Comment`s is a getter on these classes' prototypes. Add a `toJSON` method to both classes so `JSON.stringify` includes `loc` in the generated JSON.
2026-03-21 13:10:25 +00:00
overlookmotel 9de9385fd1 refactor(linter/plugins): rename oxlint/plugin to oxlint/plugins (#18792)
Part of #18610.

Our intent is to move `definePlugin`, `defineRule`, and `eslintCompatPlugin` to a separate package `@oxlint/plugins` (plural to avoid confusion with naming convention for plugins `oxlint-plugin-xxx`).

So rename the current entry point which exports these functions from `oxlint/plugin` to `oxlint/plugins` (plural).
2026-02-01 13:23:14 +00:00
camc314 81eb6fa9db refactor(linter): split entry points for custom plugins/config/types (#18601)
This is technically breaking (only for types), but custom plugins are experimental.

The ruletester/defineRule/definePlugin are re-exported but with a `@deprecated` tag which I think is a good enough trade off

I want to avoid users bringing in a ton of custom plugin code when doing `import { defineConfig } from 'oxlint'`
2026-01-27 00:58:08 +00:00
overlookmotel a3d203bc2d fix(linter/plugins): make node, token, and comment objects have Object.prototype in prototype chain (#17220)
AST node, token, and comment objects have an object `NodeProto` / `TokenProto` as their prototype. Those objects provide a getter for `loc`.

Previously `NodeProto` and `TokenProto` had `null` as their prototype.

Turns out that was a problem as ESQuery (weirdly) compares nodes sometimes by converting them to strings with `${node}`. This relies on `Object.prototype.toString`, which wasn't present in the prototype chain.

Fix this by making `NodeProto` and `TokenProto` have `Object.prototype` as their prototype (like "normal" objects).
2025-12-21 17:43:25 +00:00
overlookmotel b2b87c608f feat(linter/plugins): add getRange and getLoc methods to SourceCode (#17179)
ESLint has undocumented `getRange` and `getLoc` methods on `SourceCode`. Add them.

These are the last 2 missing methods on `SourceCode` (according to Claude).

Also add more tests for correct functioning of `range` and `loc` properties.
2025-12-20 15:49:56 +00:00
Boshen 523a30a016 style(all): apply oxfmt default options (#16091)
Embrace the defaults!

---------

Co-authored-by: Yuji Sugiura <y.sugiura.0316@gmail.com>
2025-11-25 15:56:24 +09:00
overlookmotel 690abec235 test(linter/plugins): use subpath imports (#15920)
Shorten imports in test fixtures using [subpath imports](https://nodejs.org/docs/latest-v24.x/api/packages.html#subpath-imports).

Before:

```ts
import type { Plugin } from '../../../dist/index.js';
```

After:

```ts
import type { Plugin } from '#oxlint';
```
2025-11-21 11:44:25 +00:00
overlookmotel a72b093b05 refactor(linter/plugins): enable TS strictNullChecks (#15886)
Adapted from #15868. Enable `strictNullChecks` in TSConfig for `apps/oxlint`.

Rather than using `!` all over the place, I've added a function `assertIsNonNull`, which performs the same function. Idea is that we can later on produce a debug build where `assertIsNonNull` does an actual runtime assertion (rather than just a TS `asserts`) that the value is not `null` or `undefined`. We can use the debug build in tests, and catch any logic errors.

Unfortunately, TypeScript doesn't seem able to track side effects, so there seems to be no way to tell it "after calling `initAst()`, `ast` is always non-null". Don't want to switch to a having a `getAst` function which returns a non-null value, as that'd introduce unnecessary temp vars, and function calls, on hot paths. So this seems to be the best we can do without incurring runtime cost.
2025-11-20 15:52:49 +00:00
overlookmotel aee9be1f05 style(oxlint/plugins): format test fixtures (#15600)
Format `oxlint` test fixtures. The directory `fixtures` contains not just the fixtures themselves, but also Oxlint plugins, which should be formatted.

Skip 2 specific test fixture files which must not be formatted to maintain correctness of the tests.
2025-11-11 15:56:52 +00:00
Arsh 9700a56b78 feat(linter/plugins): comment-related APIs (#14715)
Part of #14564. Implement the remaining `SourceCode` APIs related to
comments (`getCommentsBefore`, `getCommentsAfter`, `getCommentsInside`,
`commentsExistBetween`).

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-10-18 14:14:31 +01:00