Skip to content

Rule Customization

Change severity, merge options, disable or add a rule, and isolate diagnostics without forking a prebuilt configuration.

The package exports five in-place helpers for narrow project exceptions:

import {
  addRule,
  configureRule,
  disableAllRulesBut,
  disableRule,
  getOxlintConfig,
  setRuleSeverity,
} from "oxlint-config-setup";

const config = getOxlintConfig({ react: true, ai: true });

setRuleSeverity(config, "eslint/no-warning-comments", "error");
configureRule(config, "eslint/valid-typeof", [
  { requireStringLiterals: true },
]);
disableRule(config, "typescript/no-extra-non-null-assertion");
addRule(config, "eslint/no-alert", "error");

export default config;

Helper behavior

HelperEffect
setRuleSeverityChanges severity while preserving options.
configureRuleMerges supplied options while preserving severity.
disableRuleTurns every explicit occurrence off.
addRuleAdds or replaces a rule in the root configuration.
disableAllRulesButDisables every other explicit rule for diagnostics.

The first three update explicit root and existing file-override occurrences. Missing rules are left unchanged.

Option merge semantics

configureRule recursively merges plain option objects. Arrays, primitive values, and null replace the value at their positional index. Positional options not included in the patch remain unchanged.

Given:

["error", { allow: ["legacy"], limits: { min: 1, max: 10 } }, "secondary"]

this patch:

configureRule(config, "plugin/rule", [
  { allow: ["modern"], limits: { max: 20 } },
]);

produces:

["error", { allow: ["modern"], limits: { min: 1, max: 20 } }, "secondary"]

The array is replaced, while limits.min and the trailing positional option are retained.

Scoped composition targets

Unscoped calls update the root and every explicit override occurrence. A config created by getComposedOxlintConfig() also supports a final { scope } target:

disableRule(config, "vitest/no-focused-tests", { scope: "vitest" });

The target is an identity assigned to the package-created file override, not a guess based on a glob. Unknown and unselected scopes throw. User-authored overrides remain ordinary Oxlint overrides and are intentionally not given a package scope identity.