Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions apps/oxlint/src-js/plugins/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ export function registerPlugin(plugin: Plugin, packageName: string | null): Plug
if (!isArray(inputDefaultOptions)) {
throw new TypeError("`rule.meta.defaultOptions` must be an array if provided");
}
// TODO: This isn't quite safe, as `defaultOptions` isn't from JSON, and `deepFreezeJsonArray`
// assumes it is. We should perform options merging on Rust side instead, and also validate
// `defaultOptions` against options schema.
deepFreezeJsonArray(inputDefaultOptions);
defaultOptions = inputDefaultOptions;

if (inputDefaultOptions.length !== 0) {
// TODO: This isn't quite safe, as `defaultOptions` isn't from JSON, and `deepFreezeJsonArray`
// assumes it is. We should perform options merging on Rust side instead, and also validate
// `defaultOptions` against options schema.
deepFreezeJsonArray(inputDefaultOptions);
defaultOptions = inputDefaultOptions;
}
}

// Extract messages for messageId support
Expand Down
6 changes: 4 additions & 2 deletions apps/oxlint/test/fixtures/options/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
true,
[],
16
]
],
"options-plugin/empty-default-options": ["error", "from-config", 42]
},
"overrides": [
{
"files": ["files/nested/**"],
"rules": {
"options-plugin/options": ["error", { "somethingElse": true }],
"options-plugin/merge-options": ["error", { "fromConfig": 21 }, { "fromConfig": 22 }]
"options-plugin/merge-options": ["error", { "fromConfig": 21 }, { "fromConfig": 22 }],
"options-plugin/empty-default-options": "error"
}
}
]
Expand Down
21 changes: 20 additions & 1 deletion apps/oxlint/test/fixtures/options/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
: ^
`----

x options-plugin(empty-default-options):
| options: [
| "from-config",
| 42
| ]
| isDeepFrozen: true
,-[files/index.js:1:1]
1 | debugger;
: ^
`----

x options-plugin(merge-options):
| options: [
| {
Expand Down Expand Up @@ -116,6 +127,14 @@
: ^
`----

x options-plugin(empty-default-options):
| options: []
| isDeepFrozen: true
,-[files/nested/index.js:1:1]
1 | let x;
: ^
`----

x options-plugin(merge-options):
| options: [
| {
Expand Down Expand Up @@ -162,7 +181,7 @@
: ^
`----

Found 0 warnings and 8 errors.
Found 0 warnings and 10 errors.
Finished in Xms on 2 files using X threads.
```

Expand Down
18 changes: 18 additions & 0 deletions apps/oxlint/test/fixtures/options/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const plugin: Plugin = {
return {};
},
},

options: {
create(context) {
context.report({
Expand All @@ -37,6 +38,7 @@ const plugin: Plugin = {
return {};
},
},

"default-options": {
meta: {
defaultOptions: [
Expand All @@ -57,6 +59,7 @@ const plugin: Plugin = {
return {};
},
},

"merge-options": {
meta: {
defaultOptions: [
Expand All @@ -76,6 +79,21 @@ const plugin: Plugin = {
return {};
},
},

"empty-default-options": {
meta: {
defaultOptions: [],
},
create(context) {
context.report({
message:
`\noptions: ${JSON.stringify(context.options, null, 2)}\n` +
`isDeepFrozen: ${isDeepFrozen(context.options)}`,
node: SPAN,
});
return {};
},
},
},
};

Expand Down
Loading