diff --git a/lib/util/glob-util.js b/lib/util/glob-util.js index 4106ca5240d..03d1a2bdd9c 100644 --- a/lib/util/glob-util.js +++ b/lib/util/glob-util.js @@ -104,28 +104,22 @@ function resolveFileGlobPatterns(patterns, options) { * @returns {string[]} Resolved absolute filenames. */ function listFilesToProcess(globPatterns, options) { + options = options || { ignore: true }; const files = [], added = {}; const cwd = (options && options.cwd) || process.cwd(); - options = options || { ignore: true, dotfiles: true }; - const ignoredPaths = new IgnoredPaths(options); - const globOptions = { - nodir: true, - cwd - }; - const shouldIgnore = ignoredPaths.getIgnoredFoldersGlobChecker(); - /** * Executes the linter on a file defined by the `filename`. Skips * unsupported file extensions and 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 {IgnoredPaths} ignoredPaths An instance of IgnoredPaths * @returns {void} */ - function addFile(filename, shouldWarnIgnored) { + function addFile(filename, shouldWarnIgnored, ignoredPaths) { let ignored = false; let isSilentlyIgnored; @@ -160,10 +154,24 @@ function listFilesToProcess(globPatterns, options) { const file = path.resolve(cwd, pattern); if (shell.test("-f", file)) { - addFile(fs.realpathSync(file), !shell.test("-d", file)); + const ignoredPaths = new IgnoredPaths(options); + + addFile(fs.realpathSync(file), !shell.test("-d", file), ignoredPaths); } else { + + // regex to find .hidden or /.hidden patterns, but not ./relative or ../relative + const globIncludesDotfiles = /(?:(?:^\.)|(?:[\/\\]\.))[^\/\\\.].*/.test(pattern); + + const ignoredPaths = new IgnoredPaths(Object.assign({}, options, {dotfiles: options.dotfiles || globIncludesDotfiles})); + const shouldIgnore = ignoredPaths.getIgnoredFoldersGlobChecker(); + const globOptions = { + nodir: true, + dot: true, + cwd, + }; + new GlobSync(pattern, globOptions, shouldIgnore).found.forEach(function(globMatch) { - addFile(path.resolve(cwd, globMatch), false); + addFile(path.resolve(cwd, globMatch), false, ignoredPaths); }); } }); diff --git a/tests/fixtures/cli-engine/hidden/.hiddenfolder/double-quotes.js b/tests/fixtures/cli-engine/hidden/.hiddenfolder/double-quotes.js new file mode 100644 index 00000000000..96b076005a5 --- /dev/null +++ b/tests/fixtures/cli-engine/hidden/.hiddenfolder/double-quotes.js @@ -0,0 +1,2 @@ +var bar = "
Hello world!
"; +bar(bar); diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index ba46a3bc28a..8b2af233a13 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -523,6 +523,22 @@ describe("CLIEngine", function() { assert.equal(report.results[0].messages[0].message, expectedMsg); }); + it("should report on globs with explicit inclusion of dotfiles, even though ignored by default", function() { + + engine = new CLIEngine({ + cwd: getFixturePath("cli-engine"), + rules: { + quotes: [2, "single"] + } + }); + + const report = engine.executeOnFiles(["hidden/.hiddenfolder/*.js"]); + + assert.equal(report.results.length, 1); + assert.equal(report.results[0].errorCount, 1); + assert.equal(report.results[0].warningCount, 0); + }); + it("should not check default ignored files without --no-ignore flag", function() { engine = new CLIEngine({ @@ -585,6 +601,26 @@ describe("CLIEngine", function() { assert.equal(report.results[0].messages[0].ruleId, "quotes"); }); + it("should check .hidden files if they are unignored with an --ignore-pattern", function() { + + engine = new CLIEngine({ + cwd: getFixturePath("cli-engine"), + ignore: true, + useEslintrc: false, + ignorePattern: "!.hidden*", + rules: { + quotes: [2, "single"] + } + }); + + const report = engine.executeOnFiles(["hidden/"]); + + assert.equal(report.results.length, 1); + assert.equal(report.results[0].warningCount, 0); + assert.equal(report.results[0].errorCount, 1); + assert.equal(report.results[0].messages[0].ruleId, "quotes"); + }); + it("should report zero messages when given a pattern with a .js and a .js2 file", function() { engine = new CLIEngine({ diff --git a/tests/lib/util/glob-util.js b/tests/lib/util/glob-util.js index f218a28bda7..efbef5699b2 100644 --- a/tests/lib/util/glob-util.js +++ b/tests/lib/util/glob-util.js @@ -199,7 +199,9 @@ describe("globUtil", function() { it("should not return hidden files for standard glob patterns", function() { const patterns = [getFixturePath("glob-util", "hidden", "**/*.js")]; - const result = globUtil.listFilesToProcess(patterns); + const result = globUtil.listFilesToProcess(patterns, { + cwd: getFixturePath() + }); assert.equal(result.length, 0); }); @@ -207,8 +209,7 @@ describe("globUtil", function() { it("should return hidden files if included in glob pattern", function() { const patterns = [getFixturePath("glob-util", "hidden", "**/.*.js")]; const result = globUtil.listFilesToProcess(patterns, { - cwd: getFixturePath(), - dotfiles: true + cwd: getFixturePath() }); const file1 = getFixturePath("glob-util", "hidden", ".foo.js");