Skip to content

Commit 65bce3a

Browse files
not-an-aardvarkplatinumazure
authored andcommitted
Fix: ensure --stdin flag works when stdin is piped asynchronously (eslint#10393)
1 parent b9b23a9 commit 65bce3a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

bin/eslint.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ process.once("uncaughtException", err => {
5656
});
5757

5858
if (useStdIn) {
59-
process.exitCode = cli.execute(process.argv, fs.readFileSync(process.stdin.fd, "utf8"));
59+
60+
/*
61+
* Note: `process.stdin.fd` is not used here due to https://github.com/nodejs/node/issues/7439.
62+
* Accessing the `process.stdin` property seems to modify the behavior of file descriptor 0, resulting
63+
* in an error when stdin is piped in asynchronously.
64+
*/
65+
const STDIN_FILE_DESCRIPTOR = 0;
66+
67+
process.exitCode = cli.execute(process.argv, fs.readFileSync(STDIN_FILE_DESCRIPTOR, "utf8"));
6068
} else if (init) {
6169
const configInit = require("../lib/config/config-initializer");
6270

tests/bin/eslint.js

+11
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ describe("bin/eslint.js", () => {
152152
}
153153
);
154154

155+
it("successfully reads from an asynchronous pipe", () => {
156+
const child = runESLint(["--stdin", "--no-eslintrc"]);
157+
158+
child.stdin.write("var foo = bar;\n");
159+
return new Promise(resolve => setTimeout(resolve, 300)).then(() => {
160+
child.stdin.write("var baz = qux;\n");
161+
child.stdin.end();
162+
163+
return assertExitCode(child, 0);
164+
});
165+
});
155166
});
156167

157168
describe("running on files", () => {

0 commit comments

Comments
 (0)