Permalink
Browse files

Chore: refactor --no-ignore flag logic (#10146)

  • Loading branch information...
not-an-aardvark committed Mar 30, 2018
1 parent 4f61a0d commit 9a020dc145a651a82c321edf1995494744a7e703
Showing with 17 additions and 26 deletions.
  1. +17 −26 lib/util/glob-util.js
View
@@ -106,7 +106,7 @@ const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/;
function listFilesToProcess(globPatterns, providedOptions) {
const options = providedOptions || { ignore: true };
const files = [];
const added = {};
const addedFilenames = new Set();
const cwd = options.cwd || process.cwd();
@@ -117,41 +117,32 @@ function listFilesToProcess(globPatterns, providedOptions) {
/**
* Executes the linter on a file defined by the `filename`. Skips
* unsupported file extensions and any files that are already linted.
* any files that are already linted.
* @param {string} filename The file to be processed
* @param {boolean} shouldWarnIgnored Whether or not a report should be made if
* the file is ignored
* @param {boolean} isDirectPath True if the file
* was provided as a direct path (as opposed to being resolved from a glob)
* @param {IgnoredPaths} ignoredPaths An instance of IgnoredPaths
* @returns {void}
*/
function addFile(filename, shouldWarnIgnored, ignoredPaths) {
let ignored = false;
let isSilentlyIgnored;
if (ignoredPaths.contains(filename, "default")) {
ignored = (options.ignore !== false) && shouldWarnIgnored;
isSilentlyIgnored = !shouldWarnIgnored;
function addFile(filename, isDirectPath, ignoredPaths) {
if (addedFilenames.has(filename)) {
return;
}
if (options.ignore !== false) {
if (ignoredPaths.contains(filename, "custom")) {
if (shouldWarnIgnored) {
ignored = true;
} else {
isSilentlyIgnored = true;
}
}
}
const shouldProcessCustomIgnores = options.ignore !== false;
const shouldLintIgnoredDirectPaths = options.ignore === false;
const fileMatchesIgnorePatterns = ignoredPaths.contains(filename, "default") ||
(shouldProcessCustomIgnores && ignoredPaths.contains(filename, "custom"));
if (isSilentlyIgnored && !ignored) {
return;
if (fileMatchesIgnorePatterns && isDirectPath && !shouldLintIgnoredDirectPaths) {
files.push({ filename, ignored: true });
addedFilenames.add(filename);
}
if (added[filename]) {
return;
if (!fileMatchesIgnorePatterns || (isDirectPath && shouldLintIgnoredDirectPaths)) {
files.push({ filename, ignored: false });
addedFilenames.add(filename);
}
files.push({ filename, ignored });
added[filename] = true;
}
debug("Creating list of files to process.");

0 comments on commit 9a020dc

Please sign in to comment.