Permalink
Browse files

Fix: allow linting the empty string from stdin (fixes #9515) (#9517)

This fixes an issue where `cli` would treat an empty-string argument as
missing.
  • Loading branch information...
not-an-aardvark authored and Aladdin-ADD committed Oct 26, 2017
1 parent 350a72c commit b8aa0718c88774f7ef59b5b1ca22e1478a09b1e6
Showing with 14 additions and 5 deletions.
  1. +7 −5 lib/cli.js
  2. +7 −0 tests/lib/cli.js
View
@@ -144,6 +144,8 @@ const cli = {
const files = currentOptions._;
const useStdin = typeof text === "string";
if (currentOptions.version) { // version from package.json
log.info(`v${require("../package.json").version}`);
@@ -153,7 +155,7 @@ const cli = {
log.error("The --print-config option must be used with exactly one file name.");
return 1;
}
if (text) {
if (useStdin) {
log.error("The --print-config option is not available for piped-in code.");
return 1;
}
@@ -164,27 +166,27 @@ const cli = {
log.info(JSON.stringify(fileConfig, null, " "));
return 0;
} else if (currentOptions.help || (!files.length && !text)) {
} else if (currentOptions.help || (!files.length && !useStdin)) {
log.info(options.generateHelp());
} else {
debug(`Running on ${text ? "text" : "files"}`);
debug(`Running on ${useStdin ? "text" : "files"}`);
if (currentOptions.fix && currentOptions.fixDryRun) {
log.error("The --fix option and the --fix-dry-run option cannot be used together.");
return 1;
}
if (text && currentOptions.fix) {
if (useStdin && currentOptions.fix) {
log.error("The --fix option is not available for piped-in code; use --fix-dry-run instead.");
return 1;
}
const engine = new CLIEngine(translateOptions(currentOptions));
const report = text ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files);
const report = useStdin ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files);
if (currentOptions.fix) {
debug("Fix mode enabled - applying fixes");
View
@@ -101,6 +101,13 @@ describe("cli", () => {
assert.strictEqual(result, 1);
});
it("should not print debug info when passed the empty string as text", () => {
const result = cli.execute(["--stdin", "--no-eslintrc"], "");
assert.strictEqual(result, 0);
assert.isTrue(log.info.notCalled);
});
it("should return no error when --ext .js2 is specified", () => {
const filePath = getFixturePath("files");
const result = cli.execute(`--ext .js2 ${filePath}`);

0 comments on commit b8aa071

Please sign in to comment.