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