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

Chore: Apply memoization to config creation within glob utils #9944

Merged
merged 4 commits into from Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/util/glob-util.js
Expand Up @@ -8,7 +8,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
const lodash = require("lodash"),
fs = require("fs"),
path = require("path"),
GlobSync = require("./glob"),

Expand Down Expand Up @@ -88,6 +89,8 @@ function resolveFileGlobPatterns(patterns, options) {
return patterns.filter(p => p.length).map(processPathExtensions);
}

const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/;

/**
* Build a list of absolute filesnames on which ESLint will act.
* Ignored files are excluded from the results, as are duplicates.
Expand All @@ -107,6 +110,11 @@ function listFilesToProcess(globPatterns, options) {

const cwd = (options && options.cwd) || process.cwd();

const getIgnorePaths = lodash.memoize(
optionsObj =>
new IgnoredPaths(optionsObj)
);

/**
* Executes the linter on a file defined by the `filename`. Skips
* unsupported file extensions and any files that are already linted.
Expand Down Expand Up @@ -151,15 +159,20 @@ function listFilesToProcess(globPatterns, options) {
const file = path.resolve(cwd, pattern);

if (fs.existsSync(file) && fs.statSync(file).isFile()) {
const ignoredPaths = new IgnoredPaths(options);
const ignoredPaths = getIgnorePaths(options);

addFile(fs.realpathSync(file), true, ignoredPaths);
} else {

// regex to find .hidden or /.hidden patterns, but not ./relative or ../relative
const globIncludesDotfiles = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/.test(pattern);
const globIncludesDotfiles = dotfilesPattern.test(pattern);
let newOptions = options;

if (!options.dotfiles) {
newOptions = Object.assign({}, options, { dotfiles: globIncludesDotfiles });
}

const ignoredPaths = new IgnoredPaths(Object.assign({}, options, { dotfiles: options.dotfiles || globIncludesDotfiles }));
const ignoredPaths = getIgnorePaths(newOptions);
const shouldIgnore = ignoredPaths.getIgnoredFoldersGlobChecker();
const globOptions = {
nodir: true,
Expand Down