2 * @fileoverview Provide the function that emits deprecation warnings.
3 * @author Toru Nagashima <http://github.com/mysticatea>
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const path = require("path");
13 //------------------------------------------------------------------------------
15 //------------------------------------------------------------------------------
17 // Definitions for deprecation warnings.
18 const deprecationWarningMessages = {
19 ESLINT_LEGACY_ECMAFEATURES:
20 "The 'ecmaFeatures' config file property is deprecated and has no effect.",
21 ESLINT_PERSONAL_CONFIG_LOAD:
22 "'~/.eslintrc.*' config files have been deprecated. " +
23 "Please use a config file per project or the '--config' option.",
24 ESLINT_PERSONAL_CONFIG_SUPPRESS:
25 "'~/.eslintrc.*' config files have been deprecated. " +
26 "Please remove it or add 'root:true' to the config files in your " +
27 "projects in order to avoid loading '~/.eslintrc.*' accidentally."
30 const sourceFileErrorCache = new Set();
33 * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
34 * for each unique file path, but repeated invocations with the same file path have no effect.
35 * No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
36 * @param {string} source The name of the configuration source to report the warning for.
37 * @param {string} errorCode The warning message to show.
40 function emitDeprecationWarning(source, errorCode) {
41 const cacheKey = JSON.stringify({ source, errorCode });
43 if (sourceFileErrorCache.has(cacheKey)) {
47 sourceFileErrorCache.add(cacheKey);
49 const rel = path.relative(process.cwd(), source);
50 const message = deprecationWarningMessages[errorCode];
53 `${message} (found in "${rel}")`,
59 //------------------------------------------------------------------------------
61 //------------------------------------------------------------------------------
64 emitDeprecationWarning