or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-interface.mdconfiguration.mdindex.mdprogrammatic-api.md

cli-interface.mddocs/

0

# CLI Interface

1

2

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

3

4

## Capabilities

5

6

### Basic Usage

7

8

```bash

9

# Lint all supported files in current directory

10

xo

11

12

# Lint specific files or patterns

13

xo index.js src/*.ts test/**/*.js

14

15

# Lint with glob patterns

16

xo "src/**/*.{js,ts}" "test/**/*.spec.*"

17

```

18

19

### Auto-fixing

20

21

Automatically fix linting issues where possible.

22

23

```bash

24

# Fix all fixable issues

25

xo --fix

26

27

# Fix specific files

28

xo --fix src/index.js

29

30

# Combine with other options

31

xo --fix --space --react src/

32

```

33

34

### Formatting Options

35

36

Control code style and formatting preferences.

37

38

```bash

39

# Use spaces instead of tabs (default: 2 spaces)

40

xo --space

41

42

# Use specific number of spaces

43

xo --space 4

44

45

# Force tab indentation

46

xo --space false

47

48

# Control semicolon usage

49

xo --semicolon # Require semicolons (default)

50

xo --no-semicolon # Disallow semicolons

51

```

52

53

### Prettier Integration

54

55

Enable Prettier formatting integration.

56

57

```bash

58

# Format with Prettier

59

xo --prettier

60

61

# Prettier compatibility mode (disable conflicting rules)

62

xo --prettier=compat

63

```

64

65

### React Support

66

67

Enable React-specific linting rules.

68

69

```bash

70

# Enable React support

71

xo --react

72

73

# Combine with other options

74

xo --react --prettier --space 2

75

```

76

77

### Configuration

78

79

Specify custom configuration files and working directories.

80

81

```bash

82

# Use custom config file

83

xo --config ./custom-xo.config.js

84

85

# Set working directory

86

xo --cwd /path/to/project

87

88

# Combine configuration options

89

xo --config ./xo.config.js --cwd ./src

90

```

91

92

### Output Control

93

94

Control what gets displayed in the output.

95

96

```bash

97

# Show only errors (hide warnings)

98

xo --quiet

99

100

# Use specific reporter

101

xo --reporter json

102

xo --reporter compact

103

xo --reporter unix

104

105

# Print effective ESLint config for a file

106

xo --print-config=src/index.js

107

```

108

109

### Ignore Patterns

110

111

Specify files and directories to ignore.

112

113

```bash

114

# Ignore specific patterns

115

xo --ignore "dist/**" --ignore "*.min.js"

116

117

# Multiple ignore patterns

118

xo --ignore "node_modules/**" --ignore "coverage/**" --ignore "build/**"

119

```

120

121

### Editor Integration

122

123

Open files with issues directly in your editor.

124

125

```bash

126

# Open files with issues in editor

127

xo --open

128

129

# Combine with other options

130

xo --open --quiet

131

```

132

133

### Stdin Support

134

135

Lint code from standard input.

136

137

```bash

138

# Lint from stdin

139

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

140

141

# Specify filename for context

142

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

143

144

# Fix stdin input

145

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

146

```

147

148

### Version Information

149

150

```bash

151

# Show XO version

152

xo --version

153

```

154

155

## CLI Options Reference

156

157

```typescript { .api }

158

interface CliFlags {

159

/** Automatically fix issues (default: false) */

160

fix: boolean;

161

162

/** Reporter to use for output formatting */

163

reporter?: string;

164

165

/** Space indentation configuration (string that gets parsed) */

166

space?: string;

167

168

/** Path to XO configuration file */

169

configPath?: string;

170

171

/** Show only errors, not warnings */

172

quiet?: boolean;

173

174

/** Use semicolons at end of statements */

175

semicolon?: boolean;

176

177

/** Enable Prettier integration */

178

prettier?: boolean;

179

180

/** Enable React-specific rules (default: false) */

181

react: boolean;

182

183

/** Working directory for files (default: process.cwd()) */

184

cwd: string;

185

186

/** Print effective ESLint config for file */

187

printConfig?: string;

188

189

/** Show version information */

190

version?: boolean;

191

192

/** Read code from stdin */

193

stdin?: boolean;

194

195

/** Filename for stdin input (default: "stdin.js") */

196

stdinFilename: string;

197

198

/** Open files with issues in editor */

199

open?: boolean;

200

201

/** Ignore pattern globs (can be specified multiple times) */

202

ignore: string[];

203

}

204

```

205

206

## Exit Codes

207

208

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

209

210

- **0**: No errors found (warnings may be present)

211

- **1**: Errors found or linting failed

212

213

## Examples

214

215

### Common Development Workflows

216

217

```bash

218

# Standard development setup

219

xo --fix --space 2 --react

220

221

# Pre-commit hook setup

222

xo --quiet --reporter=compact

223

224

# CI/CD pipeline

225

xo --reporter=junit --quiet

226

227

# Debug configuration

228

xo --print-config=src/index.ts

229

```

230

231

### Advanced Usage

232

233

```bash

234

# Custom ignore patterns for build artifacts

235

xo --ignore "dist/**" --ignore "build/**" --ignore "*.generated.*"

236

237

# TypeScript project with custom config

238

xo --config ./tsconfig.eslint.json --cwd ./src "**/*.{ts,tsx}"

239

240

# Multi-project monorepo

241

xo --cwd ./packages/frontend --react --prettier

242

xo --cwd ./packages/backend --space 4

243

```

244

245

### Integration Examples

246

247

```bash

248

# Package.json script

249

"scripts": {

250

"lint": "xo",

251

"lint:fix": "xo --fix",

252

"lint:ci": "xo --quiet --reporter=junit"

253

}

254

255

# Git pre-commit hook

256

#!/bin/sh

257

xo --fix --quiet && git add .

258

259

# VS Code task

260

{

261

"type": "shell",

262

"command": "xo",

263

"args": ["--fix", "--open"],

264

"group": "build"

265

}

266

```

267

268

## Error Handling

269

270

XO provides clear error messages and suggestions:

271

272

```bash

273

# Configuration errors

274

$ xo --print-config=""

275

Error: The `--print-config` flag must be used with exactly one filename

276

277

# Invalid options

278

$ xo --invalid-option

279

Error: Unknown option: --invalid-option

280

281

# File access errors

282

$ xo --config ./missing-config.js

283

Error: Config file not found: ./missing-config.js

284

```

285

286

## Environment Variables

287

288

XO respects certain environment variables:

289

290

```bash

291

# GitHub Actions integration (automatically enables quiet mode)

292

GITHUB_ACTIONS=true xo

293

294

# Node.js options

295

NODE_OPTIONS="--max-old-space-size=8192" xo large-project/

296

```

297

298

## Reporter Options

299

300

XO supports multiple built-in reporters:

301

302

- `stylish` (default): Human-readable format with colors

303

- `compact`: Compact format for CI environments

304

- `json`: Machine-readable JSON output

305

- `junit`: JUnit XML format for CI integration

306

- `checkstyle`: Checkstyle XML format

307

- `tap`: TAP (Test Anything Protocol) format

308

- `unix`: Unix-style format

309

310

```bash

311

# Examples of different reporters

312

xo --reporter=json > lint-results.json

313

xo --reporter=junit > junit-results.xml

314

xo --reporter=compact --quiet

315

```