Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

81 строка
2.5 KiB

  1. #!/usr/bin/env node
  2. /**
  3. * @fileoverview Main CLI that is run via the eslint command.
  4. * @author Nicholas C. Zakas
  5. */
  6. /* eslint no-console:off */
  7. "use strict";
  8. //------------------------------------------------------------------------------
  9. // Helpers
  10. //------------------------------------------------------------------------------
  11. const useStdIn = (process.argv.indexOf("--stdin") > -1),
  12. init = (process.argv.indexOf("--init") > -1),
  13. debug = (process.argv.indexOf("--debug") > -1);
  14. // must do this initialization *before* other requires in order to work
  15. if (debug) {
  16. require("debug").enable("eslint:*,-eslint:code-path");
  17. }
  18. //------------------------------------------------------------------------------
  19. // Requirements
  20. //------------------------------------------------------------------------------
  21. // now we can safely include the other modules that use debug
  22. const cli = require("../lib/cli"),
  23. path = require("path"),
  24. fs = require("fs");
  25. //------------------------------------------------------------------------------
  26. // Execution
  27. //------------------------------------------------------------------------------
  28. process.once("uncaughtException", err => {
  29. // lazy load
  30. const lodash = require("lodash");
  31. if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) {
  32. const template = lodash.template(fs.readFileSync(path.resolve(__dirname, `../messages/${err.messageTemplate}.txt`), "utf-8"));
  33. const pkg = require("../package.json");
  34. console.error("\nOops! Something went wrong! :(");
  35. console.error(`\nESLint: ${pkg.version}.\n${template(err.messageData || {})}`);
  36. } else {
  37. console.error(err.message);
  38. console.error(err.stack);
  39. }
  40. process.exitCode = 2;
  41. });
  42. if (useStdIn) {
  43. /*
  44. * Note: `process.stdin.fd` is not used here due to https://github.com/nodejs/node/issues/7439.
  45. * Accessing the `process.stdin` property seems to modify the behavior of file descriptor 0, resulting
  46. * in an error when stdin is piped in asynchronously.
  47. */
  48. const STDIN_FILE_DESCRIPTOR = 0;
  49. process.exitCode = cli.execute(process.argv, fs.readFileSync(STDIN_FILE_DESCRIPTOR, "utf8"));
  50. } else if (init) {
  51. const configInit = require("../lib/config/config-initializer");
  52. configInit.initializeConfig().then(() => {
  53. process.exitCode = 0;
  54. }).catch(err => {
  55. process.exitCode = 1;
  56. console.error(err.message);
  57. console.error(err.stack);
  58. });
  59. } else {
  60. process.exitCode = cli.execute(process.argv);
  61. }