CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-xo

JavaScript/TypeScript linter (ESLint wrapper) with great defaults

Overview
Eval results
Files

cli-interface.mddocs/

CLI Interface

XO provides a comprehensive command-line interface for linting JavaScript and TypeScript projects with zero configuration required.

Capabilities

Basic Usage

# Lint all supported files in current directory
xo

# Lint specific files or patterns
xo index.js src/*.ts test/**/*.js

# Lint with glob patterns
xo "src/**/*.{js,ts}" "test/**/*.spec.*"

Auto-fixing

Automatically fix linting issues where possible.

# Fix all fixable issues
xo --fix

# Fix specific files
xo --fix src/index.js

# Combine with other options
xo --fix --space --react src/

Formatting Options

Control code style and formatting preferences.

# Use spaces instead of tabs (default: 2 spaces)
xo --space

# Use specific number of spaces
xo --space 4

# Force tab indentation
xo --space false

# Control semicolon usage
xo --semicolon        # Require semicolons (default)
xo --no-semicolon     # Disallow semicolons

Prettier Integration

Enable Prettier formatting integration.

# Format with Prettier
xo --prettier

# Prettier compatibility mode (disable conflicting rules)
xo --prettier=compat

React Support

Enable React-specific linting rules.

# Enable React support
xo --react

# Combine with other options
xo --react --prettier --space 2

Configuration

Specify custom configuration files and working directories.

# Use custom config file
xo --config ./custom-xo.config.js

# Set working directory
xo --cwd /path/to/project

# Combine configuration options
xo --config ./xo.config.js --cwd ./src

Output Control

Control what gets displayed in the output.

# Show only errors (hide warnings)
xo --quiet

# Use specific reporter
xo --reporter json
xo --reporter compact
xo --reporter unix

# Print effective ESLint config for a file
xo --print-config=src/index.js

Ignore Patterns

Specify files and directories to ignore.

# Ignore specific patterns
xo --ignore "dist/**" --ignore "*.min.js"

# Multiple ignore patterns
xo --ignore "node_modules/**" --ignore "coverage/**" --ignore "build/**"

Editor Integration

Open files with issues directly in your editor.

# Open files with issues in editor
xo --open

# Combine with other options
xo --open --quiet

Stdin Support

Lint code from standard input.

# Lint from stdin
echo "console.log('hello')" | xo --stdin

# Specify filename for context
echo "const x: string = 'test'" | xo --stdin --stdin-filename="test.ts"

# Fix stdin input
echo "console.log( 'hello' )" | xo --stdin --fix

Version Information

# Show XO version
xo --version

CLI Options Reference

interface CliFlags {
  /** Automatically fix issues (default: false) */
  fix: boolean;
  
  /** Reporter to use for output formatting */
  reporter?: string;
  
  /** Space indentation configuration (string that gets parsed) */
  space?: string;
  
  /** Path to XO configuration file */
  configPath?: string;
  
  /** Show only errors, not warnings */
  quiet?: boolean;
  
  /** Use semicolons at end of statements */
  semicolon?: boolean;
  
  /** Enable Prettier integration */
  prettier?: boolean;
  
  /** Enable React-specific rules (default: false) */
  react: boolean;
  
  /** Working directory for files (default: process.cwd()) */
  cwd: string;
  
  /** Print effective ESLint config for file */
  printConfig?: string;
  
  /** Show version information */
  version?: boolean;
  
  /** Read code from stdin */
  stdin?: boolean;
  
  /** Filename for stdin input (default: "stdin.js") */
  stdinFilename: string;
  
  /** Open files with issues in editor */
  open?: boolean;
  
  /** Ignore pattern globs (can be specified multiple times) */
  ignore: string[];
}

Exit Codes

XO uses standard exit codes to indicate the result of linting:

  • 0: No errors found (warnings may be present)
  • 1: Errors found or linting failed

Examples

Common Development Workflows

# Standard development setup
xo --fix --space 2 --react

# Pre-commit hook setup
xo --quiet --reporter=compact

# CI/CD pipeline
xo --reporter=junit --quiet

# Debug configuration
xo --print-config=src/index.ts

Advanced Usage

# Custom ignore patterns for build artifacts
xo --ignore "dist/**" --ignore "build/**" --ignore "*.generated.*"

# TypeScript project with custom config
xo --config ./tsconfig.eslint.json --cwd ./src "**/*.{ts,tsx}"

# Multi-project monorepo
xo --cwd ./packages/frontend --react --prettier
xo --cwd ./packages/backend --space 4

Integration Examples

# Package.json script
"scripts": {
  "lint": "xo",
  "lint:fix": "xo --fix",
  "lint:ci": "xo --quiet --reporter=junit"
}

# Git pre-commit hook
#!/bin/sh
xo --fix --quiet && git add .

# VS Code task
{
  "type": "shell",
  "command": "xo",
  "args": ["--fix", "--open"],
  "group": "build"
}

Error Handling

XO provides clear error messages and suggestions:

# Configuration errors
$ xo --print-config=""
Error: The `--print-config` flag must be used with exactly one filename

# Invalid options
$ xo --invalid-option
Error: Unknown option: --invalid-option

# File access errors
$ xo --config ./missing-config.js
Error: Config file not found: ./missing-config.js

Environment Variables

XO respects certain environment variables:

# GitHub Actions integration (automatically enables quiet mode)
GITHUB_ACTIONS=true xo

# Node.js options
NODE_OPTIONS="--max-old-space-size=8192" xo large-project/

Reporter Options

XO supports multiple built-in reporters:

  • stylish (default): Human-readable format with colors
  • compact: Compact format for CI environments
  • json: Machine-readable JSON output
  • junit: JUnit XML format for CI integration
  • checkstyle: Checkstyle XML format
  • tap: TAP (Test Anything Protocol) format
  • unix: Unix-style format
# Examples of different reporters
xo --reporter=json > lint-results.json
xo --reporter=junit > junit-results.xml
xo --reporter=compact --quiet

Install with Tessl CLI

npx tessl i tessl/npm-xo

docs

cli-interface.md

configuration.md

index.md

programmatic-api.md

tile.json