Commit Graph

6 Commits

Author SHA1 Message Date
overlookmotel 5cc7c907d6 feat(linter/plugins): pass env from Rust to JS (#17291)
Pass `env` to JS plugins. JS plugins don't do anything with it yet, except allow the user to see it. But they will in a following PR.
2025-12-23 10:53:25 +00:00
overlookmotel e39deb610e refactor(linter/plugins): add error messages to debug assertions (#17171)
Add error messages to all `debugAssert()` calls, for easier debugging.

When running Oxlint normally, we can easily figure out where errors are coming from stack traces, but in conformance test snapshot, line and column are removed from errors in the snapshot, so it's less easy.
2025-12-20 13:59:12 +00:00
overlookmotel 42603ba23b fix(linter/plugins): always define languageOptions.globals (#17008)
Previously `context.languageOptions.globals` was `null` if no globals defined in config. This was a slight incompatibility with ESLint, which doesn't define `globals` property at all on `languageOptions` in this case.

Instead make `languageOptions.globals` an empty object. This should make no practical difference from what ESLint does, but avoids errors in rules if they do something like this:

```js
if (languageOptions.globals !== undefined) {
  // This would throw if `globals` was `null` (as it used to be)
  const hasWindow = languageOptions.globals.window !== "off";
}
```
2025-12-17 14:26:58 +00:00
overlookmotel da509be78a refactor(linter/plugins): convert global properties to vars with TSDown plugin, instead of manually (#16961)
Previously we had a pattern of destructuring properties of global objects into top-level vars. e.g.:

```js
const { keys: ObjectKeys, hasOwn } = Object,
  { isArray } = Array;
```

Doing this is more performant, but it makes the code harder to read.

Instead, write code normally, and use a TSDown plugin to convert:

```js
const keys = Object.keys(obj);
```

to:

```js
import { ObjectKeys } from "../utils/globals.ts";
const keys = ObjectKeys(obj);
```

Defining all the destructured globals in a single file (`utils/globals.ts`) is advantageous for bundle size. If the TSDown plugin created top level `const ObjectKeys = Object.keys;` statements in each file, then you can end up with this in bundle as minifier doesn't de-duplicate:

```js
const ObjectKeys = Object.keys;
const ObjectKeys$1 = Object.keys;
const ObjectKeys$2 = Object.keys;
```

The globals we use have to be manually added to `utils/globals.ts`, but TSDown plugin warns when this needs to be done, and doesn't generate a broken build in the meantime.

This plugin is run in debug builds too, so that the tests will catch any bugs.
2025-12-16 17:33:37 +00:00
overlookmotel 0241b9a920 perf(linter/plugins): remove code for renaming global values (#16610)
After #16609, the value of globals is serialized correctly ("writable" not "writeable"), so this workaround is no longer required. Remove it.
2025-12-08 17:08:06 +00:00
Arsh 5c62c16e43 feat(linter/plugins): allow JS plugins to access globals (#16512)
- This PR implements a naive, inefficient solution to #16359.
- To establish current and expected behavior, this PR serializes
rust-resolved and -overridden globals once for every file.

## Future work
- [ ] Add test for globals from the `env` field. Implement support if
not currently supported.
- [ ] Optimization: we want to serialize `globals` for all files only
once at the start of the lint run.

## AI Usage
- This PR was drafted by Claude Sonnet 4.5 in Plan + Agent mode, then
manually reviewed and iterated on.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-12-06 23:08:19 +00:00