XO Linter
XO is an opinionated JavaScript and TypeScript linter that wraps ESLint, providing a zero-configuration setup with strict, readable code defaults. It aims to streamline code style enforcement and eliminate style-related discussions in pull requests. The current stable version is 2.0.2, with a relatively active release cadence to incorporate updates and maintain compatibility with its underlying dependencies. Key differentiators include its batteries-included approach, which bundles many useful ESLint plugins (e.g., `unicorn`, `import-x`, `n`), automatic caching for performance, first-class TypeScript support, and flexible integration options, including optional Prettier usage. It mandates an ESM-only project structure for optimal functionality.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module <path_to_xo>/index.js from <your_file> not supported.
cause Attempting to import XO programmatically using CommonJS `require()` syntax in an ES module context, or running XO in a project that is not configured as an ES module.fixChange your import statement to `import xo from 'xo';` if using XO programmatically. Ensure your `package.json` has `"type": "module"` if your `.js` files are intended to be ESM. -
Your current Node.js version is <version>. XO requires Node.js >= 20.19.
cause The installed Node.js version is older than the minimum required by XO v2.0.0+.fixUpdate your Node.js installation to version 20.19 or newer. Consider using a version manager like `nvm` or `volta`. -
ESLint couldn't find the plugin "eslint-plugin-promise".
cause This specific plugin's rules were temporarily removed from XO v2.0.0 due to compatibility issues with ESLint 10.fixThis is expected behavior in XO v2.0.0. You cannot re-enable these rules until XO re-integrates them in a future release. Review your linting expectations accordingly. -
ESLint couldn't find the config "<config_name>" to extend from.
cause A configuration file (e.g., `xo.config.js`) might be trying to extend a CJS-specific configuration or an older config that's no longer compatible with ESLint 10.fixVerify your `xo.config.js` or similar file is using correct ESM syntax and extending valid, compatible configurations. Ensure there are no CJS-style `module.exports` or `require()` calls within the config file itself.
Warnings
- breaking XO v2.0.0 and later require Node.js version 20.19 or higher. Older Node.js versions are not supported.
- breaking XO v2.0.0 and later require ESLint version 10. Ensure your project's ESLint dependency (if any) is compatible or allow XO to manage its own ESLint peer dependency.
- breaking CommonJS (CJS) config files are no longer supported. Configuration must be provided in ES module format (e.g., `.js`, `.mjs`, `.ts`, `.mts`) as XO is an ESM-only package.
- breaking The `eslint-plugin-promise` rules were temporarily removed in v2.0.0 due to compatibility issues with ESLint 10. This may affect existing projects relying on these specific rules.
- gotcha XO is strictly an ESM-only package. Attempting to use `require()` or run XO in a non-ESM Node.js environment will result in errors.
Install
-
npm install xo -
yarn add xo -
pnpm add xo
Imports
- xo
const xo = require('xo');import xo from 'xo';
- create-xo
npm init xo
- eslint-config-xo-react
/* configured via 'react' option or implicitly */
Quickstart
{
"name": "my-project",
"version": "1.0.0",
"type": "module",
"devDependencies": {
"xo": "^2.0.0"
},
"scripts": {
"lint": "xo",
"lint:fix": "xo --fix"
}
}
// src/index.js
const myVar = 'hello' ; // Linting issue: extra space, single quotes
function MyComponent(props) { // Linting issue: function-style component for React
return (<div>{props.message}</div>);
}
console.log(myVar, MyComponent);
// To run:
// npm install
// npm run lint
// npm run lint:fix