The oxlint configuration containing hapi style guide rules and config. To use in your project, add
@hapi/oxc-plugin to your package.json, then in your oxlint.config.ts add:
import { defineConfig } from 'oxlint';
import DefaultOxlintConfig from '@hapi/oxc-plugin/oxlint';
export default defineConfig({
extends: [DefaultOxlintConfig],
env: {
...DefaultOxlintConfig.env,
},
});The oxfmt configuration containing hapi style guide formatting rules. To use in your project, add
@hapi/oxc-plugin to your package.json, then in your oxfmt.config.ts add:
import { defineConfig } from 'oxfmt';
import DefaultOxfmtConfig from '@hapi/oxc-plugin/oxfmt';
export default defineConfig({
...DefaultOxfmtConfig,
});This plugin includes the following Oxlint rules:
Enforces capitalization of imported module variables.
If the string 'global-scope-only' is passed as the first option to this rule,
then it will only be enforced on assignments in the module's top level scope.
Enforces for loop iterator variable rules and restricts loop nesting depth.
This rule enforces the following:
- Restrict iterator variable names.
forloop iterator variables should be namedi. Nested loops should use the variablesj,k, and so on. - Restrict loop nesting. You can restrict the maximum nesting of
forloops. By default, this limit is three. - Prevent postfix increment and decrement operators. The hapi style guide does not allow postfix increment and decrement operators in
forloop updates. The prefix version of these operators should be used instead. - Single variable declaration in initialization section. A single
var i = 0;is allowed in the initialization section. This only applies to variable declarations, not assignments to existing variables. This means thatfor (i = 0, j = 0)is allowed ifiandjare existing variables. Variable declarations involving destructuring are not allowed.
This rule can be configured by providing a single options object. The object supports the following keys.
A number representing the maximum allowed nesting of for loops. Defaults to three.
The first variable iterator name to use. This defaults to 'i'.
Enforces the usage of var declarations only in try-catch scope.
Prevents arrow functions that implicitly create additional arrow functions.
This rule prevents the pattern () => () => () => ...;.
Functions can still be returned by arrow functions whose bodies use curly braces and an explicit return.
This rule does not accept any configuration options.
This plugin also exposes a Vitest plugin at @hapi/oxc-plugin/vitest. It runs
the oxlint and oxfmt checks as a dedicated test project, so linting and formatting violations surface
as failing tests in your existing test run.
The Vitest plugin requires vitest >= 4 in your project. It is an optional part of this package, so vitest
is not declared as a peer dependency.
To use it, add @hapi/oxc-plugin to your package.json, then
in your vitest.config.js add:
import { defineConfig } from 'vitest/config';
import oxc from '@hapi/oxc-plugin/vitest';
export default defineConfig({
plugins: [oxc()],
});When run, the plugin checks for an existing oxlint or oxfmt configuration in the working directory. If none is found, it falls back to the configurations shipped by this plugin.
The plugin accepts a single options object with the following keys.
A boolean controlling whether the oxlint check runs. Defaults to true.
A boolean controlling whether the oxfmt check runs. Defaults to true.
The working directory the checks run against. Defaults to process.cwd().