Skip to content

52-entertainment/vite-plugin-oxlint

Repository files navigation

⚓️+⚡️Vite Plugin Oxlint

This is a Vite plugin for integrating the Oxlint linter into your Vite project.

Installation

npm install vite-plugin-oxlint oxlint

Usage

Add the plugin to your vite.config.js file.

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [oxlintPlugin()]
}

Advanced Usage

Oxlint Configuration File

You can use a configuration file. See Oxlint configuration file.

Allow / Deny / Warn will override config file rules.

Default is oxlintrc.json.

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      configFile: 'eslintrc.json'
    })
  ]
}

Change working directory

You can change the directory where oxlint will run. Default is the root of your project.

Example: only lint files in your src directory.

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      path: 'src'
    })
  ]
}

Ignore patterns

You can specify patterns of files to ignore. The supported syntax is the same as for .eslintignore and .gitignore files. You should quote your patterns to avoid shell interpretation of glob patterns. See oxlint ignore

Example: lint files in your src directory, but not test.js files:

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      path: 'src',
      ignorePattern: '"test.js"'
    })
  ]
}

Allow / Deny / Warn rules

You can allow, deny or warn oxlint rules or categories. To see the list of available rules and categories, run: npx oxlint --rules This will override config file rules.

Example: deny (turn on) correctness and perf rules and allow (turn off) the debugger and eqeqeq rules.

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      deny: ['correctness', 'perf'],
      allow: ['debugger', 'eqeqeq'],
      warn: []
    })
  ]
}

Additional oxlint config:

You can pass any additional oxlint config as a string. See oxlint options for a list of available options.

Example: add the --deny-warnings and --quiet options to the vite-plugin-oxlint config:

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      params: '--deny-warnings --quiet'
    })
  ]
}

Change oxlint path

If you're using this plugin in a monorepo and encountering "command not found: oxlint" errors, you can manually specify the path to the oxlint binary.

If no local oxlint binary is found, the plugin will gracefully fall back to using npx (or the equivalent command for your package manager).

import oxlintPlugin from 'vite-plugin-oxlint'

export default {
  plugins: [
    oxlintPlugin({
      oxlintPath: '/path/to/your/monorepo/node_modules/.bin/oxlint'
    })
  ]
}

Integration with ESLint

If your project still needs ESLint, you can use vite-plugin-eslint and configure ESLint with eslint-plugin-oxlint to turn off rules already supported by oxlint.

import oxlintPlugin from 'vite-plugin-oxlint'
import eslintPlugin from 'vite-plugin-eslint'

export default {
  plugins: [oxlintPlugin(), eslintPlugin()]
}

License

MIT LICENSE

GitHub

About

⚓️+⚡️- Oxlint plugin for vite.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5