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 1 commit
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
26 changes: 22 additions & 4 deletions lib/util/glob-util.js
Expand Up @@ -8,7 +8,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
const _ = require("lodash"),
Copy link
Member

Choose a reason for hiding this comment

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

We prefer just using lodash variable in the rest of the codebase, would you mind switching that up here? Thanks!

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

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

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

const memoGetIgnorePaths = _.memoize(
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced this function (or the one below) needs a "memo" prefix, but I won't insist on a change here.

options =>
new IgnoredPaths(options)
);

const memoGetNewConfig = _.memoize(
(options, dotfiles) =>
Object.assign({}, options, { dotfiles })
);

/**
* Build a list of absolute filesnames on which ESLint will act.
* Ignored files are excluded from the results, as are duplicates.
Expand Down Expand Up @@ -151,15 +164,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 = memoGetIgnorePaths(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 = memoGetNewConfig(options, globIncludesDotfiles);
}

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