1 | /**
|
2 | * @fileoverview Provide the function that emits deprecation warnings.
|
3 | * @author Toru Nagashima <http://github.com/mysticatea>
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Requirements
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | const path = require("path");
|
12 | const lodash = require("lodash");
|
13 |
|
14 | //------------------------------------------------------------------------------
|
15 | // Private
|
16 | //------------------------------------------------------------------------------
|
17 |
|
18 | // Definitions for deprecation warnings.
|
19 | const deprecationWarningMessages = {
|
20 | ESLINT_LEGACY_ECMAFEATURES:
|
21 | "The 'ecmaFeatures' config file property is deprecated and has no effect.",
|
22 | ESLINT_PERSONAL_CONFIG_LOAD:
|
23 | "'~/.eslintrc.*' config files have been deprecated. " +
|
24 | "Please use a config file per project or the '--config' option.",
|
25 | ESLINT_PERSONAL_CONFIG_SUPPRESS:
|
26 | "'~/.eslintrc.*' config files have been deprecated. " +
|
27 | "Please remove it or add 'root:true' to the config files in your " +
|
28 | "projects in order to avoid loading '~/.eslintrc.*' accidentally."
|
29 | };
|
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 | const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
|
40 | const rel = path.relative(process.cwd(), source);
|
41 | const message = deprecationWarningMessages[errorCode];
|
42 |
|
43 | process.emitWarning(
|
44 | `${message} (found in "${rel}")`,
|
45 | "DeprecationWarning",
|
46 | errorCode
|
47 | );
|
48 | }, (...args) => JSON.stringify(args));
|
49 |
|
50 | //------------------------------------------------------------------------------
|
51 | // Public Interface
|
52 | //------------------------------------------------------------------------------
|
53 |
|
54 | module.exports = {
|
55 | emitDeprecationWarning
|
56 | };
|