Skip to content

Commit

Permalink
Move xo --init to npm init xo
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 26, 2019
1 parent 7aa7d53 commit 6463dfe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
12 changes: 3 additions & 9 deletions cli-main.js
Expand Up @@ -13,7 +13,6 @@ const cli = meow(`
$ xo [<file|glob> ...]
Options
--init Add XO to your project
--fix Automagically fix issues
--reporter Reporter to use
--env Environment preset [Can be set multiple times]
Expand All @@ -39,19 +38,16 @@ const cli = meow(`
$ xo *.js !foo.js
$ xo --space
$ xo --env=node --env=mocha
$ xo --init --space
$ xo --plugin=react
$ xo --plugin=html --extension=html
$ echo 'const x=true' | xo --stdin --fix
Tips
Put options in package.json instead of using flags so other tools can read it.
- Add XO to your project with \`npm init xo\`.
- Put options in package.json instead of using flags so other tools can read it.
`, {
booleanDefault: undefined,
flags: {
init: {
type: 'boolean'
},
fix: {
type: 'boolean'
},
Expand Down Expand Up @@ -155,9 +151,7 @@ if (options.nodeVersion) {
}

(async () => {
if (options.init) {
require('xo-init')();
} else if (options.stdin) {
if (options.stdin) {
const stdin = await getStdin();

if (options.fix) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -78,8 +78,7 @@
"resolve-from": "^5.0.0",
"semver": "^6.3.0",
"slash": "^3.0.0",
"update-notifier": "^3.0.1",
"xo-init": "^0.7.0"
"update-notifier": "^3.0.1"
},
"devDependencies": {
"ava": "^1.1.0",
Expand Down
53 changes: 20 additions & 33 deletions readme.md
Expand Up @@ -31,7 +31,7 @@ Uses [ESLint](https://eslint.org) underneath, so issues regarding rules should b
- Includes many useful ESLint plugins, like [`unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn), [`import`](https://github.com/benmosher/eslint-plugin-import), [`ava`](https://github.com/avajs/eslint-plugin-ava), [`node`](https://github.com/mysticatea/eslint-plugin-node) and more.
- Automatically enables rules based on the [`engines`](https://docs.npmjs.com/files/package.json#engines) field in your `package.json`.
- Caches results between runs for much better performance.
- Super simple to add XO to a project with `$ xo --init`.
- Super simple to add XO to a project with [`$ npm init xo`](https://github.com/xojs/create-xo).
- Fix many issues automagically with `$ xo --fix`.
- Open all files with errors at the correct line in your editor with `$ xo --open`.
- Specify [indent](#space) and [semicolon](#semicolon) preferences easily without messing with the rule config.
Expand All @@ -55,7 +55,6 @@ $ xo --help
$ xo [<file|glob> ...]
Options
--init Add XO to your project
--fix Automagically fix issues
--reporter Reporter to use
--env Environment preset [Can be set multiple times]
Expand All @@ -81,13 +80,13 @@ $ xo --help
$ xo *.js !foo.js
$ xo --space
$ xo --env=node --env=mocha
$ xo --init --space
$ xo --plugin=react
$ xo --plugin=html --extension=html
$ echo 'const x=true' | xo --stdin --fix
Tips
Put options in package.json instead of using flags so other tools can read it.
- Add XO to your project with `npm init xo`.
- Put options in package.json instead of using flags so other tools can read it.
```

*Note that the CLI will use your local install of XO when available, even when run globally.*
Expand All @@ -111,35 +110,23 @@ Check out an [example](index.js) and the [ESLint rules](https://github.com/xojs/

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.

### Before

```json
{
"name": "awesome-package",
"scripts": {
"test": "ava"
},
"devDependencies": {
"ava": "^0.20.0"
}
}
```

### After

```json
{
"name": "awesome-package",
"scripts": {
"test": "xo && ava"
},
"devDependencies": {
"ava": "^0.20.0",
"xo": "^0.18.0"
}
}
Simply run `$ npm init xo` (with any options) to add XO to your package.json or create one.

### Before/after

```diff
{
"name": "awesome-package",
"scripts": {
- "test": "ava",
+ "test": "xo && ava"
},
"devDependencies": {
- "ava": "^2.0.0"
+ "ava": "^2.0.0",
+ "xo": "^0.25.0"
}
}
```

Then just run `$ npm test` and XO will be run before your tests.
Expand Down
9 changes: 0 additions & 9 deletions test/cli-main.js
Expand Up @@ -104,15 +104,6 @@ test('quiet option', async t => {
t.is(report.warningCount, 0);
});

test('init option', async t => {
const filepath = await tempWrite('{}', 'package.json');
await main(['--init'], {
cwd: path.dirname(filepath)
});
const packageJson = fs.readFileSync(filepath, 'utf8');
t.deepEqual(JSON.parse(packageJson).scripts, {test: 'xo'});
});

test('invalid node-engine option', async t => {
const filepath = await tempWrite('console.log()\n', 'x.js');
const error = await t.throwsAsync(main(['--node-version', 'v', filepath]));
Expand Down

0 comments on commit 6463dfe

Please sign in to comment.