Skip to content

Expose oxlint/plugins-dev and oxlint/plugins exports via vite-plus #2382

Description

@connorshea

Description

I want to write custom rules and then tests for my custom Oxlint rule, and currently cannot do that out-of-the-box with vite-plus.

This doesn't work, and no sub-exports exist for the lint path at all.

Suggested solution

// oxlint-plugin/rules/no-record-string-unknown.js
import { defineRule } from "vite-plus/lint/plugins";

export const noRecordStringUnknown = defineRule({
  meta: {
    type: "suggestion",
    docs: { description: "Cool rule" }
  },
  createOnce(context) {
    return {
      console.log('foo');
    }
  },
});

// oxlint-plugin/index.js
import { definePlugin } from "vite-plus/lint/plugins";
import { noRecordStringUnknown } from "./rules/no-record-string-unknown.js";

export default definePlugin({
  meta: { name: "test-app" },
  rules: { "no-record-string-unknown": noRecordStringUnknown },
});
import { RuleTester } from "vite-plus/lint/plugins-dev";
import { describe, it } from "vite-plus/test";
import { noRecordStringUnknown } from "./no-record-string-unknown.js";

// This is admittedly jank but seemingly the intended way to do it.
RuleTester.describe = describe;
RuleTester.it = it;

const ruleTester = new RuleTester();

ruleTester.run("no-record-string-unknown", noRecordStringUnknown, {
  valid: [
    { code: "let goodCode = true;" },
  ],
  invalid: [
    {
      code: "let badCode = true;",
      filename: "a.ts",
      errors: [{ messageId: "noRecordStringUnknown" }],
    },
  ],
});

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
  • Check that there isn't already an issue requesting the same feature.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Fields

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions