.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @eslint / eslintrc / lib / shared / deprecation-warnings.js
1 /**
2  * @fileoverview Provide the function that emits deprecation warnings.
3  * @author Toru Nagashima <http://github.com/mysticatea>
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Requirements
9 //------------------------------------------------------------------------------
10
11 const path = require("path");
12
13 //------------------------------------------------------------------------------
14 // Private
15 //------------------------------------------------------------------------------
16
17 // Defitions 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."
28 };
29
30 const sourceFileErrorCache = new Set();
31
32 /**
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.
38  * @returns {void}
39  */
40 function emitDeprecationWarning(source, errorCode) {
41     const cacheKey = JSON.stringify({ source, errorCode });
42
43     if (sourceFileErrorCache.has(cacheKey)) {
44         return;
45     }
46     sourceFileErrorCache.add(cacheKey);
47
48     const rel = path.relative(process.cwd(), source);
49     const message = deprecationWarningMessages[errorCode];
50
51     process.emitWarning(
52         `${message} (found in "${rel}")`,
53         "DeprecationWarning",
54         errorCode
55     );
56 }
57
58 //------------------------------------------------------------------------------
59 // Public Interface
60 //------------------------------------------------------------------------------
61
62 module.exports = {
63     emitDeprecationWarning
64 };