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 | // Definitions for deprecation warnings.
|
---|
18 | const deprecationWarningMessages = {
|
---|
19 | ESLINT_LEGACY_ECMAFEATURES:
|
---|
20 | "The 'ecmaFeatures' config file property is deprecated and has no effect."
|
---|
21 | };
|
---|
22 |
|
---|
23 | const sourceFileErrorCache = new Set();
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
|
---|
27 | * for each unique file path, but repeated invocations with the same file path have no effect.
|
---|
28 | * No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
|
---|
29 | * @param {string} source The name of the configuration source to report the warning for.
|
---|
30 | * @param {string} errorCode The warning message to show.
|
---|
31 | * @returns {void}
|
---|
32 | */
|
---|
33 | function emitDeprecationWarning(source, errorCode) {
|
---|
34 | const cacheKey = JSON.stringify({ source, errorCode });
|
---|
35 |
|
---|
36 | if (sourceFileErrorCache.has(cacheKey)) {
|
---|
37 | return;
|
---|
38 | }
|
---|
39 |
|
---|
40 | sourceFileErrorCache.add(cacheKey);
|
---|
41 |
|
---|
42 | const rel = path.relative(process.cwd(), source);
|
---|
43 | const message = deprecationWarningMessages[errorCode];
|
---|
44 |
|
---|
45 | process.emitWarning(
|
---|
46 | `${message} (found in "${rel}")`,
|
---|
47 | "DeprecationWarning",
|
---|
48 | errorCode
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | //------------------------------------------------------------------------------
|
---|
53 | // Public Interface
|
---|
54 | //------------------------------------------------------------------------------
|
---|
55 |
|
---|
56 | module.exports = {
|
---|
57 | emitDeprecationWarning
|
---|
58 | };
|
---|