### Correct code example for unicorn/prefer-string-starts-ends-with Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-starts-ends-with Shows the correct usage of String.prototype.startsWith() for checking string start. ```javascript const foo = "hello"; foo.startsWith("abc"); ``` -------------------------------- ### Correct code examples for unicorn/prefer-import-meta-properties Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-import-meta-properties These examples show the preferred way to get file paths using import.meta.filename and import.meta.dirname. This is the modern approach recommended by the rule. ```javascript const filename = import.meta.filename; const dirname = import.meta.dirname; ``` -------------------------------- ### Install migrate-oxlint skill Source: https://oxc.rs/docs/guide/usage/linter/migrate-from-eslint.html Install the interactive migration skill into your coding agent. ```bash npx skills add https://github.com/oxc-project/oxc --skill migrate-oxlint ``` -------------------------------- ### Incorrect code example for unicorn/prefer-string-starts-ends-with Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-starts-ends-with Demonstrates incorrect usage of regex for checking string start. ```javascript const foo = "hello"; /^abc/.test(foo); ``` -------------------------------- ### Install Oxlint with bun Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Install oxlint as a development dependency using bun. ```sh $ bun add -D oxlint ``` -------------------------------- ### Per-file setup with `before` hook Source: https://oxc.rs/docs/guide/usage/linter/writing-js-plugins.html Shows how to reset a counter in the `before` hook for per-file setup when using the `createOnce` API. ```diff - let classCount = 0; + let classCount; return { + before() { + classCount = 0; // Reset counter + }, ClassDeclaration(node) { classCount++; if (classCount === 6) { context.report({ message: "Too many classes", node }); } }, }; ``` -------------------------------- ### Correct JSX File Example Source: https://oxc.rs/docs/guide/usage/linter/rules/react/jsx-filename-extension This example demonstrates the correct usage with a .jsx file extension. ```jsx // filename: MyComponent.jsx function MyComponent() { return
; } ``` -------------------------------- ### Install Oxfmt Source: https://oxc.rs/docs/guide/usage/formatter.html Install oxfmt as a development dependency using pnpm. ```sh pnpm add -D oxfmt ``` -------------------------------- ### Enable no-labels Rule in Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-labels Configuration examples for enabling the 'no-labels' rule in an Oxc linting setup. ```json { "rules": { "no-labels": "error" } } ``` -------------------------------- ### Correct Code Example for jest/require-hook Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/require-hook This example shows the correct usage where setup and teardown logic are encapsulated within Jest hooks like beforeEach and afterEach. This ensures code runs at the appropriate time during the test lifecycle, maintaining isolation and predictability. ```javascript import { database, isCity } from "../database"; import { Logger } from "../../../src/Logger"; import { loadCities } from "../api"; jest.mock("../api"); const initializeCityDatabase = () => { database.addCity("Vienna"); database.addCity("San Juan"); database.addCity("Wellington"); }; const clearCityDatabase = () => { database.clear(); }; beforeEach(() => { initializeCityDatabase(); }); test("that persists cities", () => { expect(database.cities.length).toHaveLength(3); }); test("city database has Vienna", () => { expect(isCity("Vienna")).toBeTruthy(); }); test("city database has San Juan", () => { expect(isCity("San Juan")).toBeTruthy(); }); describe("when loading cities from the api", () => { let consoleWarnSpy; beforeEach(() => { consoleWarnSpy = jest.spyOn(console, "warn"); loadCities.mockResolvedValue(["Wellington", "London"]); }); it("does not duplicate cities", async () => { await database.loadCities(); expect(database.cities).toHaveLength(4); }); }); afterEach(() => { clearCityDatabase(); }); ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-set-size Shows the preferred and more performant way to get the size of a Set using the `size` property. ```javascript const size = new Set([1, 2, 3]).size; ``` -------------------------------- ### Correct code examples for unicorn/prefer-global-this Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-global-this These examples show the preferred usage of globalThis for cross-environment compatibility. ```javascript globalThis.alert("Hi"); if (typeof globalThis.Buffer !== "undefined") { } globalThis.postMessage("done"); ``` -------------------------------- ### Correct code examples for unicorn/prefer-math-min-max Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-math-min-max These examples demonstrate the preferred usage of Math.min() and Math.max() for simple comparisons. ```javascript Math.min(height, 50); Math.max(height, 50); ``` -------------------------------- ### Correct JSX Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/interactive-supports-focus These examples demonstrate correct usage, ensuring interactive elements are focusable. ```jsx
void 0} /> ``` ```jsx Click me! ``` ```jsx Click me too! ``` ```jsx Click ALL the things! ``` ```jsx ``` -------------------------------- ### Quick Start Migration with bun Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add oxfmt as a dev dependency, run the migration command, and then format your code using bun. ```bash $ bun add -D oxfmt@latest && bunx oxfmt --migrate=prettier && bunx oxfmt ``` -------------------------------- ### Correct Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/capitalized-comments Examples of code that adheres to the capitalized-comments rule when the 'always' option is used. Comments starting with non-letters are ignored. ```javascript // Capitalized comment /* Capitalized block comment */ // 123 - comments starting with non-letters are ignored ``` -------------------------------- ### Correct code example for unicorn/prefer-date-now Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-date-now This example shows the preferred way to get the current timestamp using `Date.now()`, which is considered more concise and efficient by the rule. ```javascript const ts = Date.now(); ``` -------------------------------- ### Quick Start Migration with npm Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add oxfmt as a dev dependency, run the migration command, and then format your code using npm. ```bash $ npm add -D oxfmt@latest && npx oxfmt --migrate=prettier && npx oxfmt ``` -------------------------------- ### Correct Promise Return Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/promise/always-return Examples of code that adheres to the promise/always-return rule. ```javascript myPromise.then((val) => val * 2); myPromise.then(function (val) { return val * 2; }); myPromise.then(doSomething); // could be either myPromise.then((b) => { if (b) { return "yes"; } else { return "no"; } }); ``` -------------------------------- ### Install Oxlint with pnpm Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Install oxlint as a development dependency using pnpm. ```sh $ pnpm add -D oxlint ``` -------------------------------- ### Disallow export in ``` -------------------------------- ### Using `createOnce` instead of `create` Source: https://oxc.rs/docs/guide/usage/linter/writing-js-plugins.html Demonstrates the change from ESLint's `create` API to Oxlint's `createOnce` API for per-file setup. ```diff - create(context) { + createOnce(context) { ``` -------------------------------- ### Quick Start Migration with pnpm Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add oxfmt as a dev dependency, run the migration command, and then format your code using pnpm. ```bash $ pnpm add -D oxfmt@latest && pnpm oxfmt --migrate=prettier && pnpm oxfmt ``` -------------------------------- ### Install Oxlint with npm Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Install oxlint as a development dependency using npm. ```sh $ npm add -D oxlint ``` -------------------------------- ### Quick Start Migration with yarn Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add oxfmt as a dev dependency, run the migration command, and then format your code using yarn. ```bash $ yarn add -D oxfmt@latest && yarn oxfmt --migrate=prettier && yarn oxfmt ``` -------------------------------- ### Allow variable declaration in ``` -------------------------------- ### Per-Extension Configuration Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/import/extensions Demonstrates how to configure specific extensions ('vue', 'ts', 'css') with different enforcement strategies ('always', 'never') and how package imports are handled when 'ignorePackages' is enabled. ```javascript // Configuration: { "vue": "always", "ts": "never" } import Component from "./Component.vue"; // ✓ OK - .vue configured as "always" import utils from "./utils"; // ✓ OK - .ts configured as "never" import styles from "./styles.css"; // ✓ OK - .css not configured, ignored // Configuration: ["ignorePackages", { "js": "never", "ts": "never" }] import foo from "./foo"; // ✓ OK - no extension import bar from "lodash/fp"; // ✓ OK - package import, ignored (ignorePackages sets this to true) ``` -------------------------------- ### Initialize Request with LSP Options Source: https://oxc.rs/docs/guide/usage/linter/lsp-config-reference.html Example of an `initialize` request sent by the client to the LSP server, including workspace-specific options. ```json { "processId": 123, "rootUri": null, "workspaceFolders": [], "capabilities": {}, "initializationOptions": [ { "workspaceUri": "file:///home/user/project", "options": { "unusedDisableDirectives": "deny", "typeAware": true } } ] } ``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-set-size Demonstrates the incorrect usage of converting a Set to an array to get its length. ```javascript const length = [...new Set([1, 2, 3])].length; ``` -------------------------------- ### Install Oxlint with yarn Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Install oxlint as a development dependency using yarn. ```sh $ yarn add -D oxlint ``` -------------------------------- ### Correct Code Examples for unicorn/empty-brace-spaces Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/empty-brace-spaces These examples demonstrate the correct formatting for braces after the unicorn/empty-brace-spaces rule has been applied. ```javascript const a = {}; class A {} ``` -------------------------------- ### Incorrect code examples for unicorn/prefer-date-now Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-date-now These examples demonstrate the incorrect usage patterns that the unicorn/prefer-date-now rule flags. It includes using `new Date().getTime()` and `new Date().valueOf()` to get the current timestamp. ```javascript const ts = new Date().getTime(); const ts = new Date().valueOf(); ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-trim-start-end Shows the preferred usage of String#trimStart() and String#trimEnd() for consistent string trimming. ```javascript str.trimStart(); str.trimEnd(); ``` -------------------------------- ### Correct code examples for unicorn/require-module-specifiers Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/require-module-specifiers These examples show valid import statements that adhere to the unicorn/require-module-specifiers rule. ```javascript import "foo"; import foo from "foo"; ``` -------------------------------- ### Correct test description format Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-lowercase-title Example of a test description that adheres to the rule by starting with a lowercase letter. ```javascript it("adds 1 + 2 to equal 3", () => { expect(sum(1, 2)).toBe(3); }); ``` -------------------------------- ### Incorrect test description format Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-lowercase-title Example of a test description that violates the rule by starting with an uppercase letter. ```javascript it("Adds 1 + 2 to equal 3", () => { expect(sum(1, 2)).toBe(3); }); ``` -------------------------------- ### Correct code examples for unicorn/no-immediate-mutation Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-immediate-mutation These examples show how to correctly initialize and mutate variables in a single step, avoiding the rule's violation. ```javascript const array = [1, 2, 3]; const object = { foo: 1, bar: 2 }; const set = new Set([1, 2, 3]); const map = new Map([ ["foo", 1], ["bar", 2], ]); ``` -------------------------------- ### Correct Usage with Imported Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/node/no-process-env This example demonstrates correct code by importing configuration from a separate file, adhering to the node/no-process-env rule. This approach improves testability and explicit configuration. ```javascript import config from "./config"; if (config.env === "development") { //... } ``` -------------------------------- ### Initialize oxfmt configuration file Source: https://oxc.rs/docs/guide/usage/formatter/quickstart.html Create a default `.oxfmtrc.json` configuration file. ```sh oxfmt --init ``` -------------------------------- ### Incorrect code example for no-div-regex Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-div-regex This snippet shows code that violates the no-div-regex rule by starting a regular expression with '/=foo/'. ```javascript function bar() { return /=foo/; } ``` -------------------------------- ### Correct Code Example (target: any) Source: https://oxc.rs/docs/guide/usage/linter/rules/import/prefer-default-export Provides a correct code example when the target is 'any'. This shows a module with a default export, even if other named exports exist. ```javascript export default function bar() {} ``` -------------------------------- ### Incorrect Code Example for jest/require-hook Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/require-hook This example demonstrates incorrect usage where setup and teardown logic are placed at the top level or directly within describe blocks, outside of Jest hooks. This can lead to unpredictable test behavior and issues with test isolation. ```javascript import { database, isCity } from "../database"; import { Logger } from "../../../src/Logger"; import { loadCities } from "../api"; jest.mock("../api"); const initializeCityDatabase = () => { database.addCity("Vienna"); database.addCity("San Juan"); database.addCity("Wellington"); }; const clearCityDatabase = () => { database.clear(); }; initializeCityDatabase(); test("that persists cities", () => { expect(database.cities.length).toHaveLength(3); }); test("city database has Vienna", () => { expect(isCity("Vienna")).toBeTruthy(); }); test("city database has San Juan", () => { expect(isCity("San Juan")).toBeTruthy(); }); describe("when loading cities from the api", () => { let consoleWarnSpy = jest.spyOn(console, "warn"); loadCities.mockResolvedValue(["Wellington", "London"]); it("does not duplicate cities", async () => { await database.loadCities(); expect(database.cities).toHaveLength(4); }); }); clearCityDatabase(); ``` -------------------------------- ### Examples of correct code for no-empty-pattern Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-empty-pattern Shows valid code examples that adhere to the no-empty-pattern rule. ```javascript var {a = {}} = foo; var {a = []} = foo; function foo({a = {}}) {} function foo({a = []}) {} ``` -------------------------------- ### Incorrect Vue.js Code with Watch After Await Source: https://oxc.rs/docs/guide/usage/linter/rules/vue/no-watch-after-await This example demonstrates incorrect usage where a `watch` is registered after an `await` in the `setup()` function, which is flagged by the rule. ```vue ``` -------------------------------- ### Disallow invalid fetch options Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-invalid-fetch-options Examples of incorrect code that would be flagged by the rule. This includes providing a body with a GET or HEAD method. ```javascript const response = await fetch("/", { method: "GET", body: "foo=bar" }); const request = new Request("/", { method: "GET", body: "foo=bar" }); ``` -------------------------------- ### Correct Code Examples for eqeqeq Rule ('smart' option) Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/eqeqeq These examples demonstrate correct usage with the 'smart' option for the eqeqeq rule, showing allowed loose comparisons. ```javascript /* eqeqeq: ["error", "smart"] */ if (typeof foo == "undefined") { } if (foo == null) { } if (foo != null) { } ``` -------------------------------- ### Incorrect code with lowercaseFirstCharacterOnly option Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-lowercase-title Example of incorrect code when 'lowercaseFirstCharacterOnly' is true, showing a violation where a nested describe block starts with an uppercase letter. ```js /* vitest/prefer-lowercase-title: ["error", { "lowercaseFirstCharacterOnly": true }] */ describe("MyClass", () => { describe("MyMethod", () => { it("does things", () => { // }); }); }); ``` -------------------------------- ### Correct Test File Path Example Source: https://oxc.rs/docs/guide/usage/linter/rules/vitest/consistent-test-filename Shows a file path that conforms to the configured naming convention for test files. ```text __tests__/2.spec.ts ``` -------------------------------- ### Allow Unique Hooks in Jest Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/no-duplicate-hooks These examples demonstrate correct usage where each hook type appears only once within its scope. This ensures a clear and predictable test setup. ```javascript describe("foo", () => { beforeEach(() => { // some setup }); test("foo_test", () => { // some test }); }); // Nested describe scenario describe("foo", () => { beforeEach(() => { // some setup }); test("foo_test", () => { // some test }); describe("bar", () => { test("bar_test", () => { beforeEach(() => { // some setup }); }); }); }); ``` -------------------------------- ### Install oxfmt with bun Source: https://oxc.rs/docs/guide/usage/formatter/quickstart.html Add oxfmt as a development dependency using bun. ```sh $ bun add -D oxfmt ``` -------------------------------- ### Allowing specific prefixes with allowedPrefixes Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-lowercase-title Demonstrates correct code when the 'allowedPrefixes' option is configured to permit titles starting with 'GET'. This is useful for API endpoint tests. ```js /* jest/prefer-lowercase-title: ["error", { "allowedPrefixes": ["GET"] }] */ describe("GET /live"); ``` -------------------------------- ### Correct Code Example for max-classes-per-file Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/max-classes-per-file This example shows code that adheres to the max-classes-per-file rule, as it does not contain any class definitions. ```javascript function foo() { var bar = 1; let baz = 2; const qux = 3; } ``` -------------------------------- ### Correct code examples for unicorn/prefer-array-find Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-array-find These examples demonstrate the preferred, more efficient usage of `find` and `findLast` for retrieving elements. ```javascript const match = users.find((u) => u.id === id); const match = users.find(fn); const match = users.findLast(fn); ``` -------------------------------- ### Correct Object and Class Syntax Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/accessor-pairs Examples of correct code demonstrating proper getter/setter pairs for properties in an object and a class. ```javascript var o = { set a(value) { this.val = value; }, get a() { return this.val; }, }; class C { set a(value) { this.val = value; } get a() { return this.val; } } ``` -------------------------------- ### Correct Vue.js Code with Watch Before Await Source: https://oxc.rs/docs/guide/usage/linter/rules/vue/no-watch-after-await This example shows the correct pattern where the `watch` is registered before any `await` expressions in the `setup()` function, thus avoiding the rule violation. ```vue ``` -------------------------------- ### TypeScript Configuration with Plugins and Rules (TypeScript) Source: https://oxc.rs/docs/guide/usage/linter/nested-config.html Example of a TypeScript-specific configuration file in TypeScript format. ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["typescript"], rules: { "typescript/no-explicit-any": "error", }, }); ``` -------------------------------- ### Example Configuration for jest/no-restricted-matchers Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/no-restricted-matchers Configure bans for Jest matchers and modifiers. The value can be a string message for alternatives or null to use the default message. Bans are checked against the start of the expect chain. ```json { "jest/no-restricted-matchers": [ "error", { "toBeFalsy": null, "resolves": "Use `expect(await promise)` instead.", "toHaveBeenCalledWith": null, "not.toHaveBeenCalledWith": null, "resolves.toHaveBeenCalledWith": null, "rejects.toHaveBeenCalledWith": null, "resolves.not.toHaveBeenCalledWith": null, "rejects.not.toHaveBeenCalledWith": null } ] } ``` -------------------------------- ### Correct Code Examples for promise/prefer-await-to-callbacks Source: https://oxc.rs/docs/guide/usage/linter/rules/promise/prefer-await-to-callbacks These examples show the preferred async/await syntax for asynchronous operations. They are more readable and easier to manage errors with. ```javascript await doSomething(arg); async function doSomethingElse() {} function* generator() { yield yieldValue((err) => {}); } eventEmitter.on("error", (err) => {}); ``` -------------------------------- ### Ignore specific filenames with 'ignore' option Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/filename-case The 'ignore' option accepts an array of regular expression patterns to exclude certain filenames from the casing rule. This example ignores filenames starting with 'foo'. ```json { "unicorn/filename-case": [ "error", { "ignore": ["^foo.*$"] } ] } ``` -------------------------------- ### Correct code example for unicorn/no-unnecessary-await Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-unnecessary-await Shows the correct way to use `await` with a promise. ```javascript async function bad() { await promise; } ``` -------------------------------- ### GitHub Actions workflow for Oxlint Source: https://oxc.rs/docs/guide/usage/linter/ci.html Configure a GitHub Actions workflow to run Oxlint on pull requests and pushes to the main branch. This setup includes checking out code, setting up Node.js, installing dependencies, and running the lint script. ```yaml name: Lint on: pull_request: push: branches: [main] permissions: {} jobs: oxlint: runs-on: ubuntu-latest steps: # NOTE: For security, it is strongly recommended to pin all # actions to a specific SHA hash instead of using a version # tag like this. - uses: actions/checkout@v7 with: persist-credentials: false - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v6 with: node-version: lts/* cache: pnpm # alternatively use npm install / yarn install here - run: pnpm install --frozen-lockfile - run: pnpm run lint ``` -------------------------------- ### Correct use of object spread and Object.assign Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/prefer-object-spread These examples demonstrate correct usage of object spread syntax and Object.assign. Object spread is preferred when starting with an empty object or merging properties. Object.assign is considered correct when its first argument is not an object literal. ```javascript ({ ...foo }); ({ ...baz, foo: "bar" }); // Any Object.assign call without an object literal as the first argument Object.assign(foo, { bar: baz }); Object.assign(foo, bar); Object.assign(foo, { bar, baz }); Object.assign(foo, { ...baz }); ``` -------------------------------- ### Additional Correct Code Examples for no-useless-computed-key Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-useless-computed-key Provides examples of correct code, including handling of '__proto__' and 'constructor' properties, and static properties. ```javascript const c = { __proto__: foo, // defines object's prototype ["__proto__"]: bar, // defines a property named "__proto__" }; class Foo { ["constructor"]; // instance field named "constructor" constructor() {} static ["constructor"]; static ["prototype"]; } ``` -------------------------------- ### Correct img alt text examples Source: https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/img-redundant-alt Examples of correct alt text that avoid redundant words or use variables. Includes an example of an aria-hidden image. ```jsx Foo eating a sandwich. Picture of me taking a photo of an image // Will pass because it is hidden. {`Baz // This is valid since photo is a variable name. ``` -------------------------------- ### Example configuration for unicorn/switch-case-braces Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/switch-case-braces Illustrates how to configure the unicorn/switch-case-braces rule with the 'avoid' option in a JSON configuration file. ```json "unicorn/switch-case-braces": ["error", "avoid"] ``` -------------------------------- ### Exported Name Example Source: https://oxc.rs/docs/guide/usage/linter/rules/import/namespace This is an example of an exported name from a module. ```javascript // ./foo.js export const bar = "I'm bar"; ``` -------------------------------- ### Correct code using async/await Source: https://oxc.rs/docs/guide/usage/linter/rules/promise/prefer-await-to-then This example demonstrates the preferred async/await syntax for handling Promises. ```javascript async function hi() { await thing(); } ``` -------------------------------- ### Enable eslint/complexity Rule in Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/complexity Demonstrates how to enable the eslint/complexity rule with default settings in various configuration formats. ```json { "rules": { "complexity": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ rules: { "complexity": "error", }, }); ``` ```bash oxlint --deny complexity ``` -------------------------------- ### Correct Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-assertion Examples of code that adheres to the `no-non-null-assertion` rule. ```typescript x; x?.y; x.y; ``` -------------------------------- ### Incorrect Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-assertion Examples of code that violates the `no-non-null-assertion` rule. ```typescript x!; x!.y; x.y!; ``` -------------------------------- ### Correct Code Examples for func-names (as-needed) Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/func-names Presents correct code patterns for the 'as-needed' option, showing where names are inferred or explicitly provided. ```javascript /* func-names: ["error", "as-needed"] */ const bar = function () {}; const cat = { meow: function () {} }; class C { #bar = function () {}; baz = function () {}; } quux ??= function () {}; (function bar() { /* ... */ })(); export default function foo() {} ``` -------------------------------- ### Correct Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-empty-interface Examples of code that adheres to the no-empty-interface rule. ```typescript interface Foo { member: string; } interface Bar extends Foo { member: string; } ``` -------------------------------- ### Install migrate-oxfmt skill Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add the migrate-oxfmt skill to your coding agent from the provided GitHub repository. ```bash npx skills add https://github.com/oxc-project/oxc --skill migrate-oxfmt ``` -------------------------------- ### Incorrect Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-empty-interface Examples of code that violates the no-empty-interface rule. ```typescript interface Foo {} interface Bar extends Foo {} ``` -------------------------------- ### Install Oxlint Globally Source: https://oxc.rs/docs/guide/usage/linter/editors.html Install the Oxlint CLI globally using npm. This is a prerequisite for using Oxlint as a language server in some editors. ```shell npm i -g oxlint ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unreachable This example shows code where all statements are reachable. ```typescript function foo() { console.log("this will be executed"); return 2; } ``` -------------------------------- ### Correct Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-template-curly-in-string Examples of code that adheres to the no-template-curly-in-string rule. ```javascript `Hello ${name}!`; `Time: ${12 * 60 * 60 * 1000}`; templateFunction`Hello ${name}`; ``` -------------------------------- ### Correct Usage of require Source: https://oxc.rs/docs/guide/usage/linter/rules/node/no-new-require This example shows the correct way to use 'require' to import a module and then instantiate it if it's a constructor. ```javascript var AppHeader = require("app-header"); var appHeader = new AppHeader(); ``` -------------------------------- ### Incorrect Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-template-curly-in-string Examples of code that violates the no-template-curly-in-string rule. ```javascript "Hello ${name}!"; "Hello ${name}!"; "Time: ${12 * 60 * 60 * 1000}"; ``` -------------------------------- ### Initialize Oxlint config file Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Generate a default .oxlintrc.json configuration file. ```sh oxlint --init ``` -------------------------------- ### Generator Function Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/func-names A basic example of a generator function definition. ```javascript function* foobar(i) { yield i; yield i + 10; } ``` -------------------------------- ### Correct React Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/react/no-unsafe Shows correct usage of React lifecycle methods, avoiding the unsafe ones. ```jsx class Foo extends React.Component { componentDidMount() {} componentDidUpdate() {} render() {} } ``` -------------------------------- ### Enable Rule with Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/node/callback-return Configuration examples for enabling the node/callback-return rule in Oxc using different methods. ```json { "plugins": ["node"], "rules": { "node/callback-return": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["node"], rules: { "node/callback-return": "error", }, }); ``` ```bash oxlint --deny node/callback-return --node-plugin ``` -------------------------------- ### Correct code examples for prefer-expect-type-of Source: https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-expect-type-of These examples show the preferred usage of `expect(value).toBeTypeOf(type)` which aligns with the vitest/prefer-expect-type-of rule. They cover the same primitive types as the incorrect examples. ```javascript test("type checking", () => { expect("hello").toBeTypeOf("string"); expect(42).toBeTypeOf("number"); expect(true).toBeTypeOf("boolean"); expect({}).toBeTypeOf("object"); expect(() => {}).toBeTypeOf("function"); expect(Symbol()).toBeTypeOf("symbol"); expect(123n).toBeTypeOf("bigint"); expect(undefined).toBeTypeOf("undefined"); }); ``` -------------------------------- ### Install Oxfmt with deno Source: https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html Add oxfmt as a development dependency to your project using deno. ```bash $ deno add -D npm:oxfmt@latest ``` -------------------------------- ### Empty File Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-empty-file An example of an empty file that violates the unicorn/no-empty-file rule. ```javascript ``` -------------------------------- ### Oxlint JSON Configuration Example Source: https://oxc.rs/docs/guide/usage/linter/config-file-reference.html Example of an Oxlint configuration file in JSON format. Use this for basic configuration and compatibility with ESLint. ```json { "$schema": "./node_modules/oxlint/configuration_schema.json", "plugins": ["import", "typescript", "unicorn"], "env": { "browser": true }, "globals": { "foo": "readonly" }, "settings": { "react": { "version": "18.2.0" }, "custom": { "option": true } }, "rules": { "eqeqeq": "warn", "import/no-cycle": "error", "react/self-closing-comp": [ "error", { "html": false } ] }, "overrides": [ { "files": ["*.test.ts", "*.spec.ts"], "rules": { "@typescript-eslint/no-explicit-any": "off" } } ] } ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier Examples of correct code that adheres to the typescript/no-unnecessary-qualifier rule. ```typescript namespace A { export type B = number; const value: B = 1; } ``` -------------------------------- ### Enable Rule with Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/vitest/no-standalone-expect Demonstrates how to enable the vitest/no-standalone-expect rule with an error severity level in different configuration formats. ```json { "plugins": ["vitest"], "rules": { "vitest/no-standalone-expect": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["vitest"], rules: { "vitest/no-standalone-expect": "error", }, }); ``` ```bash oxlint --deny vitest/no-standalone-expect --vitest-plugin ``` -------------------------------- ### Enable Rule with Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/func-style Shows how to enable the 'func-style' rule with a basic configuration in an Oxc configuration file. ```json { "rules": { "func-style": "error" } } ``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier Examples of incorrect code that the typescript/no-unnecessary-qualifier rule will flag. ```typescript namespace A { export type B = number; const value: A.B = 1; } ``` -------------------------------- ### Correct Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-nullish-coalescing These examples demonstrate code that adheres to the no-non-null-asserted-nullish-coalescing rule. ```typescript foo ?? bar; foo ?? bar!; foo!.bazz ?? bar; foo!.bazz ?? bar!; foo() ?? bar; ``` -------------------------------- ### Incorrect Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-nullish-coalescing These examples demonstrate code that violates the no-non-null-asserted-nullish-coalescing rule. ```typescript foo! ?? bar; foo.bazz! ?? bar; foo!.bazz! ?? bar; foo()! ?? bar; let x!: string; x! ?? ""; let x: string; x = foo(); x! ?? ""; ``` -------------------------------- ### Enable rule using .oxlintrc.json Source: https://oxc.rs/docs/guide/usage/linter/rules/vitest/consistent-test-it Configuration example for enabling the 'vitest/consistent-test-it' rule in an .oxlintrc.json file. ```json { "plugins": ["vitest"], "rules": { "vitest/consistent-test-it": "error" } } ``` -------------------------------- ### TypeScript Configuration with Plugins and Rules (JSON) Source: https://oxc.rs/docs/guide/usage/linter/nested-config.html Example of a TypeScript-specific configuration file in JSON format. ```json { "plugins": ["typescript"], "rules": { "typescript/no-explicit-any": "error" } } ``` -------------------------------- ### Incorrect Promise Return Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/promise/always-return Examples of code that violates the promise/always-return rule. ```javascript myPromise.then(function (val) {}); myPromise.then(() => { doSomething(); }); myPromise.then((b) => { if (b) { return "yes"; } else { forgotToReturn(); } }); ``` -------------------------------- ### Incorrect code examples for node/no-exports-assign Source: https://oxc.rs/docs/guide/usage/linter/rules/node/no-exports-assign Examples of code that violates the `node/no-exports-assign` rule. ```js exports = {}; ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/oxc/uninvoked-array-callback Shows the correct way to use an array callback by ensuring elements exist. ```javascript const list = new Array(5).fill().map((_) => createElement()); ``` -------------------------------- ### Enable vitest/require-hook Rule with Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/vitest/require-hook Demonstrates how to enable the vitest/require-hook rule in different configuration formats. ```json { "plugins": ["vitest"], "rules": { "vitest/require-hook": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["vitest"], rules: { "vitest/require-hook": "error", }, }); ``` ```bash oxlint --deny vitest/require-hook --vitest-plugin ``` -------------------------------- ### Correct dynamic import Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/import-style This example shows a correct way to handle dynamic import, importing the default export. ```javascript async () => { const { default: chalk } = await import("chalk"); }; ``` -------------------------------- ### Enable func-names Rule in Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/func-names Configuration examples for enabling the 'func-names' rule in different formats: JSON, TypeScript, and CLI. ```json { "rules": { "func-names": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ rules: { "func-names": "error", }, }); ``` ```bash oxlint --deny func-names ``` -------------------------------- ### Correct code example for unicorn/no-array-fill-with-reference-type Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-array-fill-with-reference-type Shows the correct way to initialize an array with unique object instances using Array.from() and a factory function. ```javascript const rows = Array.from({ length: 3 }, () => ({})); ``` -------------------------------- ### Correct Code Example (target: single) Source: https://oxc.rs/docs/guide/usage/linter/rules/import/prefer-default-export Demonstrates correct code when the target is 'single'. It shows a module with a named export and a default export. ```javascript export const foo = "foo"; const bar = "bar"; export default bar; ``` -------------------------------- ### Enable require-await Rule with Type Awareness Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/require-await Configuration examples to enable the typescript/require-await rule, ensuring type information is utilized. ```json { "options": { "typeAware": true }, "rules": { "typescript/require-await": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ options: { typeAware: true }, rules: { "typescript/require-await": "error", }, }); ``` ```bash oxlint --type-aware --deny typescript/require-await ``` -------------------------------- ### Correct Code Examples for no-control-regex Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-control-regex These examples show valid regular expressions that do not use control characters or their problematic escape sequences. They include examples with printable characters and standard whitespace escapes. ```javascript var pattern1 = /\x20/; var pattern2 = /\u0020/; var pattern3 = /\u{20}/u; var pattern4 = /\t/; var pattern5 = /\n/; var pattern6 = new RegExp("\x20"); var pattern7 = new RegExp("\\t"); var pattern8 = new RegExp("\\n"); ``` -------------------------------- ### Enable react/require-render-return Rule via CLI Source: https://oxc.rs/docs/guide/usage/linter/rules/react/require-render-return Illustrates how to enable the react/require-render-return rule directly from the command line interface. ```bash oxlint --deny react/require-render-return --react-plugin ``` -------------------------------- ### Incorrect Heading Example Source: https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/heading-has-content This example shows an empty heading element, which violates the rule. ```jsx

``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unreachable This example shows code that will never be executed after a return statement. ```typescript function foo() { return 2; console.log("this will never be executed"); } ``` -------------------------------- ### Correct Code Examples for unicorn/prefer-single-call Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-single-call Shows the correct, combined usage of Array#push/unshift, Element#classList.add/remove, and importScripts calls. ```javascript foo.push(1, 2); foo.unshift(2, 1); element.classList.add("foo", "bar"); importScripts("foo.js", "bar.js"); ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-redeclare This example demonstrates correct code where a variable 'a' is declared once and then reassigned. ```javascript var a = 3; a = 10; ``` -------------------------------- ### Format Files Source: https://oxc.rs/docs/guide/usage/formatter.html Run the 'fmt' script to format files in your project. ```sh pnpm run fmt ``` -------------------------------- ### Neovim: Install coc-oxc Source: https://oxc.rs/docs/guide/usage/formatter/editors.html Install the coc-oxc plugin for Neovim using the :CocInstall command. ```vim :CocInstall coc-oxc ``` -------------------------------- ### Styled Components Plugin Input Example Source: https://oxc.rs/docs/guide/usage/transformer/plugins.html Example of JSX code using styled-components before transformation. ```jsx import styled from "styled-components"; const Button = styled.div` color: blue; padding: 10px; `; ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-node-protocol This snippet demonstrates the correct way to import a Node.js built-in module using the 'node:' protocol. ```javascript import fs from "node:fs"; ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/vue/no-deprecated-vue-config-keycodes This example demonstrates code that adheres to the rule, avoiding the deprecated `Vue.config.keyCodes`. ```js Vue.config.silent = true; ``` -------------------------------- ### Example Configuration: Object Notation Source: https://oxc.rs/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence This configuration object allows fine-grained control over brace presence for props, children, and prop element values. ```jsonc { "rules": { "react/jsx-curly-brace-presence": ["error", { "props": , "children": , "propElementValues": }] } } ``` -------------------------------- ### Correct assert usage Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/consistent-assert This example demonstrates the preferred, correct usage of the assert module, utilizing `assert.ok()` for clearer intent. This aligns with the unicorn/consistent-assert rule. ```javascript import assert from "node:assert"; assert.ok(divide(10, 2) === 5); ``` -------------------------------- ### Root Configuration File (JSON) Source: https://oxc.rs/docs/guide/usage/linter/nested-config.html Example of a root .oxlintrc.json file defining a shared baseline rule. ```json { "rules": { "no-debugger": "error" } } ``` -------------------------------- ### Incorrect code examples for unicorn/prefer-math-min-max Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-math-min-max These examples show ternary expressions that can be replaced by Math.min() or Math.max(). ```javascript height > 50 ? 50 : height; height > 50 ? height : 50; ``` -------------------------------- ### Import Sorting with Partition by Comment Source: https://oxc.rs/docs/guide/usage/formatter/config-file-reference.html Demonstrates how to use comments to partition imports into logical groups. When enabled, comments act as delimiters, separating imports into distinct partitions. ```javascript import { b1, b2 } from "b"; // PARTITION import { a } from "a"; import { c } from "c"; ``` -------------------------------- ### Incorrect Type Conversion Example Source: https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-conversion Shows an example of unnecessary type conversion that the rule will flag. ```typescript const value = String("asdf"); ``` -------------------------------- ### Enable import/max-dependencies Rule in Oxlint Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/import/max-dependencies Demonstrates how to enable the import/max-dependencies rule in Oxlint using different configuration methods. ```json { "plugins": ["import"], "rules": { "import/max-dependencies": "error" } } ``` ```typescript import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["import"], rules: { "import/max-dependencies": "error", }, }); ``` ```bash oxlint --deny import/max-dependencies --import-plugin ``` -------------------------------- ### Neovim: Install oxfmt Source: https://oxc.rs/docs/guide/usage/formatter/editors.html Install the oxfmt binary globally using npm for use with Neovim's LSP configuration. ```shell npm i -g oxfmt ``` -------------------------------- ### Correct Export Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/import/export These examples show correct export patterns that adhere to the import/export rule. Renaming exports and using wildcard exports without conflicts are demonstrated. ```javascript let foo; export { foo as foo1 }; // Renamed export to avoid conflict export * from "./export-all"; // No conflict if export-all.js also exports foo ``` -------------------------------- ### Correct Heading Example Source: https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/heading-has-content This example shows a heading element with accessible content, satisfying the rule. ```jsx

Foo

``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/jest/no-test-return-statement This example shows incorrect usage where a test explicitly returns a value. ```javascript test("one", () => { return expect(1).toBe(1); }); ``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-useless-catch This example shows a catch clause that only rethrows the error, which is considered redundant. ```javascript try { doSomethingThatMightThrow(); } catch (e) { throw e; } ``` -------------------------------- ### Correct static import Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/import-style This example shows a correct static import style for the 'chalk' module, using a default import. ```javascript import chalk from "chalk"; ``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-irregular-whitespace This example demonstrates code with irregular whitespace characters that the linter will flag. ```javascript // Contains irregular whitespace characters (invisible) function example() { var foo = "bar"; // irregular whitespace before 'bar' } ``` -------------------------------- ### Enable Rule with Configuration Source: https://oxc.rs/docs/guide/usage/linter/rules/react/jsx-no-useless-fragment Demonstrates how to enable the react/jsx-no-useless-fragment rule in various configuration formats. ```json { "plugins": ["react"], "rules": { "react/jsx-no-useless-fragment": "error" } } ``` ```ts import { defineConfig } from "oxlint"; export default defineConfig({ plugins: ["react"], rules: { "react/jsx-no-useless-fragment": "error", }, }); ``` ```bash oxlint --deny react/jsx-no-useless-fragment --react-plugin ``` -------------------------------- ### Incorrect Code Example for no-lone-blocks Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-lone-blocks This snippet shows an example of code that violates the no-lone-blocks rule. ```javascript { var x = 1; } ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/nextjs/no-document-import-in-page Shows the correct usage of importing `next/document` within the `pages/_document.js` file. ```jsx // `pages/_document.jsx` import Document from "next/document"; class MyDocument extends Document { //... } export default MyDocument; ``` -------------------------------- ### Olint Configuration for promise/no-return-wrap Source: https://oxc.rs/docs/guide/usage/linter/rules/promise/no-return-wrap Configuration examples for enabling the promise/no-return-wrap rule in Oxlint using different formats. ```json { "plugins": ["promise"], "rules": { "promise/no-return-wrap": "error" } } ``` -------------------------------- ### Examples of incorrect code for no-empty-pattern Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-empty-pattern Provides various examples of code that violate the no-empty-pattern rule. ```javascript var {} = foo; var [] = foo; var {a: {}} = foo; var {a: []} = foo; function foo({}) {} function foo([]) {} function foo({a: {}}) {} function foo({a: []}) {} ``` -------------------------------- ### Correct Code Examples for no-object-constructor Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-object-constructor These examples demonstrate correct usage of the Object constructor or alternative patterns that are allowed by the rule. ```javascript Object("foo"); const obj = { a: 1, b: 2 }; const isObject = (value) => value === Object(value); const createObject = (Object) => new Object(); ``` -------------------------------- ### Run Oxlint after creating config Source: https://oxc.rs/docs/guide/usage/linter/quickstart.html Execute Oxlint after initializing and customizing the configuration file. ```sh oxlint ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-dupe-class-members This example shows correct code where class members do not have duplicate names. ```javascript class A { foo() { console.log("foo"); } } let a = new A(); a.foo(); ``` -------------------------------- ### Incorrect Code Examples Source: https://oxc.rs/docs/guide/usage/linter/rules/eslint/capitalized-comments Examples of code that violates the capitalized-comments rule when the 'always' option is used. ```javascript // lowercase comment /* lowercase block comment */ ``` -------------------------------- ### Enable Rule with Configuration (JSON) Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping Enable the unicorn/consistent-function-scoping rule with 'error' severity using a JSON configuration file. ```json { "rules": { "unicorn/consistent-function-scoping": "error" } } ``` -------------------------------- ### Correct Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-type-error This example demonstrates correct code that adheres to the unicorn/prefer-type-error rule by throwing a TypeError. ```javascript if (Array.isArray(foo)) { throw new TypeError("Expected foo to be an array"); } ``` -------------------------------- ### Correct Import Order Example Source: https://oxc.rs/docs/guide/usage/linter/rules/import/first This code adheres to the import/first rule by placing all imports at the beginning of the file. ```js import { x } from "./foo"; import { y } from "./bar"; export { x, y }; ``` -------------------------------- ### Incorrect Code Example Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-type-error This example shows code that violates the unicorn/prefer-type-error rule by throwing a generic Error. ```javascript if (Array.isArray(foo)) { throw new Error("Expected foo to be an array"); } ``` -------------------------------- ### Example Configuration: String Notation Source: https://oxc.rs/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence A simpler configuration using a string value ('always', 'never', or 'ignore') to apply a consistent rule across props and children. ```jsonc { "rules": { "react/jsx-curly-brace-presence": ["error", "always"], // or "never" or "ignore" }, } ``` -------------------------------- ### Correct code examples for unicorn/prefer-prototype-methods Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-prototype-methods Examples of code that adheres to the unicorn/prefer-prototype-methods rule by borrowing methods from prototypes. ```javascript const array = Array.prototype.slice.apply(bar); const type = Object.prototype.toString.call(foo); Reflect.apply(Array.prototype.forEach, arrayLike, [callback]); const maxValue = Math.max.apply(Math, numbers); ``` -------------------------------- ### Incorrect code examples for unicorn/prefer-prototype-methods Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-prototype-methods Examples of code that violates the unicorn/prefer-prototype-methods rule by borrowing methods from instances. ```javascript const array = [].slice.apply(bar); const type = {}.toString.call(foo); Reflect.apply([].forEach, arrayLike, [callback]); ``` -------------------------------- ### Enable jsdoc/require-throws-description rule via CLI Source: https://oxc.rs/docs/guide/usage/linter/rules/jsdoc/require-throws-description Activate the jsdoc/require-throws-description rule directly from the command line using the --deny flag and specifying the jsdoc plugin. ```bash oxlint --deny jsdoc/require-throws-description --jsdoc-plugin ``` -------------------------------- ### Install oxfmt with pnpm Source: https://oxc.rs/docs/guide/usage/formatter/quickstart.html Add oxfmt as a development dependency using pnpm. ```sh $ pnpm add -D oxfmt ```