Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eslint.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.stack);
  38. }
  39. process.exitCode = 2;
  40. });
  41. if (useStdIn) {
  42. /*
  43. * Note: `process.stdin.fd` is not used here due to https://github.com/nodejs/node/issues/7439.
  44. * Accessing the `process.stdin` property seems to modify the behavior of file descriptor 0, resulting
  45. * in an error when stdin is piped in asynchronously.
  46. */
  47. const STDIN_FILE_DESCRIPTOR = 0;
  48. process.exitCode = cli.execute(process.argv, fs.readFileSync(STDIN_FILE_DESCRIPTOR, "utf8"));
  49. } else if (init) {
  50. const configInit = require("../lib/config/config-initializer");
  51. configInit.initializeConfig().then(() => {
  52. process.exitCode = 0;
  53. }).catch(err => {
  54. process.exitCode = 1;
  55. console.error(err.message);
  56. console.error(err.stack);
  57. });
  58. } else {
  59. process.exitCode = cli.execute(process.argv);
  60. }