]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/bin/eslint.js
4 * @fileoverview Main CLI that is run via the eslint command.
5 * @author Nicholas C. Zakas
8 /* eslint no-console:off */
12 // to use V8's code cache to speed up instantiation time
13 require("v8-compile-cache");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const useStdIn
= process
.argv
.includes("--stdin"),
20 init
= process
.argv
.includes("--init"),
21 debug
= process
.argv
.includes("--debug");
23 // must do this initialization *before* other requires in order to work
25 require("debug").enable("eslint:*,-eslint:code-path");
28 //------------------------------------------------------------------------------
30 //------------------------------------------------------------------------------
32 // now we can safely include the other modules that use debug
33 const path
= require("path"),
35 cli
= require("../lib/cli");
37 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
41 process
.once("uncaughtException", err
=> {
44 const lodash
= require("lodash");
46 if (typeof err
.messageTemplate
=== "string" && err
.messageTemplate
.length
> 0) {
47 const template
= lodash
.template(fs
.readFileSync(path
.resolve(__dirname
, `../messages/${err.messageTemplate}.txt`), "utf-8"));
48 const pkg
= require("../package.json");
50 console
.error("\nOops! Something went wrong! :(");
51 console
.error(`\nESLint: ${pkg.version}.\n\n${template(err.messageData || {})}`);
53 console
.error(err
.stack
);
63 * - https://github.com/nodejs/node/blob/master/doc/api/process.md#processstdin
64 * - https://github.com/nodejs/node/blob/master/doc/api/process.md#a-note-on-process-io
65 * - https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-01/msg00419.html
66 * - https://github.com/nodejs/node/issues/7439 (historical)
68 * On Windows using `fs.readFileSync(STDIN_FILE_DESCRIPTOR, "utf8")` seems
69 * to read 4096 bytes before blocking and never drains to read further data.
71 * The investigation on the Emacs thread indicates:
73 * > Emacs on MS-Windows uses pipes to communicate with subprocesses; a
74 * > pipe on Windows has a 4K buffer. So as soon as Emacs writes more than
75 * > 4096 bytes to the pipe, the pipe becomes full, and Emacs then waits for
76 * > the subprocess to read its end of the pipe, at which time Emacs will
77 * > write the rest of the stuff.
79 * Using the nodejs code example for reading from stdin.
84 process
.stdin
.setEncoding("utf8");
85 process
.stdin
.on("readable", () => {
87 // Use a loop to make sure we read all available data.
88 while ((chunk
= process
.stdin
.read()) !== null) {
93 process
.stdin
.on("end", () => {
94 process
.exitCode
= cli
.execute(process
.argv
, contents
, "utf8");
97 const configInit
= require("../lib/init/config-initializer");
99 configInit
.initializeConfig().then(() => {
100 process
.exitCode
= 0;
102 process
.exitCode
= 1;
103 console
.error(err
.message
);
104 console
.error(err
.stack
);
107 process
.exitCode
= cli
.execute(process
.argv
);