XO is an opinionated and minimal code linter and formatter for JavaScript and TypeScript. It helps developers maintain consistent code style and catch potential errors early in the development process. By enforcing a set of predefined rules, XO streamlines the coding workflow and reduces the time spent on manual code reviews and formatting.
To begin using XO, you need to install it as a development dependency in your project. This is typically done using npm or yarn.
# Initialize XO in a JavaScript project, installing it as a development dependency
npm install --save-dev xo
Once installed, you can run XO from your command line to lint files in your project. The tool automatically detects your project type and applies relevant rules.
# Lint files in the current directory
xo
# Lint files in a specific directory
xo ./src
XO can automatically fix many common code style issues. This feature is invaluable for quickly resolving formatting inconsistencies and minor errors.
# Fix issues automatically
xo --fix
# Fix issues and format files (e.g., enforcing spaces)
xo --fix --space
While XO is opinionated, it offers flexibility through configuration files and command-line options to tailor its behavior to your project's specific needs.
# Lint files based on specific environment settings (like Node.js or browser)
xo --env=node
# Use a specific linter configuration file
xo --config=path/to/.xoconfig
# Lint files that match a specific pattern
xo "src/**/*.js"
# Customize rules directly in command line
xo --rule="semi: ['error', 'always']"
# Ignore a specific file or pattern
xo --ignore="ignored-file.js"
# Check specific file extensions
xo --extension=jsx
Accessing help and version information is straightforward with XO's command-line interface.
# Display the help and available options
xo --help
# Display the version number of XO
xo --version
- XO GitHub Repository
- ESLint Configuration Guide (XO uses ESLint internally)
- MDN JavaScript Guide