-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
Changes from 10 commits
81cb471
4d703a5
b9e5313
c0eccb1
4dfe33e
13d92cb
5703434
012c30a
57040c8
3566cf8
1009113
2aa2776
9757062
bf7d913
6e0e4af
2f172b0
ce27572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ 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 globby = require('globby'); | ||
|
||
const DEFAULT_IGNORE = [ | ||
'**/node_modules/**', | ||
|
@@ -191,10 +193,33 @@ function groupConfigs(paths, baseOptions, overrides) { | |
return arr; | ||
} | ||
|
||
function getIgnores(opts) { | ||
const gitignores = globby.sync('**/.gitignore'); | ||
let ignores = []; | ||
|
||
gitignores.forEach(path => { | ||
const result = parseGitignore(path); | ||
const location = path.substring(0, path.length - 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we do this? If I assume it's for removing the name from the path? Just use |
||
const fullPathResult = []; | ||
|
||
result.forEach(file => { | ||
file = location + file; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
fullPathResult.push(file); | ||
}); | ||
|
||
ignores = ignores.concat(fullPathResult || []); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just do the following: const ignores = gitignores
.map(path => {
const res = parseGitignore(path);
const location = path.substring(0, path.length - 10);
return res.map(file => location + file);
})
.reduce((a, b) => a.concat(b)); |
||
|
||
opts.ignores = DEFAULT_IGNORE.concat(opts.ignores || [], ignores); | ||
|
||
return opts; | ||
} | ||
|
||
function preprocess(opts) { | ||
opts = mergeWithPkgConf(opts); | ||
opts = normalizeOpts(opts); | ||
opts.ignores = DEFAULT_IGNORE.concat(opts.ignores || []); | ||
opts = getIgnores(opts); | ||
|
||
return opts; | ||
} | ||
|
||
|
@@ -208,3 +233,4 @@ exports.mergeApplicableOverrides = mergeApplicableOverrides; | |
exports.groupConfigs = groupConfigs; | ||
exports.preprocess = preprocess; | ||
exports.emptyOptions = emptyOptions; | ||
exports.getIgnores = getIgnores; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This is a test .gitignore. | ||
foo/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,17 @@ test.failing('ignores fixture', async t => { | |
t.throws(execa('../../../cli.js', ['--no-local'], {cwd})); | ||
}); | ||
|
||
test('ignore files in .gitignore', async t => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good if this test was duplicated as an API test too (using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this should be an API test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make sure the I've merged this now, but would be nice if you could submit an API test for this. |
||
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}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
module.exports = function (foo) { | ||
return foo + 'bar' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo.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')) | ||
}) |
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')) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should only look for
.gitignore
files in not already ignored locations. So you need to pass the existing ignores here (in theignore
option). Right now it also looks in for example thenode_modules
folder, which is very slow.Should also be a test for this (API test).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must also take into account the XO
cwd
option.