Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paths in .gitignore are ignored by default #148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const deepAssign = require('deep-assign');
const multimatch = require('multimatch');
const resolveFrom = require('resolve-from');
const pathExists = require('path-exists');
const globby = require('globby');
const gitignore = require('parse-gitignore');

const DEFAULT_IGNORE = [
'**/node_modules/**',
Expand Down Expand Up @@ -195,6 +197,13 @@ function preprocess(opts) {
opts = mergeWithPkgConf(opts);
opts = normalizeOpts(opts);
opts.ignores = DEFAULT_IGNORE.concat(opts.ignores || []);

// append .gitignore contents if present
const paths = globby.sync('.gitignore', {});
if (paths.length === 1) {
opts.ignores = opts.ignores.concat(gitignore(paths[0]));
}

return opts;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"has-flag": "^2.0.0",
"meow": "^3.4.2",
"multimatch": "^2.1.0",
"parse-gitignore": "^0.3.1",
"path-exists": "^3.0.0",
"pkg-conf": "^1.0.1",
"resolve-cwd": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Additional global variables your code accesses during execution.

Type: `Array`

Some [paths](https://github.com/sindresorhus/xo/blob/master/options-manager.js) are ignored by default. Additional ignores can be added here.
Some [paths](https://github.com/sindresorhus/xo/blob/master/options-manager.js) are ignored by default. Paths in `.gitignore` are also ignored by default. Additional ignores can be added here.

### space

Expand Down
10 changes: 10 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ test.failing('ignores fixture', async t => {
t.throws(execa('../../../cli.js', ['--no-local'], {cwd}));
});

test('gitignore fixture', async t => {
const cwd = path.join(__dirname, 'fixtures/gitignore');
try {
await execa('../../../cli.js', ['--no-local'], {cwd});
} catch (err) {
t.is(err.stdout.indexOf('foo.js'), -1);
t.true(err.stdout.indexOf('bar.js') !== -1);
}
});

test('supports being extended with a shareable config', async () => {
const cwd = path.join(__dirname, 'fixtures/project');
await execa('../../../cli.js', ['--no-local'], {cwd});
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/gitignore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/foo.js
5 changes: 5 additions & 0 deletions test/fixtures/gitignore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports = function (foo) {
return foo + 'bar'
}
21 changes: 21 additions & 0 deletions test/fixtures/gitignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"xo": {
"space": 2,
"semicolon": false,
"overrides": [
{
"files": "test/*.js",
"esnext": true,
"space": 3
},
{
"files": "test/foo.js",
"space": 4
}
],
"rules": {
"import/no-extraneous-dependencies": 0,
"ava/no-ignored-test-files": 0
}
}
}
6 changes: 6 additions & 0 deletions test/fixtures/gitignore/test/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava'
import fn from '../'

test(t => {
t.is(fn('foo'), fn('foobar'))
})