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
11 changes: 9 additions & 2 deletions apps/oxlint/src-js/plugins/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ export function registerPlugin(

const { fixable } = ruleMeta;
if (fixable != null) {
if (fixable !== "code" && fixable !== "whitespace") {
// `true` and `false` aren't valid values for `meta.fixable`, but we accept them for
// backward compatibility with some ESLint plugins
if (
fixable !== "code" &&
fixable !== "whitespace" &&
fixable !== true &&
fixable !== false
) {
throw new TypeError("Invalid `rule.meta.fixable`");
}
isFixable = true;
isFixable = (fixable as "code" | "whitespace" | true | false) !== false;
}

// If `schema` provided, compile schema to validator for applying schema defaults to options
Expand Down
10 changes: 10 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsPlugins": ["./plugin.ts"],
"categories": {
"correctness": "off"
},
"rules": {
"fixable-boolean-plugin/no-debugger-true": "error",
"fixable-boolean-plugin/no-console-false": "error"
}
}
2 changes: 2 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/files/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
debugger;
console.log("test");
28 changes: 28 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/fix.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Exit code
1

# stdout
```
x fixable-boolean-plugin(no-console-false): Console with fixable: false
,-[files/index.js:2:1]
1 | debugger;
2 | console.log("test");
: ^^^^^^^^^^^^^^^^^^^
`----

Found 0 warnings and 1 error.
Finished in Xms on 1 file with 2 rules using X threads.
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```

# File altered: files/index.js
```

console.log("test");

```
3 changes: 3 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fix": true
}
28 changes: 28 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/output.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Exit code
1

# stdout
```
x fixable-boolean-plugin(no-debugger-true): Debugger with fixable: true
,-[files/index.js:1:1]
1 | debugger;
: ^^^^^^^^^
2 | console.log("test");
`----

x fixable-boolean-plugin(no-console-false): Console with fixable: false
,-[files/index.js:2:1]
1 | debugger;
2 | console.log("test");
: ^^^^^^^^^^^^^^^^^^^
`----

Found 0 warnings and 2 errors.
Finished in Xms on 1 file with 2 rules using X threads.
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
54 changes: 54 additions & 0 deletions apps/oxlint/test/fixtures/fixable_boolean/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { Plugin } from "#oxlint/plugin";

// Test backward compatibility for `meta.fixable: true` and `meta.fixable: false`
// which some ESLint plugins use instead of "code" or "whitespace"
const plugin: Plugin = {
meta: {
name: "fixable-boolean-plugin",
},
rules: {
// Rule with fixable: true (backward compatibility)
"no-debugger-true": {
meta: {
fixable: true as any,
},
create(context) {
return {
DebuggerStatement(node) {
context.report({
message: "Debugger with fixable: true",
node,
fix(fixer) {
return fixer.remove(node);
},
});
},
};
},
},
// Rule with fixable: false (backward compatibility)
"no-console-false": {
meta: {
fixable: false as any,
},
create(context) {
return {
CallExpression(node) {
if (
node.callee.type === "MemberExpression" &&
node.callee.object.type === "Identifier" &&
node.callee.object.name === "console"
) {
context.report({
message: "Console with fixable: false",
node,
});
}
},
};
},
},
},
};

export default plugin;
Loading