JavaScript happiness style linter ❤️

JavaScript happiness style linter ❤️

Enforce strict code style. Never discuss code style on a pull request again!

No decision-making. No .eslintrc, .jshintrc, .jscsrc to manage. It just works!

Uses ESLint underneath, so issues regarding rules should be opened over there.

JSX is supported by default.

$ npm install --global xo
$ xo --help
    $ xo [<file|glob> ...]
    --init          Add XO to your project
    --fix           Automagically fix issues
    --compact       Compact output
    --stdin         Validate code from stdin
    --esnext        Enable ES2015+ rules
    --env           Environment preset  [Can be set multiple times]
    --global        Global variable  [Can be set multiple times]
    --ignore        Additional paths to ignore  [Can be set multiple times]
    --space         Use space indent instead of tabs  [Default: 2]
    --no-semicolon  Prevent use of semicolons
    --plugin        Include third-party plugins  [Can be set multiple times]
    --extend        Extend defaults with a custom config  [Can be set multiple times]
    --open          Open files with issues in your editor
    $ xo
    $ xo index.js
    $ xo *.js !foo.js
    $ xo --esnext --space
    $ xo --env=node --env=mocha
    $ xo --init --esnext
    $ xo --plugin=react
    Put options in package.json instead of using flags so other tools can read it.

Any of these can be overridden if necessary.

  • Tab indentation (or space)
  • Semicolons
  • Single-quotes
  • No unused variables
  • Space after keyword if (condition) {}
  • Always === instead of ==

Check out an example and the ESLint rules.

The recommended workflow is to add XO locally to your project and run it with the tests.

Simply run $ xo --init (with any options) to add XO to your package.json or create one.

"name": "awesome-package",
"scripts": {
"test": "ava"
"devDependencies": {
"ava": "^0.7.0"
"name": "awesome-package",
"scripts": {
"test": "xo && ava"
"devDependencies": {
"ava": "^0.7.0",
"xo": "^0.12.0"

Then just run $ npm test and XO will be run before your tests.

You can configure some options in XO by putting it in package.json:

"name": "awesome-package",
"xo": {
"esnext": true

Globals and rules can be configured inline in files.

Type: boolean
Default: false

Enable ES2015+ rules.

ES2015+ is parsed even without this option. You can already use ES2016 features like async/await and decorators. For a full list of features see Babel's experimental features and their Learn ES2015.

Type: array
Default: ['node']

Which environments your code is designed to run in. Each environment brings with it a certain set of predefined global variables.

Type: array

Additional global variables your code accesses during execution.

Type: array

Some paths are ignored by default. Additional ignores can be added here.

Type: boolean, number
Default: false (tab indentation)

Set it to true to get 2-space indentation or specify the number of spaces.

This option exists for pragmatic reasons, but I would strongly recommend you read "Why tabs are superior".

Type: object

Override any of the default rules. See the ESLint docs for more info on each rule.

Please take a moment to consider if you really need to use this option.

Type: boolean
Default: true (semicolons required)

Set it to false to enforce no-semicolon style.

Type: array

Include third-party plugins.

Type: array, string

Use one or more shareable configs to override any of the default rules (like rules above).

It means hugs and kisses.

The Standard style is a really cool idea. I too wish we could have one style to rule them all! But the reality is that the JS community is just too diverse and opinionated to create one code style. They also made the mistake of pushing their own style instead of the most popular one. In contrast, XO is more pragmatic and has no aspiration of being the style. My goal with XO is to make it simple to enforce consistent code style with close to no config. XO comes with my code style preference by default, as I mainly made it for myself, but everything is configurable.

XO is based on ESLint. This project started out as just a shareable ESLint config, but it quickly grew out of that. I wanted something even simpler. Just typing xo and be done. No decision-making. No config. I also have some exciting future plans for it. However, you can still get most of the XO benefits while using ESLint directly with the ESLint shareable config.

You can use Syntastic's ESLint checker with the following settings in your .vimrc file:

let g:syntastic_javascript_eslint_generic = 1
let g:syntastic_javascript_eslint_exec = 'xo'
let g:syntastic_javascript_eslint_args = '--compact'
let g:syntastic_javascript_checkers = ['eslint']

MIT © Sindre Sorhus