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

Ignore paths from .gitignore #147

Merged
merged 17 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from 7 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
14 changes: 13 additions & 1 deletion options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const deepAssign = require('deep-assign');
const multimatch = require('multimatch');
const resolveFrom = require('resolve-from');
const pathExists = require('path-exists');
const parseGitignore = require('parse-gitignore');

const DEFAULT_IGNORE = [
'**/node_modules/**',
Expand Down Expand Up @@ -191,10 +192,20 @@ function groupConfigs(paths, baseOptions, overrides) {
return arr;
}

function getIgnores(opts) {
const gitignore = parseGitignore('.gitignore');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to take into account the cwd option.


opts.ignores = DEFAULT_IGNORE.concat(opts.ignores || []);
opts.ignores = opts.ignores.concat(gitignore || []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for multiple concat statement. Array#concat support multiple arguments.


return opts;
}

function preprocess(opts) {
opts = mergeWithPkgConf(opts);
opts = normalizeOpts(opts);
opts.ignores = DEFAULT_IGNORE.concat(opts.ignores || []);
opts = getIgnores(opts);

return opts;
}

Expand All @@ -208,3 +219,4 @@ exports.mergeApplicableOverrides = mergeApplicableOverrides;
exports.groupConfigs = groupConfigs;
exports.preprocess = preprocess;
exports.emptyOptions = emptyOptions;
exports.getIgnores = getIgnores;
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, including paths in .gitignore. Additional ignores can be added here.

### space

Expand Down
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a test .gitignore.
foo/
5 changes: 5 additions & 0 deletions test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ test('groupConfigs', t => {
return obj;
}));
});

test('gitignore', t => {
const result = manager.getIgnores({});
t.not(result.ignores.indexOf('foo/**'), -1);
});