deprecation-warnings.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @fileoverview Provide the function that emits deprecation warnings.
  3. * @author Toru Nagashima <http://github.com/mysticatea>
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const path = require("path");
  10. const lodash = require("lodash");
  11. //------------------------------------------------------------------------------
  12. // Private
  13. //------------------------------------------------------------------------------
  14. // Defitions for deprecation warnings.
  15. const deprecationWarningMessages = {
  16. ESLINT_LEGACY_ECMAFEATURES:
  17. "The 'ecmaFeatures' config file property is deprecated and has no effect.",
  18. ESLINT_PERSONAL_CONFIG_LOAD:
  19. "'~/.eslintrc.*' config files have been deprecated. " +
  20. "Please use a config file per project or the '--config' option.",
  21. ESLINT_PERSONAL_CONFIG_SUPPRESS:
  22. "'~/.eslintrc.*' config files have been deprecated. " +
  23. "Please remove it or add 'root:true' to the config files in your " +
  24. "projects in order to avoid loading '~/.eslintrc.*' accidentally."
  25. };
  26. /**
  27. * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
  28. * for each unique file path, but repeated invocations with the same file path have no effect.
  29. * No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
  30. * @param {string} source The name of the configuration source to report the warning for.
  31. * @param {string} errorCode The warning message to show.
  32. * @returns {void}
  33. */
  34. const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
  35. const rel = path.relative(process.cwd(), source);
  36. const message = deprecationWarningMessages[errorCode];
  37. process.emitWarning(
  38. `${message} (found in "${rel}")`,
  39. "DeprecationWarning",
  40. errorCode
  41. );
  42. }, (...args) => JSON.stringify(args));
  43. //------------------------------------------------------------------------------
  44. // Public Interface
  45. //------------------------------------------------------------------------------
  46. module.exports = {
  47. emitDeprecationWarning
  48. };