Skip to content

Commit fdf051d

Browse files
pvdlgsindresorhus
authored andcommitted
Use globby gitignore handling (#283)
1 parent fd89175 commit fdf051d

5 files changed

Lines changed: 7 additions & 97 deletions

File tree

index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ module.exports.lintText = (str, opts) => {
6161

6262
if (opts.filename) {
6363
const filename = path.relative(opts.cwd, opts.filename);
64-
const isIgnored = multimatch(filename, opts.ignores).length > 0;
65-
const isGitIgnored = !optionsManager.getGitIgnoreFilter(opts)(opts.filename);
6664

67-
if (isIgnored || isGitIgnored) {
65+
if (multimatch(filename, opts.ignores).length > 0 ||
66+
globby.gitignore.sync({cwd: opts.cwd, ignore: opts.ignores})(opts.filename)) {
6867
return {
6968
errorCount: 0,
7069
warningCount: 0,
@@ -89,11 +88,11 @@ module.exports.lintFiles = (patterns, opts) => {
8988

9089
const isEmptyPatterns = patterns.length === 0;
9190
const defaultPattern = `**/*.{${opts.extensions.join(',')}}`;
92-
const ignoreFilter = optionsManager.getGitIgnoreFilter(opts);
9391

94-
patterns = isEmptyPatterns ? [defaultPattern] : arrify(patterns);
95-
96-
return globby(patterns, {ignore: opts.ignores, nodir: true, cwd: opts.cwd}).then(paths => {
92+
return globby(
93+
isEmptyPatterns ? [defaultPattern] : arrify(patterns),
94+
{ignore: opts.ignores, gitignore: true, cwd: opts.cwd}
95+
).then(paths => {
9796
// Filter out unwanted file extensions
9897
// For silly users that don't specify an extension in the glob pattern
9998
if (!isEmptyPatterns) {
@@ -103,8 +102,6 @@ module.exports.lintFiles = (patterns, opts) => {
103102
});
104103
}
105104

106-
paths = paths.filter(ignoreFilter);
107-
108105
if (!(opts.overrides && opts.overrides.length > 0)) {
109106
return runEslint(paths, opts);
110107
}

lib/gitignore.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

lib/options-manager.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const pkgConf = require('pkg-conf');
99
const resolveFrom = require('resolve-from');
1010
const prettier = require('prettier');
1111

12-
const getGitIgnoreFilter = require('./gitignore').getGitIgnoreFilter;
13-
1412
const DEFAULT_IGNORE = [
1513
'**/node_modules/**',
1614
'**/bower_components/**',
@@ -298,4 +296,3 @@ module.exports.groupConfigs = groupConfigs;
298296
module.exports.preprocess = preprocess;
299297
module.exports.emptyOptions = emptyOptions;
300298
module.exports.getIgnores = getIgnores;
301-
module.exports.getGitIgnoreFilter = getGitIgnoreFilter;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"eslint-plugin-promise": "^3.6.0",
8585
"eslint-plugin-unicorn": "^2.1.0",
8686
"get-stdin": "^5.0.0",
87-
"globby": "^6.0.0",
87+
"globby": "^7.1.1",
8888
"has-flag": "^2.0.0",
8989
"ignore": "^3.2.6",
9090
"lodash.isequal": "^4.4.0",

test/gitignore.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)