Socket
Socket
Sign inDemoInstall

xo

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xo

JavaScript happiness style ❤️ XOXO


Version published
Weekly downloads
89K
decreased by-6.37%
Maintainers
1
Weekly downloads
 
Created
Source


XO


JavaScript happiness style ❤️ XOXO

Build Status

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.

Code style

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

Any of these can be overridden if necessary.

Check out an example and the ESLint rules.

Install

$ npm install --global xo

Usage

$ xo --help

  Usage
    $ xo [<file|glob> ...]

  Options
    --init     Add XO to your project
    --compact  Compact output
    --stdin    Validate code from stdin
    --esnext   Enable ES2015 support and 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]

  Examples
    $ xo
    $ xo index.js
    $ xo *.js !foo.js
    $ xo --esnext --space
    $ xo --esnext --env=node --env=mocha

  Tips
    Put options in package.json instead of using flags so other tools can read it.

Workflow

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

Simply run $ xo --init to add XO to your package.json:

Before

{
	"name": "my-awesome-project",
	"scripts": {
		"test": "mocha"
	},
	"devDependencies": {
		"mocha": "^2.0.0"
	}
}

After

{
	"name": "my-awesome-project",
	"scripts": {
		"test": "xo && mocha"
	},
	"devDependencies": {
		"mocha": "^2.0.0",
		"xo": "^0.4.0"
	}
}

Config

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

{
	"name": "my-awesome-project",
	"xo": {
		"env": ["node", "mocha"]
	}
}

Globals and rules can be configured inline in files.

esnext

Type: boolean
Default: false

Enable ES2015 support and linting rules.

envs

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.

globals

Type: array

Additional global variables your code accesses during execution.

ignores

Type: array

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

space

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".

rules

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.

FAQ

Why not Standard?

The Standard style is a really cool idea. I too wish we could have one style to rule them all! Unfortunately, they made the mistake of pushing their own style instead of the most popular one. I don't think it's realistic to convert everyone. In contrast, XO is more pragmatic and has no aspiration of being the style. XO does use tabs by default, but everything is configurable if necessary.

Why not ESLint?

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.

Editors

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 03 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc