source: imaps-frontend/node_modules/eslint/lib/shared/deprecation-warnings.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.9 KB
Line 
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
11const path = require("path");
12
13//------------------------------------------------------------------------------
14// Private
15//------------------------------------------------------------------------------
16
17// Definitions for deprecation warnings.
18const deprecationWarningMessages = {
19 ESLINT_LEGACY_ECMAFEATURES:
20 "The 'ecmaFeatures' config file property is deprecated and has no effect."
21};
22
23const 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 */
33function 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
56module.exports = {
57 emitDeprecationWarning
58};
Note: See TracBrowser for help on using the repository browser.