Skip to content

Commit

Permalink
Use globby gitignore handling (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and sindresorhus committed Jan 14, 2018
1 parent fd89175 commit fdf051d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 97 deletions.
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ module.exports.lintText = (str, opts) => {

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

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

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

patterns = isEmptyPatterns ? [defaultPattern] : arrify(patterns);

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

paths = paths.filter(ignoreFilter);

if (!(opts.overrides && opts.overrides.length > 0)) {
return runEslint(paths, opts);
}
Expand Down
41 changes: 0 additions & 41 deletions lib/gitignore.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const pkgConf = require('pkg-conf');
const resolveFrom = require('resolve-from');
const prettier = require('prettier');

const getGitIgnoreFilter = require('./gitignore').getGitIgnoreFilter;

const DEFAULT_IGNORE = [
'**/node_modules/**',
'**/bower_components/**',
Expand Down Expand Up @@ -298,4 +296,3 @@ module.exports.groupConfigs = groupConfigs;
module.exports.preprocess = preprocess;
module.exports.emptyOptions = emptyOptions;
module.exports.getIgnores = getIgnores;
module.exports.getGitIgnoreFilter = getGitIgnoreFilter;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-unicorn": "^2.1.0",
"get-stdin": "^5.0.0",
"globby": "^6.0.0",
"globby": "^7.1.1",
"has-flag": "^2.0.0",
"ignore": "^3.2.6",
"lodash.isequal": "^4.4.0",
Expand Down
43 changes: 0 additions & 43 deletions test/gitignore.js

This file was deleted.

0 comments on commit fdf051d

Please sign in to comment.