Skip to content

Commit

Permalink
Skip package.json files with "xo": false (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmartin authored and sindresorhus committed Oct 10, 2016
1 parent 3c42847 commit 8933f51
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function normalizeOpts(opts) {

function mergeWithPkgConf(opts) {
opts = Object.assign({cwd: process.cwd()}, opts);

return Object.assign({}, pkgConf.sync('xo', opts.cwd), opts);
const conf = pkgConf.sync('xo', {cwd: opts.cwd, skipOnFalse: true});
return Object.assign({}, conf, opts);
}

// define the shape of deep properties for deepAssign
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"meow": "^3.4.2",
"multimatch": "^2.1.0",
"path-exists": "^3.0.0",
"pkg-conf": "^1.0.1",
"pkg-conf": "^2.0.0",
"resolve-cwd": "^1.0.0",
"resolve-from": "^2.0.0",
"update-notifier": "^1.0.0",
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ XO makes it easy to override configs for specific files. The `overrides` propert
```


## Tips

### Using a parent's config

If you have a directory structure with nested `package.json` files and you want one of the child manifests to be skipped, you can do so by setting `"xo": false`. For example, when you have separate app and dev `package.json` files with `electron-builder`.


## FAQ

#### What does XO mean?
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/nested/child-empty/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"xo": {}
}
3 changes: 3 additions & 0 deletions test/fixtures/nested/child-ignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"xo": false
}
5 changes: 5 additions & 0 deletions test/fixtures/nested/child/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"xo": {
"esnext": false
}
}
2 changes: 2 additions & 0 deletions test/fixtures/nested/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var obj = { a: 1 };
console.log(obj.a);
5 changes: 5 additions & 0 deletions test/fixtures/nested/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"xo": {
"esnext": true
}
}
30 changes: 30 additions & 0 deletions test/options-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import path from 'path';
import test from 'ava';
import proxyquire from 'proxyquire';
import parentConfig from './fixtures/nested/package.json';
import childConfig from './fixtures/nested/child/package.json';

const manager = proxyquire('../options-manager', {
'resolve-from': (cwd, path) => `cwd/${path}`
Expand Down Expand Up @@ -138,3 +141,30 @@ test('groupConfigs', t => {
return obj;
}));
});

test('mergeWithPkgConf: use child if closest', t => {
const cwd = path.resolve('fixtures', 'nested', 'child');
const result = manager.mergeWithPkgConf({cwd});
const expected = Object.assign({}, childConfig.xo, {cwd});
t.deepEqual(result, expected);
});

test('mergeWithPkgConf: use parent if closest', t => {
const cwd = path.resolve('fixtures', 'nested');
const result = manager.mergeWithPkgConf({cwd});
const expected = Object.assign({}, parentConfig.xo, {cwd});
t.deepEqual(result, expected);
});

test('mergeWithPkgConf: use parent if child is ignored', t => {
const cwd = path.resolve('fixtures', 'nested', 'child-ignore');
const result = manager.mergeWithPkgConf({cwd});
const expected = Object.assign({}, parentConfig.xo, {cwd});
t.deepEqual(result, expected);
});

test('mergeWithPkgConf: use child if child is empty', t => {
const cwd = path.resolve('fixtures', 'nested', 'child-empty');
const result = manager.mergeWithPkgConf({cwd});
t.deepEqual(result, {cwd});
});

0 comments on commit 8933f51

Please sign in to comment.