Skip to content

Commit

Permalink
Chore: Apply memoization to config creation within glob utils (#9944)
Browse files Browse the repository at this point in the history
* Chore: Apply memoization to config creation within glob utils

* Code Review updates

* Safer memoization

* Safer memoization
  • Loading branch information
brokentone authored and kaicataldo committed Feb 16, 2018
1 parent 0e4ae22 commit 70f22f3
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit 70f22f3

Please sign in to comment.